Screenshots for the wiki's guide; emoji and wide characters render right
TestShot also draws Review's confirm, a deploy part way and finished, Manage, Dashboard, Backups and Alerts on the Friends & family preset, without starting anything. render.py gives wide characters two cells, as the terminal does, and draws emoji from Noto Color Emoji. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bf168a4c3e
commit
fce7d7b1ce
2 files changed
+93
-3
No files matched your search
@@ -3,10 +3,16 @@ package ui
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/muesli/termenv"
|
||||
|
||||
"interzone/internal/catalog"
|
||||
"interzone/internal/config"
|
||||
"interzone/internal/deploy"
|
||||
)
|
||||
|
||||
// TestShot draws screens that need a server, on the layout tests' sample
|
||||
@@ -22,16 +28,86 @@ func TestShot(t *testing.T) {
|
||||
open func(*App)
|
||||
}{
|
||||
{"users", openUsers},
|
||||
// The wiki's guide, on the Friends & family preset.
|
||||
{"wiki-confirm", func(a *App) {
|
||||
a.cfg.Target = config.Target{Mode: "ssh", Host: "192.0.2.1", User: "root"}
|
||||
a.jump(a.index("Review"))
|
||||
rs := a.cur().(*reviewScreen)
|
||||
rs.checking, rs.verbose, rs.confirm = false, true, true
|
||||
rs.checks = []deploy.Finding{
|
||||
{Group: "Server", Name: "Connect", Detail: "root@192.0.2.1, Debian 12, 4 CPUs, 8 GB RAM"},
|
||||
{Group: "DNS", Name: "matrix.example.org", Service: "Synapse", Detail: "192.0.2.1"},
|
||||
{Group: "DNS", Name: "element.example.org", Service: "Element Web", Detail: "192.0.2.1"},
|
||||
{Group: "DNS", Name: "sable.example.org", Service: "Sable", Detail: "192.0.2.1"},
|
||||
{Group: "DNS", Name: "call.element.example.org", Service: "Element Call", Detail: "192.0.2.1"},
|
||||
{Group: "Federation", Name: "example.org", Detail: ".well-known/matrix/server points at matrix.example.org:443"},
|
||||
}
|
||||
}},
|
||||
{"wiki-deploy", func(a *App) { fakeDeploy(a, false) }},
|
||||
{"wiki-deployed", func(a *App) { fakeDeploy(a, true) }},
|
||||
{"wiki-manage", func(a *App) {
|
||||
a.jump(a.index("Manage"))
|
||||
a.health = &deploy.Health{Up: true, Trusted: true, CertLeft: 89 * 24 * time.Hour}
|
||||
}},
|
||||
{"wiki-dashboard", openDashboard},
|
||||
{"wiki-backups", func(a *App) {
|
||||
a.jump(a.index("Backups"))
|
||||
a.cur().(*backupsScreen).form.get("on").on = true
|
||||
}},
|
||||
{"wiki-alerts", func(a *App) {
|
||||
a.jump(a.index("Alerts"))
|
||||
f := a.cur().(*alertsScreen).form
|
||||
f.get("on").on = true
|
||||
f.get("format").choice = 2
|
||||
f.get("room").input.SetValue("#alerts:example.org")
|
||||
}},
|
||||
}
|
||||
for _, s := range shots {
|
||||
a := demoApp(t, 120, 36)
|
||||
a.cfg.Sources.Blackout = true // like the other shots
|
||||
if strings.HasPrefix(s.name, "wiki-") {
|
||||
t.Setenv("XDG_CONFIG_HOME", "/home/demo/.config")
|
||||
a.cfg.Sources.Blackout = false
|
||||
a.cfg.Components = map[string]bool{}
|
||||
for _, id := range catalog.Presets[1].Components {
|
||||
a.cfg.Components[id] = true
|
||||
}
|
||||
}
|
||||
lipgloss.SetColorProfile(termenv.TrueColor)
|
||||
lipgloss.SetHasDarkBackground(true)
|
||||
s.open(a)
|
||||
if strings.HasPrefix(s.name, "wiki-") {
|
||||
a.status = "" // the demo's home can't be saved to
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(dir, s.name+".ans"), []byte(a.View()+"\n"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
lipgloss.SetColorProfile(termenv.Ascii)
|
||||
}
|
||||
|
||||
// fakeDeploy shows a first install part way through, or finished, without
|
||||
// starting one: entering the Deploy screen would.
|
||||
func fakeDeploy(a *App, finished bool) {
|
||||
a.step = a.index("Deploy")
|
||||
ds := a.cur().(*deployScreen)
|
||||
ds.cfg, ds.opts = a.cfg, deploy.Options{Action: deploy.ActionInstall}
|
||||
ds.states, ds.running, ds.follow = map[deploy.Step]stepState{}, true, true
|
||||
ds.started = time.Now().Add(-14 * time.Minute)
|
||||
ds.handle(deploy.Event{Plan: deploy.Plan(deploy.ActionInstall)})
|
||||
for _, st := range []deploy.Step{deploy.StepAnsible, deploy.StepPlaybook, deploy.StepInventory, deploy.StepRoles, deploy.StepImages, deploy.StepMirrors, deploy.StepInstall} {
|
||||
ds.handle(deploy.Event{Step: st, Started: true})
|
||||
}
|
||||
for _, task := range []string{"matrix-base : Ensure Matrix base paths exist", "docker : Install Docker", "matrix-postgres : Ensure Postgres container is running",
|
||||
"matrix-synapse : Ensure Synapse container image is pulled", "matrix-client-element : Ensure Element Web config installed", "coturn : Ensure Coturn configuration is in place"} {
|
||||
line := "TASK [" + task + "] ****"
|
||||
ds.handle(deploy.Event{Step: deploy.StepInstall, Line: line, Task: task})
|
||||
ds.handle(deploy.Event{Step: deploy.StepInstall, Line: "ok: [matrix.example.org]"})
|
||||
}
|
||||
ds.elapsed = 14*time.Minute + 32*time.Second
|
||||
if finished {
|
||||
ds.handle(deploy.Event{Step: deploy.StepSelfCheck, Started: true})
|
||||
ds.handle(deploy.Event{Done: true, Result: &deploy.Result{Passed: []string{"Synapse", "Element Web", "Sable", "Element Call", "Matrix Authentication Service", "Ketesa"}}})
|
||||
ds.elapsed = 23*time.Minute + 8*time.Second
|
||||
}
|
||||
}
|
||||
@@ -6,13 +6,14 @@
|
||||
# Puts already rendered windows side by side (docs/screenshots/phone.png).
|
||||
#
|
||||
# Needs Pillow, fontTools and the DejaVu and Noto symbol fonts.
|
||||
import re, sys
|
||||
import re, sys, unicodedata
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
from fontTools.ttLib import TTFont
|
||||
|
||||
SIZE = 26
|
||||
FONTS = ["/usr/share/fonts/TTF/DejaVuSansMono.ttf", "/usr/share/fonts/TTF/DejaVuSansMono-Bold.ttf"]
|
||||
FALLBACK = ["/usr/share/fonts/TTF/DejaVuSans.ttf", "/usr/share/fonts/noto/NotoSansSymbols2-Regular.ttf", "/usr/share/fonts/noto/NotoSansMath-Regular.ttf"]
|
||||
EMOJI = "/usr/share/fonts/noto/NotoColorEmoji.ttf" # a bitmap font: drawn at 109 px, then scaled
|
||||
BG, FG = (21, 19, 30), (220, 216, 235)
|
||||
|
||||
reg = ImageFont.truetype(FONTS[0], SIZE)
|
||||
@@ -48,6 +49,14 @@ def draw_cell(d, ch, px, py, fg):
|
||||
if "r" in a: d.rectangle([mx, my - 1, r, my], fill=fg)
|
||||
return True
|
||||
|
||||
def draw_emoji(img, ch, px, py):
|
||||
e = Image.new("RGBA", (160, 160))
|
||||
ImageDraw.Draw(e).text((0, 0), ch, font=ImageFont.truetype(EMOJI, 109), embedded_color=True)
|
||||
e = e.crop(e.getbbox())
|
||||
h = CH - 6
|
||||
e = e.resize((max(1, round(e.width * h / e.height)), h), Image.LANCZOS)
|
||||
img.paste(e, (px + (2 * CW - e.width) // 2, py + 3), e)
|
||||
|
||||
def finish(img, out, width=None):
|
||||
if width:
|
||||
img = img.resize((width, round(img.height * width / img.width)), Image.LANCZOS)
|
||||
@@ -95,7 +104,10 @@ for line in lines:
|
||||
if line[i] == "\x1b": # other escapes
|
||||
m2 = re.compile(r"\x1b\[[0-9;?]*[A-Za-z]").match(line, i)
|
||||
i = m2.end() if m2 else i + 1; continue
|
||||
row.append((line[i], fg, bg, b)); i += 1
|
||||
row.append((line[i], fg, bg, b))
|
||||
if unicodedata.east_asian_width(line[i]) in "WF":
|
||||
row.append(("", fg, bg, b)) # it takes two cells, as in the terminal
|
||||
i += 1
|
||||
cells.append(row)
|
||||
|
||||
cols = max(len(r) for r in cells); rows = len(cells)
|
||||
@@ -113,9 +125,11 @@ for y, row in enumerate(cells):
|
||||
for x, (ch, fg, bg, b) in enumerate(row):
|
||||
px, py = tx + x * CW, ty + y * CH
|
||||
if bg: d.rectangle([px, py, px + CW - 1, py + CH - 1], fill=bg)
|
||||
if ch != " ":
|
||||
if ch not in (" ", ""):
|
||||
# block and box characters stretch over the whole cell so they join
|
||||
if draw_cell(d, ch, px, py, fg): continue
|
||||
if ch and font_for(ch, b) is reg and ord(ch) not in cmap and unicodedata.east_asian_width(ch) == "W":
|
||||
draw_emoji(img, ch, px, py); continue
|
||||
d.text((px, py + 1), ch, font=font_for(ch, b), fill=fg)
|
||||
bg = Image.new("RGBA", img.size, (0, 0, 0, 255))
|
||||
finish(Image.alpha_composite(bg, img), sys.argv[2], int(sys.argv[3]) if len(sys.argv) > 3 else None)
|
||||
Reference in new issue
Block a user