Fix full screen size

This commit is contained in:
IamTheFij 2024-10-18 13:27:33 -07:00
parent 5451e54082
commit fcbf201460

29
main.go
View File

@ -106,7 +106,7 @@ func (m model) Init() tea.Cmd {
os.Exit(0) os.Exit(0)
}() }()
return textinput.Blink return tea.Batch(tea.WindowSize(), textinput.Blink)
} }
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
@ -204,15 +204,15 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// Run onFocusStart commands // Run onFocusStart commands
m.runCommands(m.onFocusStart) m.runCommands(m.onFocusStart)
} }
return m, tick() return m, tick()
} }
return m, tick() return m, tick()
case tea.WindowSizeMsg: case tea.WindowSizeMsg:
if m.fullscreen { m.width = msg.Width
m.width = msg.Width m.height = msg.Height
m.height = msg.Height
}
} }
// Update text inputs // Update text inputs
@ -274,8 +274,12 @@ func (m model) inputScreenView() string {
// View for timer screen with optional fullscreen centering // View for timer screen with optional fullscreen centering
func (m model) timerScreenView() string { func (m model) timerScreenView() string {
progressView := m.progressBar.ViewAs(float64(m.totalTime-m.remaining) / float64(m.totalTime)) if m.fullscreen {
progressBarPadding := 5
m.progressBar.Width = m.width - progressBarPadding
}
progressView := m.progressBar.ViewAs(float64(m.totalTime-m.remaining) / float64(m.totalTime))
status := lipgloss.NewStyle().Bold(true).Render(fmt.Sprintf("State: %s", m.state)) status := lipgloss.NewStyle().Bold(true).Render(fmt.Sprintf("State: %s", m.state))
intervalInfo := fmt.Sprintf("Interval: %d / %d", m.intervalNum, m.intervals) intervalInfo := fmt.Sprintf("Interval: %d / %d", m.intervalNum, m.intervals)
timeLeft := fmt.Sprintf("Time left: %s", m.remaining.String()) timeLeft := fmt.Sprintf("Time left: %s", m.remaining.String())
@ -404,10 +408,17 @@ func main() {
} }
// Start tea program // Start tea program
p := tea.NewProgram(m, tea.WithAltScreen())
_, err := p.Run()
return err options := []tea.ProgramOption{}
if m.fullscreen {
options = append(options, tea.WithAltScreen())
}
p := tea.NewProgram(m, options...)
if _, err := p.Run(); err != nil {
return fmt.Errorf("error running program: %w", err)
}
return nil
}, },
} }