Skip to content

Commit

Permalink
feat(pty): support windows
Browse files Browse the repository at this point in the history
  • Loading branch information
winhost committed Nov 8, 2024
1 parent 5f14659 commit 0b44b26
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ replace github.com/tree-sitter/tree-sitter-markdown => ./pkg/tree-sitter-markdow
replace github.com/tree-sitter-grammars/tree-sitter-yaml => ./pkg/tree-sitter-yaml/bindings/go

replace github.com/tree-sitter-grammars/tree-sitter-toml => ./pkg/tree-sitter-toml/bindings/go

replace github.com/creack/pty => ./pkg/photostorm/pty
require (
github.com/charlievieth/fastwalk v1.0.8
github.com/reinhrst/fzf-lib v0.9.0
Expand Down
28 changes: 20 additions & 8 deletions pkg/pty/pty.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ func setupLogFile(filename string) (*os.File, error) {

type Pty struct {
Cmd *exec.Cmd
File *os.File
File pty.Pty
Ch chan os.Signal
wch chan bool
Rows uint16 // ws_row: Number of rows (in cells).
Cols uint16 //
}
Expand Down Expand Up @@ -117,7 +118,7 @@ func RunNoStdin(Args []string) *Pty {
if err != nil {
log.Fatal(err)
}
ret := &Pty{Cmd: c, File: f, Ch: make(chan os.Signal, 1)}
ret := &Pty{Cmd: c, File: f, Ch: make(chan os.Signal, 1), wch: make(chan bool, 1)}

return ret
}
Expand All @@ -142,14 +143,25 @@ func RunCommand(Args []string) *Pty {
}
io.Copy(stdin2, os.Stdin)
}()
ret := &Pty{File: f, Ch: make(chan os.Signal, 1)}
ret := &Pty{File: f, Ch: make(chan os.Signal, 1),wch: make(chan bool, 1),}
ret.Notify()
go func() {
for range ret.Ch {
// if err := pty.InheritSize(os.Stdin, ret.File); err != nil {
// }
if err := pty.Setsize(ret.File, &pty.Winsize{Rows: ret.Rows, Cols: ret.Cols}); err != nil {
log.Printf("error resizing pty: %s", err)
for {
select {
case <-ret.wch:
{
if err := pty.Setsize(ret.File, &pty.Winsize{Rows: ret.Rows, Cols: ret.Cols}); err != nil {
debug.DebugLogf("pty","error resizing pty: %s", err)
}
}
case <-ret.Ch:
{
// if err := pty.InheritSize(os.Stdin, ret.File); err != nil {
// }
if err := pty.Setsize(ret.File, &pty.Winsize{Rows: ret.Rows, Cols: ret.Cols}); err != nil {
log.Printf("error resizing pty: %s", err)
}
}
}
}
}()
Expand Down
4 changes: 3 additions & 1 deletion pkg/pty/pty_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package pty
func (pty *Pty) OsUpdateSize(Rows uint16, Cols uint16) {
pty.Rows = Rows
pty.Cols = Cols
// pty.Ch <- syscall.SIGWINCH
go func () {
pty.wch <- true
}()
}
func (ret Pty)Notify(){
// signal.Notify(ret.Ch, syscall.SIGWINCH)
Expand Down

0 comments on commit 0b44b26

Please sign in to comment.