Skip to content

Commit

Permalink
Improve TTY debugability
Browse files Browse the repository at this point in the history
Ref: #259
  • Loading branch information
walles committed Jan 5, 2025
1 parent e7ecaa2 commit 69a7f5d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
18 changes: 12 additions & 6 deletions twin/screen-setup-windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,6 @@ func (screen *UnixScreen) setupTtyInTtyOut() error {
return fmt.Errorf("failed to set raw mode: %w", err)
}

updatedTerminalState, err := term.GetState(int(screen.ttyIn.Fd()))
if err != nil {
return err
}
log.Info("Raw terminal state: ", fmt.Sprintf("%+v", updatedTerminalState))

screen.ttyOut = os.Stdout

// Enable console colors, from: https://stackoverflow.com/a/52579002
Expand All @@ -119,6 +113,18 @@ func (screen *UnixScreen) setupTtyInTtyOut() error {
return fmt.Errorf("failed to set stdout console mode: %w", err)
}

ttyInTerminalState, err := term.GetState(int(screen.ttyIn.Fd()))
if err != nil {
return err
}
log.Info("ttyin terminal state: ", fmt.Sprintf("%+v", ttyInTerminalState))

ttyOutTerminalState, err := term.GetState(int(screen.ttyOut.Fd()))
if err != nil {
return err
}
log.Info("ttyout terminal state: ", fmt.Sprintf("%+v", ttyOutTerminalState))

return nil
}

Expand Down
13 changes: 10 additions & 3 deletions twin/screen-setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,20 @@ func (screen *UnixScreen) setupTtyInTtyOut() error {
return err
}

updatedTerminalState, err := term.GetState(int(screen.ttyIn.Fd()))
screen.ttyOut = os.Stdout

ttyInTerminalState, err := term.GetState(int(screen.ttyIn.Fd()))
if err != nil {
return err
}
log.Info("Raw terminal state: ", fmt.Sprintf("%+v", updatedTerminalState))
log.Info("ttyin terminal state: ", fmt.Sprintf("%+v", ttyInTerminalState))

ttyOutTerminalState, err := term.GetState(int(screen.ttyOut.Fd()))
if err != nil {
return err
}
log.Info("ttyout terminal state: ", fmt.Sprintf("%+v", ttyOutTerminalState))

screen.ttyOut = os.Stdout
return nil
}

Expand Down

0 comments on commit 69a7f5d

Please sign in to comment.