diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-08-27 08:49:38 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-08-27 08:49:38 +0200 |
| commit | 83a2eaef9853194093a457b0ab65fc231acce23f (patch) | |
| tree | 965f04075964d8a98a25e7ab5255938a278df1eb /internal/render/ascii.go | |
| parent | 682d1996c04ddd3b0f305edc3fba1ae9e75403a4 (diff) | |
| download | prognosis-0.1.4.tar.gz prognosis-0.1.4.zip | |
-svg renders the forecast as a standalone SVG: temperature with the apparent
temperature dashed, precipitation as bars with the probability on its own
right-hand axis, and humidity, over shaded night bands with a rule at each
midnight. The rain panel carries two units, so the probability gets a second
axis; read against millimetres a 60% chance looks like 0.6 mm.
Written as markup rather than through gnuplot or a plotting library, so it
needs nothing installed and works wherever the binary does -- the phone
included. Axis ticks are snapped to round values and the number of gridlines
follows the step, since snapping only the ends still yields 12.5 and 27.5.
An hour label that would land under a bold date is dropped, or "23" and
"28.08" render on top of each other.
-o and -out choose the destination, for the table as much as the meteogram. A
directory gets a filename made from the place and the date, so a daily run does
not overwrite yesterday; a bare name gains the extension, so nothing lands as a
file no viewer will open. Colour is omitted when writing to a file. The place
is transliterated rather than stripped, so Zbylitowska Gora keeps its vowels.
Documented which viewers accept a pipe: feh - and chafa do, nsxiv does not and
answers with its usage, which hides the cause. The earlier claim that
ImageMagick renders these files wrong was too broad -- that is convert falling
back to its own renderer; display delegates to rsvg-convert and is fine.
Diffstat (limited to 'internal/render/ascii.go')
| -rw-r--r-- | internal/render/ascii.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/internal/render/ascii.go b/internal/render/ascii.go index 4203bc9..077a418 100644 --- a/internal/render/ascii.go +++ b/internal/render/ascii.go @@ -25,6 +25,26 @@ var asciiMap = map[rune]string{ '│': "|", } +// Transliterate maps non-ASCII characters to their ASCII equivalents where one +// is defined, leaving ASCII alone. For contexts that must not carry diacritics +// at all -- a generated filename, say -- where "Góra" should become "Gora" +// rather than losing the letter. +func Transliterate(s string) string { + var b strings.Builder + b.Grow(len(s)) + for _, r := range s { + switch { + case r < 128: + b.WriteRune(r) + default: + if sub, ok := asciiMap[r]; ok { + b.WriteString(sub) + } + } + } + return b.String() +} + // ASCII rewrites output to pure ASCII, one character for one character. // // The point is SMS: a single non-ASCII character forces the whole message from |
