From 8b29b35764d450c2fe11b6aaa6e367c1a8ebc9a8 Mon Sep 17 00:00:00 2001 From: John Costa Date: Sun, 1 Jun 2025 16:14:09 +0100 Subject: [PATCH] fix: correct width over ssh --- main.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index a01fac2..29ec770 100644 --- a/main.go +++ b/main.go @@ -91,7 +91,7 @@ func getViewPort(width int, height int) viewport.Model { return vp } -func initialModel() model { +func initialModel(w int, h int) model { posts, err := getAllPosts("/home/johnc/Code/JohnTech/content/blog") if err != nil { panic(err) @@ -107,11 +107,6 @@ func initialModel() model { listItems[i] = item{title: postInfo.Title, desc: postInfo.Date.String(), index: i} } - w, h, err := term.GetSize(os.Stdout.Fd()) - if err != nil { - panic(err) - } - list := list.New(listItems, list.NewDefaultDelegate(), w, h-4) list.SetShowTitle(false) @@ -305,7 +300,12 @@ func main() { if isSsh { initServer() } else { - p := tea.NewProgram(initialModel()) + w, h, err := term.GetSize(os.Stdout.Fd()) + if err != nil { + panic(err) + } + + p := tea.NewProgram(initialModel(w, h)) if _, err := p.Run(); err != nil { log.Fatal(err) } @@ -318,7 +318,7 @@ func main() { // tea.WithAltScreen) on a session by session basis. func teaHandler(s ssh.Session) (tea.Model, []tea.ProgramOption) { // This should never fail, as we are using the activeterm middleware. - // pty, _, _ := s.Pty() + pty, _, _ := s.Pty() // When running a Bubble Tea app over SSH, you shouldn't use the default // lipgloss.NewStyle function. @@ -338,6 +338,6 @@ func teaHandler(s ssh.Session) (tea.Model, []tea.ProgramOption) { // bg = "dark" // } - m := initialModel() + m := initialModel(pty.Window.Width, pty.Window.Height) return m, []tea.ProgramOption{tea.WithAltScreen()} }