fix: correct width over ssh
This commit is contained in:
18
main.go
18
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()}
|
||||
}
|
||||
|
Reference in New Issue
Block a user