| 1 | package tui |
| 2 | |
| 3 | import ( |
| 4 | "time" |
| 5 | |
| 6 | "charm.land/bubbles/v2/help" |
| 7 | tea "charm.land/bubbletea/v2" |
| 8 | ) |
| 9 | |
| 10 | type sessionState uint8 |
| 11 | |
| 12 | const ( |
| 13 | stateList sessionState = iota |
| 14 | stateContent |
| 15 | stateForm |
| 16 | ) |
| 17 | |
| 18 | type Model struct { |
| 19 | backend Backend |
| 20 | isRemote bool |
| 21 | |
| 22 | state sessionState |
| 23 | list listModel |
| 24 | cont contentModel |
| 25 | form formModel |
| 26 | |
| 27 | width, height int |
| 28 | ready bool |
| 29 | loading bool |
| 30 | |
| 31 | showHelp bool |
| 32 | confirmDelete bool |
| 33 | |
| 34 | status string |
| 35 | statusOK bool |
| 36 | statusUntil time.Time |
| 37 | |
| 38 | help help.Model |
| 39 | keys keyMap |
| 40 | } |
| 41 | |
| 42 | func newModel(backend Backend) Model { |
| 43 | return Model{ |
| 44 | backend: backend, |
| 45 | isRemote: backend.RemoteURL() != "", |
| 46 | state: stateList, |
| 47 | list: newListModel(nil), |
| 48 | cont: newContentModel(), |
| 49 | form: newFormModel(), |
| 50 | help: help.New(), |
| 51 | keys: defaultKeys(), |
| 52 | loading: true, |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | func (m Model) Init() tea.Cmd { |
| 57 | return tea.Batch(tea.RequestWindowSize, loadSnippetsCmd(m.backend)) |
| 58 | } |