terminal resize handling

This commit is contained in:
2026-01-01 01:15:16 +00:00
parent 7b18904775
commit 5acfa16368
+15 -9
View File
@@ -37,8 +37,10 @@ this data in msg when returned to the update func is used to update the model
*/ */
type model struct { type model struct {
width int width int
tree *fs.FsTree terminalWidth int
terminalHeight int
tree *fs.FsTree
// spinner needs to be state as I need to update the spinner on // spinner needs to be state as I need to update the spinner on
// each tick in update func // each tick in update func
spinner spinner.Model spinner spinner.Model
@@ -52,10 +54,12 @@ func createModel() model {
s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("205")) s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("205"))
return model{ return model{
width: 30, // char count width: 30, // char count
tree: nil, terminalWidth: 0,
spinner: s, terminalHeight: 0,
loading: true, tree: nil,
spinner: s,
loading: true,
} }
} }
@@ -83,6 +87,10 @@ func (m model) Init() tea.Cmd {
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) { switch msg := msg.(type) {
case tea.WindowSizeMsg:
m.terminalWidth = msg.Width
m.terminalHeight = msg.Height
return m, nil
case treeLoadedMsg: case treeLoadedMsg:
m.tree = msg.tree m.tree = msg.tree
m.loading = false m.loading = false
@@ -124,11 +132,9 @@ func (m model) View() string {
right := lipgloss.NewStyle(). right := lipgloss.NewStyle().
Render("section2") Render("section2")
leftHeight := lipgloss.Height(left)
divider := lipgloss.NewStyle(). divider := lipgloss.NewStyle().
Width(1). Width(1).
Height(leftHeight). Height(m.terminalHeight).
Background(styles.Primary). Background(styles.Primary).
Render("") // everything is a string in tui Render("") // everything is a string in tui