diff --git a/README.md b/README.md index 0aadfc5..3edc878 100644 --- a/README.md +++ b/README.md @@ -365,6 +365,8 @@ link preview from them. ./interzone -no-mouse # leave the mouse to the terminal ./interzone -layout compact # phone layout, whatever the size (or wide, or auto) ./interzone -theme nord # colours for one run (ctrl+y switches and remembers them) +./interzone -plain # no colours, ASCII boxes and bars, no animation: for screen + # readers and logs (or INTERZONE_PLAIN=1) ``` The wizard has four steps before the deploy: **Server** (where it runs, diff --git a/internal/ui/app.go b/internal/ui/app.go index 31eebbd..24e4f35 100644 --- a/internal/ui/app.go +++ b/internal/ui/app.go @@ -299,7 +299,10 @@ func (a *App) back() tea.Cmd { return a.go_(-1) } -func (a *App) View() string { +func (a *App) View() (out string) { + if plain { + defer func() { out = plainText.Replace(out) }() + } if a.w == 0 { return "" } diff --git a/internal/ui/plain_test.go b/internal/ui/plain_test.go new file mode 100644 index 0000000..eed57eb --- /dev/null +++ b/internal/ui/plain_test.go @@ -0,0 +1,28 @@ +package ui + +import ( + "strings" + "testing" + + "github.com/charmbracelet/lipgloss" +) + +// Plain mode draws the same layout in ASCII, with nothing animated. +func TestPlain(t *testing.T) { + defer func() { plain = false }() + SetPlain() + a := demoApp(t, 120, 36) + openDashboard(a) + v := a.View() + if strings.ContainsAny(v, "╭│─█▌▁◢\x1b") || !strings.Contains(v, "+---") { + t.Errorf("not plain:\n%s", v) + } + for _, l := range strings.Split(v, "\n") { + if lipgloss.Width(l) > 120 { + t.Fatalf("a line grew: %q", l) + } + } + if sp := newSpinner(); len(sp.Spinner.Frames) != 1 { + t.Error("the spinner still turns") + } +} diff --git a/internal/ui/screens_setup.go b/internal/ui/screens_setup.go index ab421b7..688ec35 100644 --- a/internal/ui/screens_setup.go +++ b/internal/ui/screens_setup.go @@ -72,7 +72,7 @@ func (s *welcomeScreen) view(w, h int) string { return sPink.Render(icon) + " " + sTitle.Render(title) + "\n " + wrap(sMuted, " ", text) } brand := gradientLines(strings.TrimPrefix(logo, "\n")) - if lipgloss.Width(brand) > w { + if lipgloss.Width(brand) > w || plain { brand = gradient("◢◤ interzone") } head := lipgloss.JoinVertical(lipgloss.Center, diff --git a/internal/ui/screens_tools.go b/internal/ui/screens_tools.go index c9547db..34d8406 100644 --- a/internal/ui/screens_tools.go +++ b/internal/ui/screens_tools.go @@ -24,6 +24,9 @@ import ( func newSpinner() spinner.Model { sp := spinner.New() sp.Spinner = spinner.MiniDot + if plain { // a redraw a second would have screen readers read it again + sp.Spinner = spinner.Spinner{Frames: []string{"…"}, FPS: time.Hour} + } sp.Style = sAccent return sp } diff --git a/internal/ui/theme.go b/internal/ui/theme.go index 5ea7ad8..78aa176 100644 --- a/internal/ui/theme.go +++ b/internal/ui/theme.go @@ -7,6 +7,7 @@ import ( "github.com/charmbracelet/lipgloss" "github.com/lucasb-eyer/go-colorful" + "github.com/muesli/termenv" "interzone/internal/config" ) @@ -233,6 +234,25 @@ func ramp(stops []string, t float64) string { return a.BlendLuv(z, seg-float64(i)).Clamped().Hex() } +// plain is plain mode, for screen readers and logs: no colours, and the +// box, bar and block characters drawn in ASCII. +var plain bool + +// SetPlain turns plain mode on, before the app starts. +func SetPlain() { + plain = true + lipgloss.SetColorProfile(termenv.Ascii) +} + +// plainText swaps the drawing characters for ASCII ones of the same width; +// sparklines become digits, 1 low to 8 full. +var plainText = strings.NewReplacer( + "╭", "+", "╮", "+", "╰", "+", "╯", "+", "┌", "+", "┐", "+", "└", "+", "┘", "+", "├", "+", "┤", "+", "┬", "+", "┴", "+", "┼", "+", + "│", "|", "─", "-", "▌", ">", "░", ".", "▸", ">", "▾", "v", "›", ">", "●", "*", "○", "o", + "▁", "1", "▂", "2", "▃", "3", "▄", "4", "▅", "5", "▆", "6", "▇", "7", "█", "8", + "◢◤", " ", +) + const logo = ` ▀█▀ █▄ █ ▀█▀ █▀▀ █▀█ ▀▀█ █▀█ █▄ █ █▀▀ █ █ ▀█ █ ██▄ █▀▄ ▄▀ █▄█ █ ▀█ ██▄` diff --git a/main.go b/main.go index 4c17ade..672a126 100644 --- a/main.go +++ b/main.go @@ -42,6 +42,7 @@ func main() { theme := flag.String("theme", "", "the colours for this run: "+strings.Join(ui.ThemeNames(), ", ")+"; ctrl+y in the app switches and remembers them") layout := flag.String("layout", "", "auto, compact (phones, narrow or portrait terminals) or wide; the default is the last one picked in the app, else auto") noMouse := flag.Bool("no-mouse", false, "don't take the mouse, so the terminal can select text without shift") + plain := flag.Bool("plain", os.Getenv("INTERZONE_PLAIN") != "", "no colours, and ASCII instead of boxes, bars and an animated spinner: for screen readers and logs (also INTERZONE_PLAIN=1)") flag.Usage = func() { fmt.Fprintln(flag.CommandLine.Output(), cli.Usage+"\n\nOptions:") flag.PrintDefaults() @@ -67,6 +68,9 @@ func main() { if !*noMouse { opts = append(opts, tea.WithMouseCellMotion()) } + if *plain { + ui.SetPlain() // before New: the screens' spinners are made there + } app := ui.New(cfg, loaded) if *layout != "" { if *layout != "auto" && *layout != "compact" && *layout != "wide" {