use source code pro - fixes mobile browser rendering
All checks were successful
Generic zig build / build (push) Successful in 1m32s
Generic zig build / deploy (push) Successful in 24s

This commit is contained in:
Emil Lerch 2026-01-10 09:25:43 -08:00
parent ea88a88e31
commit 148bd862b5
Signed by: lobo
GPG key ID: A7B62D657EF764F8
2 changed files with 32 additions and 4 deletions

View file

@ -242,14 +242,25 @@ test "handleWeather: default endpoint uses IP address" {
try ht.expectStatus(200); try ht.expectStatus(200);
try ht.expectBody( try ht.expectBody(
\\<pre>Weather report: Union City, California, United States \\<!DOCTYPE html>
\\<html>
\\<head>
\\<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
\\<link rel="stylesheet" href="https://adobe-fonts.github.io/source-code-pro/source-code-pro.css">
\\<style>
\\body{background:#000;color:#bbb}
\\pre{font-family:"Source Code Pro","DejaVu Sans Mono",Menlo,"Lucida Sans Typewriter","Lucida Console",monaco,"Bitstream Vera Sans Mono",monospace;font-size:75%}
\\</style>
\\</head>
\\<body><pre>
\\Weather report: Union City, California, United States
\\ \\
\\<span style="color:#ffff00"> \ / </span> Clear \\<span style="color:#ffff00"> \ / </span> Clear
\\<span style="color:#ffff00"> .-. </span> <span style="color:#d7ff00">+68(+68)</span> °F \\<span style="color:#ffff00"> .-. </span> <span style="color:#d7ff00">+68(+68)</span> °F
\\<span style="color:#ffff00"> ― ( ) ― </span> ↓ <span style="color:#6c6c6c">3</span> mph \\<span style="color:#ffff00"> ― ( ) ― </span> ↓ <span style="color:#6c6c6c">3</span> mph
\\<span style="color:#ffff00"> `-' </span> 6 mi \\<span style="color:#ffff00"> `-' </span> 6 mi
\\<span style="color:#ffff00"> / \ </span> 0.0 in \\<span style="color:#ffff00"> / \ </span> 0.0 in
\\</pre> \\</pre></body></html>
); );
} }

View file

@ -100,9 +100,26 @@ pub const RenderOptions = struct {
format: Format = .ansi, format: Format = .ansi,
}; };
fn writeHtmlHeader(w: *std.Io.Writer) !void {
try w.writeAll(
\\<!DOCTYPE html>
\\<html>
\\<head>
\\<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
\\<link rel="stylesheet" href="https://adobe-fonts.github.io/source-code-pro/source-code-pro.css">
\\<style>
\\body{background:#000;color:#bbb}
\\pre{font-family:"Source Code Pro","DejaVu Sans Mono",Menlo,"Lucida Sans Typewriter","Lucida Console",monaco,"Bitstream Vera Sans Mono",monospace;font-size:75%}
\\</style>
\\</head>
\\<body><pre>
\\
);
}
pub fn render(writer: *std.Io.Writer, data: types.WeatherData, options: RenderOptions) !void { pub fn render(writer: *std.Io.Writer, data: types.WeatherData, options: RenderOptions) !void {
const w = writer; const w = writer;
if (options.format == .html) try w.writeAll("<pre>"); if (options.format == .html) try writeHtmlHeader(w);
if (!options.super_quiet) if (!options.super_quiet)
try w.print( try w.print(
"{s}{s}\n\n", "{s}{s}\n\n",
@ -118,7 +135,7 @@ pub fn render(writer: *std.Io.Writer, data: types.WeatherData, options: RenderOp
try renderForecastDay(w, day, options); try renderForecastDay(w, day, options);
} }
} }
if (options.format == .html) try w.writeAll("</pre>"); if (options.format == .html) try w.writeAll("</pre></body></html>");
} }
fn renderCurrent(w: *std.Io.Writer, current: types.CurrentCondition, options: RenderOptions) !void { fn renderCurrent(w: *std.Io.Writer, current: types.CurrentCondition, options: RenderOptions) !void {