package tui import ( "github.com/gdamore/tcell/v2" "github.com/rivo/tview" "suruatoel.xyz/timefiles/lib" ) // MainScreen represents the main screen of the user interface. type MainScreen struct { app *TUI main *tview.Flex tabs *Tabs timesPage *DayUI statusBar *StatusBar help *tview.TextView } // NewMainScreen creates a new main screen of the user interface. func NewMainScreen(app *TUI) (*MainScreen, error) { ui := MainScreen{ app: app, } ui.tabs = NewTabs(true) ui.timesPage = NewDayUI(app) ui.tabs.AddTab("times", "Times", ui.timesPage, true) ui.statusBar = NewStatusBar() ui.main = tview.NewFlex(). SetDirection(tview.FlexRow). AddItem(ui.tabs, 0, 1, false). AddItem(ui.statusBar, 1, 1, false) ui.tabs.Select("times") app.uiApp.SetRoot(ui.main, true).EnableMouse(true).SetFocus(ui.timesPage) ui.addShortcuts() return &ui, nil } // SetStatus displays a message in the status bar. func (ui *MainScreen) SetStatus(message string) { ui.statusBar.SetStatus(message) } // SetTimer displays the current timer on the times page. func (ui *MainScreen) SetTimer(timer *lib.Time) { ui.timesPage.SetTimer(timer) } // SetSummary displays the time summary on the times page. func (ui *MainScreen) SetSummary(summary []*lib.Time) { ui.timesPage.SetSummary(summary) } // SetTotals displays the time totals on the times page. func (ui *MainScreen) SetTotals(totalTime lib.TotalTime) { ui.timesPage.SetTotals(totalTime) } // addShortcuts registers keyboard shortcuts for the main screen. func (ui *MainScreen) addShortcuts() { ui.main.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { switch event.Key() { case tcell.KeyCtrlN: ui.app.Focus(ui.tabs.Next()) return nil case tcell.KeyCtrlP: ui.app.Focus(ui.tabs.Prev()) return nil } return event }) }