fix: correct width over ssh

This commit is contained in:
2025-06-01 16:14:09 +01:00
parent 159cdc14a0
commit 8b29b35764

18
main.go
View File

@ -91,7 +91,7 @@ func getViewPort(width int, height int) viewport.Model {
return vp return vp
} }
func initialModel() model { func initialModel(w int, h int) model {
posts, err := getAllPosts("/home/johnc/Code/JohnTech/content/blog") posts, err := getAllPosts("/home/johnc/Code/JohnTech/content/blog")
if err != nil { if err != nil {
panic(err) panic(err)
@ -107,11 +107,6 @@ func initialModel() model {
listItems[i] = item{title: postInfo.Title, desc: postInfo.Date.String(), index: i} 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 := list.New(listItems, list.NewDefaultDelegate(), w, h-4)
list.SetShowTitle(false) list.SetShowTitle(false)
@ -305,7 +300,12 @@ func main() {
if isSsh { if isSsh {
initServer() initServer()
} else { } 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 { if _, err := p.Run(); err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -318,7 +318,7 @@ func main() {
// tea.WithAltScreen) on a session by session basis. // tea.WithAltScreen) on a session by session basis.
func teaHandler(s ssh.Session) (tea.Model, []tea.ProgramOption) { func teaHandler(s ssh.Session) (tea.Model, []tea.ProgramOption) {
// This should never fail, as we are using the activeterm middleware. // 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 // When running a Bubble Tea app over SSH, you shouldn't use the default
// lipgloss.NewStyle function. // lipgloss.NewStyle function.
@ -338,6 +338,6 @@ func teaHandler(s ssh.Session) (tea.Model, []tea.ProgramOption) {
// bg = "dark" // bg = "dark"
// } // }
m := initialModel() m := initialModel(pty.Window.Width, pty.Window.Height)
return m, []tea.ProgramOption{tea.WithAltScreen()} return m, []tea.ProgramOption{tea.WithAltScreen()}
} }