Plain mode for screen readers and logs: -plain or INTERZONE_PLAIN=1
Screen readers read every box-drawing character and re-read the screen on each spinner frame, and recorded sessions fill with colour codes. Plain mode drops colour, swaps box, bar, sparkline and marker characters for ASCII ones of the same width in the final frame, so layouts don't move, and keeps the spinner still. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5560782fe8
commit
e0a4625168
7 files changed
+62
-2
No files matched your search
@@ -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,
|
||||
|
||||
+4
-1
@@ -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 ""
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 = `
|
||||
▀█▀ █▄ █ ▀█▀ █▀▀ █▀█ ▀▀█ █▀█ █▄ █ █▀▀
|
||||
█ █ ▀█ █ ██▄ █▀▄ ▄▀ █▄█ █ ▀█ ██▄`
|
||||
|
||||
@@ -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" {
|
||||
|
||||
Reference in new issue
Block a user