Skip to content

Commit ae10ee0

Browse files
committed
Accept command-line arg that specifies which color scheme to use for the status web-ui.
1 parent 64767e4 commit ae10ee0

File tree

5 files changed

+86
-8
lines changed

5 files changed

+86
-8
lines changed

Cargo.lock

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ tokio-stream = "0.1.15"
2727
async-stream = "0.3.5"
2828
opener = "0.7.2"
2929
anyhow = "1.0.86"
30-
askama = "0.12.1"
30+
askama = { version = "0.12.1", features = ["serde-json"] }
31+
serde = { version = "1.0.209", features = ["derive"] }

README.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,45 @@ For example:
3636

3737
Open the status page and the project main page in your web browser.
3838

39-
Alternatively, provide the `--open` option (`-o` for short) to have http-horse
40-
attempt to open the status and project pages in your system default web browser:
39+
#### Automatically open status and project pages in browser
40+
41+
As an alternative to manually opening the project and status pages in a web browser,
42+
you can provide the `--open` option (`-o` for short) to have http-horse attempt to
43+
automatically open the status and project pages in your system default web browser:
4144

4245
```zsh
4346
RUST_LOG=debug cargo run -- --open ./example_web_project/out/
4447
```
4548

49+
#### Status web-UI color scheme
50+
51+
The status web-UI comes with five different built-in color schemes:
52+
53+
- Midnight Purple (Dark Mode)
54+
- Slate Green (Dark Mode)
55+
- Abyss Blue (Dark Mode)
56+
- Graphite & Copper (Dark Mode)
57+
- Crimson & Charcoal (Dark Mode)
58+
59+
The default color scheme for the status web-UI is *Graphite & Copper* (Dark Mode).
60+
61+
You can provide the `--color-scheme` argument (`-c` for short) with a value
62+
that specifies which color scheme the status web-UI should use.
63+
64+
The possible values for the color scheme argument are:
65+
66+
- `midnight-purple`
67+
- `slate-green`
68+
- `abyss-blue`
69+
- `graphite-and-copper` (the default)
70+
- `crimson-and-charcoal`
71+
72+
Example:
73+
74+
```zsh
75+
RUST_LOG=debug cargo run -- -c crimson-and-charcoal --open ./example_web_project/out/
76+
```
77+
4678
### Edit a web source file
4779

4880
Make a change to one or more of the HTML, CSS, JS, or other web files.

src/main.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use anyhow::{anyhow, Context};
22
use askama::Template;
33
use async_stream::stream;
44
use bytes::Bytes;
5-
use clap::{crate_version, Parser};
5+
use clap::{crate_version, Parser, ValueEnum};
66
use futures_util::TryStreamExt;
77
use http_body_util::{combinators::BoxBody, BodyExt, Either, Full, StreamBody};
88
use hyper::{
@@ -14,6 +14,7 @@ use hyper::{
1414
Method, Request, Response, StatusCode,
1515
};
1616
use hyper_util::rt::TokioIo;
17+
use serde::{Deserialize, Serialize};
1718
use std::{
1819
io::ErrorKind,
1920
net::{IpAddr, SocketAddr},
@@ -31,6 +32,7 @@ use tracing::{debug, error, info, warn};
3132
#[template(path = "status-webui/index.htm")]
3233
struct StatusWebUiIndex<'a> {
3334
project_dir: &'a str,
35+
color_scheme: ColorScheme,
3436
}
3537

3638
static INTERNAL_INDEX_PAGE: OnceLock<Vec<u8>> = OnceLock::new();
@@ -79,6 +81,9 @@ struct Cli {
7981
/// Port to serve status on
8082
#[arg(short = 'q', long, default_value_t = 0)]
8183
status_listen_port: u16,
84+
/// Color theme to use for status web-ui
85+
#[arg(value_enum, short = 'c', long, default_value_t = ColorScheme::GraphiteAndCopper)]
86+
color_scheme: ColorScheme,
8287
/*
8388
* Positional arguments
8489
*/
@@ -87,6 +92,22 @@ struct Cli {
8792
dir: String,
8893
}
8994

95+
/// Color theme to use for status web-ui
96+
#[derive(ValueEnum, Debug, Copy, Clone, Serialize, Deserialize)]
97+
#[serde(rename_all = "kebab-case")]
98+
enum ColorScheme {
99+
/// Midnight Purple (Dark Mode)
100+
MidnightPurple,
101+
/// Slate Green (Dark Mode)
102+
SlateGreen,
103+
/// Abyss Blue (Dark Mode)
104+
AbyssBlue,
105+
/// Graphite & Copper (Dark Mode)
106+
GraphiteAndCopper,
107+
/// Crimson & Charcoal (Dark Mode)
108+
CrimsonAndCharcoal,
109+
}
110+
90111
static PROJECT_DIR: OnceLock<PathBuf> = OnceLock::new();
91112

92113
#[tokio::main]
@@ -129,7 +150,10 @@ async fn main() -> anyhow::Result<()> {
129150
.inspect_err(|e| error!(os_string = ?e, "Fatal: Failed to convert PathBuf to String."))
130151
.map_err(|_| anyhow!("Failed to convert PathBuf to String."))?;
131152

132-
let internal_index_page = StatusWebUiIndex { project_dir: &pdir };
153+
let internal_index_page = StatusWebUiIndex {
154+
project_dir: &pdir,
155+
color_scheme: args.color_scheme,
156+
};
133157
let internal_index_page_rendered = internal_index_page.render()?.as_bytes().to_vec();
134158
INTERNAL_INDEX_PAGE
135159
.set(internal_index_page_rendered)

templates/status-webui/index.htm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<!doctype html>
2-
<html lang=en>
2+
<html lang=en data-color-scheme={{ color_scheme|json|safe }}>
33
<meta charset=utf-8>
4-
<title>Project {{ project_dir }} – http-horse</title>
4+
<title>Project {{ project_dir|safe }} – http-horse</title>
55
<link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
66
<meta name="viewport" content="width=device-width, initial-scale=1">
77
<link rel=stylesheet href=/style/main.css>
88

99
<div id=outer-main>
1010
<header id=header-main>
1111
<h1>http-horse 🐴</h1>
12-
<h2>Project <code>{{ project_dir }}</code></h2>
12+
<h2>Project <code>{{ project_dir|safe }}</code></h2>
1313
</header>
1414

1515
<div id=inner-main>

0 commit comments

Comments
 (0)