Skip to content

Commit 2bbfdc1

Browse files
committed
fix: windows console
1 parent 5eb9ec1 commit 2bbfdc1

File tree

4 files changed

+84
-9
lines changed

4 files changed

+84
-9
lines changed

compiler/internal/console/terminal.go

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import (
44
"fmt"
55
"os"
66
"os/signal"
7+
"runtime"
78
"sync"
89
"sync/atomic"
9-
"syscall"
1010
)
1111

1212
// ---------------------------------------------------------------------------
@@ -144,9 +144,14 @@ func (t *Terminal) Height() int {
144144
}
145145

146146
// WatchResize listens for SIGWINCH and updates terminal dimensions.
147+
// No-op on Windows (no SIGWINCH).
147148
func (t *Terminal) WatchResize() {
149+
sig := winchSignal()
150+
if sig == nil {
151+
return
152+
}
148153
ch := make(chan os.Signal, 1)
149-
signal.Notify(ch, winchSignal())
154+
signal.Notify(ch, sig)
150155
go func() {
151156
for range ch {
152157
if cols, rows, err := getWinsize(t.fd); err == nil {
@@ -158,9 +163,10 @@ func (t *Terminal) WatchResize() {
158163
}
159164

160165
// SetupCleanExit ensures the terminal is restored on SIGTERM/SIGHUP.
166+
// On Windows, listens for os.Interrupt only.
161167
func (t *Terminal) SetupCleanExit() {
162168
ch := make(chan os.Signal, 1)
163-
signal.Notify(ch, syscall.SIGTERM, syscall.SIGHUP)
169+
signal.Notify(ch, cleanExitSignals()...)
164170
go func() {
165171
<-ch
166172
t.Restore()
@@ -170,20 +176,27 @@ func (t *Terminal) SetupCleanExit() {
170176

171177
// HandleSuspend handles Ctrl+Z (SIGTSTP) by restoring terminal state,
172178
// then re-enabling raw mode on SIGCONT.
179+
// No-op on Windows (no job control signals).
173180
func (t *Terminal) HandleSuspend() {
181+
if runtime.GOOS == "windows" {
182+
return
183+
}
184+
susp := suspendSignal()
185+
cont := continueSignal()
186+
if susp == nil || cont == nil {
187+
return
188+
}
174189
ch := make(chan os.Signal, 1)
175-
signal.Notify(ch, suspendSignal(), continueSignal())
190+
signal.Notify(ch, susp, cont)
176191
go func() {
177192
for sig := range ch {
178-
if sig == suspendSignal() {
193+
if sig == susp {
179194
t.Restore()
180-
// Re-send SIGTSTP to actually suspend the process
181195
signal.Stop(ch)
182-
syscall.Kill(syscall.Getpid(), syscall.SIGTSTP)
196+
sendSuspendSignal()
183197
} else {
184-
// SIGCONT — re-enable raw mode
185198
t.EnableRaw()
186-
signal.Notify(ch, suspendSignal(), continueSignal())
199+
signal.Notify(ch, susp, cont)
187200
}
188201
}
189202
}()

compiler/internal/console/terminal_darwin.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,13 @@ func continueSignal() os.Signal {
6666
func winchSignal() os.Signal {
6767
return syscall.SIGWINCH
6868
}
69+
70+
// cleanExitSignals returns signals that should trigger a clean exit on darwin.
71+
func cleanExitSignals() []os.Signal {
72+
return []os.Signal{syscall.SIGTERM, syscall.SIGHUP}
73+
}
74+
75+
// sendSuspendSignal sends SIGTSTP to the current process.
76+
func sendSuspendSignal() {
77+
syscall.Kill(syscall.Getpid(), syscall.SIGTSTP)
78+
}

compiler/internal/console/terminal_linux.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,13 @@ func continueSignal() os.Signal {
9898
func winchSignal() os.Signal {
9999
return syscall.SIGWINCH
100100
}
101+
102+
// cleanExitSignals returns signals that should trigger a clean exit on linux.
103+
func cleanExitSignals() []os.Signal {
104+
return []os.Signal{syscall.SIGTERM, syscall.SIGHUP}
105+
}
106+
107+
// sendSuspendSignal sends SIGTSTP to the current process.
108+
func sendSuspendSignal() {
109+
syscall.Kill(syscall.Getpid(), syscall.SIGTSTP)
110+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//go:build windows
2+
3+
package console
4+
5+
import (
6+
"errors"
7+
"os"
8+
)
9+
10+
// enableRawMode is a no-op on Windows. The interactive console is not
11+
// supported on Windows; the CLI still works for build/run/deploy commands.
12+
func enableRawMode(fd uintptr) (restore func(), err error) {
13+
return nil, errors.New("raw mode not supported on Windows")
14+
}
15+
16+
// getWinsize returns default dimensions on Windows.
17+
func getWinsize(fd uintptr) (cols, rows int, err error) {
18+
return 80, 24, nil
19+
}
20+
21+
// suspendSignal returns nil on Windows (no SIGTSTP).
22+
func suspendSignal() os.Signal {
23+
return nil
24+
}
25+
26+
// continueSignal returns nil on Windows (no SIGCONT).
27+
func continueSignal() os.Signal {
28+
return nil
29+
}
30+
31+
// winchSignal returns nil on Windows (no SIGWINCH).
32+
func winchSignal() os.Signal {
33+
return nil
34+
}
35+
36+
// cleanExitSignals returns signals that should trigger a clean exit on Windows.
37+
func cleanExitSignals() []os.Signal {
38+
return []os.Signal{os.Interrupt}
39+
}
40+
41+
// sendSuspendSignal is a no-op on Windows (no job control).
42+
func sendSuspendSignal() {}

0 commit comments

Comments
 (0)