2021-03-08 12:48:34 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-09-14 18:00:38 -04:00
|
|
|
"log"
|
2021-03-08 12:48:34 -05:00
|
|
|
"os"
|
|
|
|
|
|
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
|
|
"github.com/muesli/termenv"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2022-02-05 22:19:46 -05:00
|
|
|
color = termenv.EnvColorProfile().Color
|
2021-03-08 12:48:34 -05:00
|
|
|
keyword = termenv.Style{}.Foreground(color("204")).Background(color("235")).Styled
|
2021-03-11 15:15:08 -05:00
|
|
|
help = termenv.Style{}.Foreground(color("241")).Styled
|
2021-03-08 12:48:34 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type model struct {
|
|
|
|
altscreen bool
|
|
|
|
quitting bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m model) Init() tea.Cmd {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
|
|
switch msg := msg.(type) {
|
|
|
|
case tea.KeyMsg:
|
|
|
|
switch msg.String() {
|
|
|
|
case "q", "ctrl+c", "esc":
|
|
|
|
m.quitting = true
|
|
|
|
return m, tea.Quit
|
|
|
|
case " ":
|
|
|
|
var cmd tea.Cmd
|
|
|
|
if m.altscreen {
|
|
|
|
cmd = tea.ExitAltScreen
|
|
|
|
} else {
|
|
|
|
cmd = tea.EnterAltScreen
|
|
|
|
}
|
|
|
|
m.altscreen = !m.altscreen
|
|
|
|
return m, cmd
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return m, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m model) View() string {
|
|
|
|
if m.quitting {
|
|
|
|
return "Bye!\n"
|
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
|
|
|
altscreenMode = " altscreen mode "
|
|
|
|
inlineMode = " inline mode "
|
|
|
|
)
|
|
|
|
|
2021-03-11 15:15:08 -05:00
|
|
|
var mode string
|
2021-03-08 12:48:34 -05:00
|
|
|
if m.altscreen {
|
|
|
|
mode = altscreenMode
|
|
|
|
} else {
|
|
|
|
mode = inlineMode
|
|
|
|
}
|
|
|
|
|
2021-03-11 15:15:08 -05:00
|
|
|
return fmt.Sprintf("\n\n You're in %s\n\n\n", keyword(mode)) +
|
|
|
|
help(" space: switch modes • q: exit\n")
|
2021-03-08 12:48:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2023-09-14 18:00:38 -04:00
|
|
|
f, err := tea.LogToFile("log.txt", "")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
defer f.Close()
|
2022-10-07 17:56:12 -04:00
|
|
|
if _, err := tea.NewProgram(model{}).Run(); err != nil {
|
2021-03-08 12:48:34 -05:00
|
|
|
fmt.Println("Error running program:", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|