summaryrefslogtreecommitdiff
path: root/tui.go
blob: 12bb665daafdb84925ef53721d29ec6416e4246b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main

import (
	"os"

	tea "github.com/charmbracelet/bubbletea"
)

type TUIModel struct {
	State *BrowserState
}

func NewTUIModel(state *BrowserState) TUIModel {
	return TUIModel{State: state}
}

func (model TUIModel) Init() tea.Cmd {
	return nil
}

func (model TUIModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
	switch msg := msg.(type) {
	case tea.KeyMsg:
		switch msg.String() {
		case "ctrl+c", "ctrl+d", "q":
			return model, tea.Quit
		}
	}

	return model, nil
}

func (model TUIModel) View() string {
	return "pardon our dust"
}

func runTUI(state *BrowserState) {
	p := tea.NewProgram(NewTUIModel(state))
	if _, err := p.Run(); err != nil {
		writeError(err.Error())
		os.Exit(1)
	}
}