Добавлена передача сигналов для закрытия запущенного процесса
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled

This commit is contained in:
2025-10-30 12:52:21 +03:00
parent dc5fd60c0d
commit 4c6713b2d3
4 changed files with 61 additions and 19 deletions

View File

@@ -893,7 +893,12 @@ proc Run {w filePath} {
cd [file dirname $filePath]
set pipe [open "|$fullCommand 2> [file join [file dirname $filePath] errors]" "r"]
set f [open [file join [file dirname $filePath] errors] "r"]
set processPID [pid $pipe]
bind $w.frame.text <Control-c> [list SendSignal $processPID "SIGKILL"]
bind $w.frame.text <Control-z> [list SendSignal $processPID "SIGTSTP"]
bind $w.frame.text <Control-d> [list SendSignal $processPID "SIGINT"]
# set pipe [open "|$command $filePath" "r"]
# set f [open [file join ~ tmp errors] "r"]
fileevent $pipe readable [list DebugInfo $w.frame.text $pipe $f]
@@ -909,7 +914,7 @@ proc DebugInfo {widget file f} {
puts $msg
$widget insert "end-4l linestart" "[::msgcat::mc "Program failed"]: $msg\n";
} else {
Highlight::ExecuteColorized $widget
# Highlight::ExecuteColorized $widget
puts $msg
$widget see "end-1l lineend"
$widget delete "end-1l lineend" end
@@ -917,9 +922,10 @@ proc DebugInfo {widget file f} {
# $widget insert end "[::msgcat::mc "Program finished successfully"]\n"
}
Highlight::ExecuteColorized $widget
# close $f
} else {
Highlight::ExecuteColorized $widget
$widget insert "end-4l linestart" [read $file]
# Highlight::ExecuteColorized $widget
$widget insert "end-4l linestart" "-->> [read $file]"
}
while {[gets $f line]>=0} {
Highlight::ExecuteColorized $widget
@@ -932,6 +938,33 @@ proc DebugInfo {widget file f} {
# $widget configure -state disabled
}
# Функция для отправки сигнала процессу
proc SendSignal {pid signal} {
global tcl_platform
if {$tcl_platform(platform) eq "unix"} {
# На Unix-системах
switch -- $signal {
"SIGINT" { exec kill -INT $pid } ; # Ctrl+C
"SIGTERM" { exec kill -TERM $pid } ; # Завершение
"SIGTSTP" { exec kill -TSTP $pid } ; # Ctrl+Z (приостановка)
"SIGKILL" { exec kill -KILL $pid } ; # Принудительное завершение
}
} else {
# На Windows
switch -- $signal {
"SIGINT" - "SIGTERM" {
# Используем taskkill для завершения
catch {exec taskkill /PID $pid /T}
}
"SIGKILL" {
# Принудительное завершение на Windows
catch {exec taskkill /PID $pid /T /F}
}
}
}
}
# Правка файла настроек
proc Settings {} {
global dir