Skip to content

Commit 0b44b26

Browse files
author
winhost
committed
feat(pty): support windows
1 parent 5f14659 commit 0b44b26

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ replace github.com/tree-sitter/tree-sitter-markdown => ./pkg/tree-sitter-markdow
1616
replace github.com/tree-sitter-grammars/tree-sitter-yaml => ./pkg/tree-sitter-yaml/bindings/go
1717

1818
replace github.com/tree-sitter-grammars/tree-sitter-toml => ./pkg/tree-sitter-toml/bindings/go
19-
19+
replace github.com/creack/pty => ./pkg/photostorm/pty
2020
require (
2121
github.com/charlievieth/fastwalk v1.0.8
2222
github.com/reinhrst/fzf-lib v0.9.0

pkg/pty/pty.go

+20-8
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ func setupLogFile(filename string) (*os.File, error) {
8585

8686
type Pty struct {
8787
Cmd *exec.Cmd
88-
File *os.File
88+
File pty.Pty
8989
Ch chan os.Signal
90+
wch chan bool
9091
Rows uint16 // ws_row: Number of rows (in cells).
9192
Cols uint16 //
9293
}
@@ -117,7 +118,7 @@ func RunNoStdin(Args []string) *Pty {
117118
if err != nil {
118119
log.Fatal(err)
119120
}
120-
ret := &Pty{Cmd: c, File: f, Ch: make(chan os.Signal, 1)}
121+
ret := &Pty{Cmd: c, File: f, Ch: make(chan os.Signal, 1), wch: make(chan bool, 1)}
121122

122123
return ret
123124
}
@@ -142,14 +143,25 @@ func RunCommand(Args []string) *Pty {
142143
}
143144
io.Copy(stdin2, os.Stdin)
144145
}()
145-
ret := &Pty{File: f, Ch: make(chan os.Signal, 1)}
146+
ret := &Pty{File: f, Ch: make(chan os.Signal, 1),wch: make(chan bool, 1),}
146147
ret.Notify()
147148
go func() {
148-
for range ret.Ch {
149-
// if err := pty.InheritSize(os.Stdin, ret.File); err != nil {
150-
// }
151-
if err := pty.Setsize(ret.File, &pty.Winsize{Rows: ret.Rows, Cols: ret.Cols}); err != nil {
152-
log.Printf("error resizing pty: %s", err)
149+
for {
150+
select {
151+
case <-ret.wch:
152+
{
153+
if err := pty.Setsize(ret.File, &pty.Winsize{Rows: ret.Rows, Cols: ret.Cols}); err != nil {
154+
debug.DebugLogf("pty","error resizing pty: %s", err)
155+
}
156+
}
157+
case <-ret.Ch:
158+
{
159+
// if err := pty.InheritSize(os.Stdin, ret.File); err != nil {
160+
// }
161+
if err := pty.Setsize(ret.File, &pty.Winsize{Rows: ret.Rows, Cols: ret.Cols}); err != nil {
162+
log.Printf("error resizing pty: %s", err)
163+
}
164+
}
153165
}
154166
}
155167
}()

pkg/pty/pty_windows.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package pty
22
func (pty *Pty) OsUpdateSize(Rows uint16, Cols uint16) {
33
pty.Rows = Rows
44
pty.Cols = Cols
5-
// pty.Ch <- syscall.SIGWINCH
5+
go func () {
6+
pty.wch <- true
7+
}()
68
}
79
func (ret Pty)Notify(){
810
// signal.Notify(ret.Ch, syscall.SIGWINCH)

0 commit comments

Comments
 (0)