go-sh-manymanuals/gshmm.go

82 lines
1.1 KiB
Go
Raw Normal View History

2023-05-10 00:49:15 +02:00
package main
import (
"flag"
"fmt"
"os"
2023-05-10 01:09:56 +02:00
"github.com/charmbracelet/bubbles/textinput"
2023-05-10 00:49:15 +02:00
tea "github.com/charmbracelet/bubbletea"
)
const help = `go-sh-manymanuals: TODO
TODO
Options:
-h output help
`
var helpFlag bool
type Configuration struct {
ManualDir string
}
func handleCliFlags() {
flag.BoolVar(&helpFlag, "h", false, "output help")
flag.Parse()
}
type model struct {
2023-05-10 01:09:56 +02:00
filterInput textinput.Model
2023-05-10 00:49:15 +02:00
}
func initialModel() model {
2023-05-10 01:09:56 +02:00
input := textinput.New()
input.Focus()
return model{
filterInput: input,
}
2023-05-10 00:49:15 +02:00
}
func (m model) Init() tea.Cmd {
2023-05-10 01:09:56 +02:00
return textinput.Blink
2023-05-10 00:49:15 +02:00
}
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
2023-05-10 01:09:56 +02:00
var cmd tea.Cmd
2023-05-10 00:49:15 +02:00
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
case "ctrl+c", "q":
return m, tea.Quit
}
}
2023-05-10 01:09:56 +02:00
m.filterInput, cmd = m.filterInput.Update(msg)
return m, cmd
2023-05-10 00:49:15 +02:00
}
func (m model) View() string {
2023-05-10 01:09:56 +02:00
return m.filterInput.View()
2023-05-10 00:49:15 +02:00
}
func main() {
handleCliFlags()
if helpFlag {
fmt.Printf(help)
os.Exit(0)
}
p := tea.NewProgram(initialModel(), tea.WithAltScreen())
if err := p.Start(); err != nil {
fmt.Printf("oops, something went wrong: %v", err)
os.Exit(1)
}
}