30 lines
502 B
Go
30 lines
502 B
Go
package tui
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
tea "charm.land/bubbletea/v2"
|
|
)
|
|
|
|
func Run() error {
|
|
p := tea.NewProgram(New())
|
|
m, err := p.Run()
|
|
if err != nil {
|
|
return fmt.Errorf("tui error: %w", err)
|
|
}
|
|
|
|
if model, ok := m.(Model); ok {
|
|
if model.command != "" {
|
|
if model.result.Error != nil {
|
|
fmt.Fprintf(os.Stderr, "failed: %s\n", model.command)
|
|
fmt.Fprintf(os.Stderr, "error: %v\n", model.result.Error)
|
|
} else {
|
|
fmt.Fprintf(os.Stdout, "%s\n", model.command)
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|