diff --git a/pkg/tui/bubbletea.go b/pkg/tui/bubbletea.go deleted file mode 100644 index e2d3d4b6..00000000 --- a/pkg/tui/bubbletea.go +++ /dev/null @@ -1,44 +0,0 @@ -package tui - -import ( - "io" - "log" - "os" - - tea "github.com/charmbracelet/bubbletea" - "github.com/fatih/color" - "github.com/mattn/go-isatty" -) - -func Start() { - opts := []tea.ProgramOption{tea.WithoutRenderer()} - - if isatty.IsTerminal(os.Stdout.Fd()) { - // If we're in TUI mode, discard log output - opts = []tea.ProgramOption{} - } - - p := tea.NewProgram(NewTerminalUI(), opts...) - go func() { - if _, err := p.StartReturningModel(); err != nil { - log.Panic(err) - } - }() -} - -func silence() func() { - null, _ := os.Open(os.DevNull) - sout := os.Stdout - serr := os.Stderr - - color.Output = null - color.Error = null - log.SetOutput(io.Discard) - - return func() { - defer null.Close() - color.Output = sout - color.Error = serr - log.SetOutput(os.Stderr) - } -} diff --git a/pkg/tui/init.go b/pkg/tui/init.go deleted file mode 100644 index 582c643e..00000000 --- a/pkg/tui/init.go +++ /dev/null @@ -1,12 +0,0 @@ -package tui - -import ( - tea "github.com/charmbracelet/bubbletea" -) - -func (this *TerminalUI) Init() tea.Cmd { - return tea.Batch( - this.spinner.Tick, - this.waitForEvent(), - ) -} diff --git a/pkg/tui/print.go b/pkg/tui/print.go deleted file mode 100644 index 1414f9e2..00000000 --- a/pkg/tui/print.go +++ /dev/null @@ -1,5 +0,0 @@ -package tui - -func Print(ev Event) { - events <- ev -} diff --git a/pkg/tui/spinner.go b/pkg/tui/spinner.go deleted file mode 100644 index 1dc1e0db..00000000 --- a/pkg/tui/spinner.go +++ /dev/null @@ -1,14 +0,0 @@ -package tui - -import ( - "github.com/charmbracelet/bubbles/spinner" - "github.com/charmbracelet/lipgloss" -) - -func newSpinner() spinner.Model { - sp := spinner.New() - sp.Spinner = spinner.Points - sp.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("#326ce5")) - - return sp -} diff --git a/pkg/tui/types.go b/pkg/tui/types.go deleted file mode 100644 index f9cd981a..00000000 --- a/pkg/tui/types.go +++ /dev/null @@ -1,62 +0,0 @@ -package tui - -import ( - "time" - - "github.com/charmbracelet/bubbles/spinner" - tea "github.com/charmbracelet/bubbletea" -) - -var ( - events = make(chan Event) -) - -// TerminalUI implements tea.Model interface -type TerminalUI struct { - in chan Event - events []Event - spinner spinner.Model -} - -type View interface { - View() -} - -type printView struct { - in chan Event - events []Event -} - -type progressView struct { - in chan Event - events []Event - spinner spinner.Model -} - -type Mode string - -const ( - ModeProgress = "progress" - ModePrint = "print" -) - -type EventType string - -const ( - EventTypeProgress = EventType("progress") - EventTypeMessage = EventType("message") -) - -type Event struct { - Name string - Message string - Took time.Duration -} - -func NewTerminalUI() tea.Model { - return &TerminalUI{ - in: events, - events: make([]Event, 5), - spinner: newSpinner(), - } -} diff --git a/pkg/tui/update.go b/pkg/tui/update.go deleted file mode 100644 index 7fa133ef..00000000 --- a/pkg/tui/update.go +++ /dev/null @@ -1,38 +0,0 @@ -package tui - -import ( - "github.com/charmbracelet/bubbles/spinner" - tea "github.com/charmbracelet/bubbletea" -) - -func (this *TerminalUI) Update(msg tea.Msg) (tea.Model, tea.Cmd) { - switch v := msg.(type) { - case tea.KeyMsg: - return this, tea.Quit - case spinner.TickMsg: - return this, this.handleSpinnerUpdate(v) - case Event: - return this, this.handleEventUpdate(v) - } - - return this, nil -} - -func (this *TerminalUI) handleSpinnerUpdate(tick spinner.TickMsg) tea.Cmd { - var cmd tea.Cmd - this.spinner, cmd = this.spinner.Update(tick) - - return cmd -} - -func (this *TerminalUI) handleEventUpdate(event Event) tea.Cmd { - this.events = append(this.events, event) - - return this.waitForEvent() -} - -func (this *TerminalUI) waitForEvent() tea.Cmd { - return func() tea.Msg { - return <-this.in - } -} diff --git a/pkg/tui/view.go b/pkg/tui/view.go deleted file mode 100644 index ea0dfcae..00000000 --- a/pkg/tui/view.go +++ /dev/null @@ -1,22 +0,0 @@ -package tui - -import ( - "fmt" - - "github.com/muesli/reflow/indent" -) - -func (this *TerminalUI) View() string { - s := "\n" + - this.spinner.View() + " Creating a cluster\n\n" - - for _, ev := range this.events { - if len(ev.Name) == 0 { - continue - } - - s += fmt.Sprintf("%s %s\n", ev.Name, ev.Took) - } - - return indent.String(s, 1) -}