Fix full screen size
This commit is contained in:
parent
5451e54082
commit
fcbf201460
25
main.go
25
main.go
@ -106,7 +106,7 @@ func (m model) Init() tea.Cmd {
|
||||
os.Exit(0)
|
||||
}()
|
||||
|
||||
return textinput.Blink
|
||||
return tea.Batch(tea.WindowSize(), textinput.Blink)
|
||||
}
|
||||
|
||||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
@ -204,16 +204,16 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
// Run onFocusStart commands
|
||||
m.runCommands(m.onFocusStart)
|
||||
}
|
||||
|
||||
return m, tick()
|
||||
}
|
||||
|
||||
return m, tick()
|
||||
|
||||
case tea.WindowSizeMsg:
|
||||
if m.fullscreen {
|
||||
m.width = msg.Width
|
||||
m.height = msg.Height
|
||||
}
|
||||
}
|
||||
|
||||
// Update text inputs
|
||||
cmds := make([]tea.Cmd, len(m.inputs))
|
||||
@ -274,8 +274,12 @@ func (m model) inputScreenView() string {
|
||||
|
||||
// View for timer screen with optional fullscreen centering
|
||||
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))
|
||||
intervalInfo := fmt.Sprintf("Interval: %d / %d", m.intervalNum, m.intervals)
|
||||
timeLeft := fmt.Sprintf("Time left: %s", m.remaining.String())
|
||||
@ -404,10 +408,17 @@ func main() {
|
||||
}
|
||||
|
||||
// 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
|
||||
},
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user