|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/charmbracelet/bubbles/textinput"
|
|
|
|
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 {
|
|
|
|
filterInput textinput.Model
|
|
|
|
}
|
|
|
|
|
|
|
|
func initialModel() model {
|
|
|
|
input := textinput.New()
|
|
|
|
input.Focus()
|
|
|
|
|
|
|
|
return model{
|
|
|
|
filterInput: input,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m model) Init() tea.Cmd {
|
|
|
|
return textinput.Blink
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
|
|
var cmd tea.Cmd
|
|
|
|
|
|
|
|
switch msg := msg.(type) {
|
|
|
|
case tea.KeyMsg:
|
|
|
|
switch msg.String() {
|
|
|
|
case "ctrl+c", "q":
|
|
|
|
return m, tea.Quit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m.filterInput, cmd = m.filterInput.Update(msg)
|
|
|
|
|
|
|
|
return m, cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m model) View() string {
|
|
|
|
return m.filterInput.View()
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|