diff --git a/game/game.go b/game/game.go index 28b3a5e..c185267 100644 --- a/game/game.go +++ b/game/game.go @@ -348,16 +348,16 @@ func (state *State) RenderUI(w io.Writer, width int) int { switch state.UIState { case StateGame: - fmt.Fprintln(w, AnsiDimmed("[enter]/[tab]: next word | [ctrl+a]: menu | [ctrl+c]: exit")) + fmt.Fprint(w, AnsiDimmed("[enter]/[tab]: next word | [ctrl+a]: menu | [ctrl+c]: exit\r\n")) uiHeight += 1 case StateMenu: - fmt.Fprintln(w, AnsiDimmed("[c]: check puzzle/word | [r]: reveal puzzle/word | [x]: clear grid | [q]: exit menu")) + fmt.Fprint(w, AnsiDimmed("[c]: check puzzle/word | [r]: reveal puzzle/word | [x]: clear grid | [q]: exit menu\r\n")) uiHeight += 1 case StateCheckMenu: - fmt.Fprintln(w, AnsiDimmed("[w]: check word | [p]: check puzzle | [q]: exit menu")) + fmt.Fprint(w, AnsiDimmed("[w]: check word | [p]: check puzzle | [q]: exit menu\r\n")) uiHeight += 1 case StateRevealMenu: - fmt.Fprintln(w, AnsiDimmed("[w]: reveal word | [p]: reveal puzzle | [q]: exit menu")) + fmt.Fprint(w, AnsiDimmed("[w]: reveal word | [p]: reveal puzzle | [q]: exit menu\r\n")) uiHeight += 1 } diff --git a/ssh/main.go b/ssh/main.go index 47f65c5..47ae551 100644 --- a/ssh/main.go +++ b/ssh/main.go @@ -39,8 +39,20 @@ func main() { io.WriteString(s, "\x1b[?25h") }() - pty, _, _ := s.Pty() // TODO: actually handle terminal size changes - uiHeight := state.RenderUI(s, pty.Window.Width) + pty, winCh, isPty := s.Pty() + if !isPty { + return + } + + windowWidth := pty.Window.Width + + uiHeight := state.RenderUI(s, windowWidth) + + go func() { + for window := range winCh { + windowWidth = window.Width + } + }() scanner := bufio.NewScanner(s) scanner.Split(func(data []byte, atEOF bool) (advance int, token []byte, err error) { @@ -72,14 +84,14 @@ func main() { state.SelectedCell = -1 fmt.Fprintf(s, "\r\x1b[%dA", uiHeight) fmt.Fprint(s, "\x1b[J") - state.RenderUI(s, pty.Window.Width) + state.RenderUI(s, windowWidth) break } fmt.Fprintf(s, "\r\x1b[%dA", uiHeight) fmt.Fprint(s, "\x1b[J") - uiHeight = state.RenderUI(s, pty.Window.Width) + uiHeight = state.RenderUI(s, windowWidth) } log.Printf("%s disconnected\n", s.RemoteAddr().String())