feat: bootstrap cli entrypoint with bubble tea and toml config
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package tui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
// Model is the initial terminal UI for parasocial.
|
||||
type Model struct {
|
||||
streamers []string
|
||||
}
|
||||
|
||||
// New returns a Bubble Tea model that displays configured streamers.
|
||||
func New(streamers []string) Model {
|
||||
return Model{streamers: append([]string(nil), streamers...)}
|
||||
}
|
||||
|
||||
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 "ctrl+c", "esc", "q":
|
||||
return m, tea.Quit
|
||||
}
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m Model) View() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Streamers\n")
|
||||
|
||||
for i, streamer := range m.streamers {
|
||||
fmt.Fprintf(&builder, "%d. %s\n", i+1, streamer)
|
||||
}
|
||||
|
||||
builder.WriteString("\n")
|
||||
return builder.String()
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package tui
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestViewDisplaysStreamers(t *testing.T) {
|
||||
model := New([]string{"alpha", "beta"})
|
||||
|
||||
got := model.View()
|
||||
want := "Streamers\n1. alpha\n2. beta\n\n"
|
||||
if got != want {
|
||||
t.Fatalf("View() = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user