diff options
author | Lukas Stabe <lukas@stabe.de> | 2020-09-26 03:39:52 +0000 |
---|---|---|
committer | Lukas Stabe <lukas@stabe.de> | 2020-09-26 03:39:52 +0000 |
commit | a4d227d34ad2bbf40ff5d542dcc8821ccb090ac7 (patch) | |
tree | caf6638bd2f26f90c4c93049100135763034afcd /src | |
parent | move css out of html into its own route (diff) | |
download | miniserve-a4d227d34ad2bbf40ff5d542dcc8821ccb090ac7.tar.gz miniserve-a4d227d34ad2bbf40ff5d542dcc8821ccb090ac7.zip |
remove default color scheme cli argument
Diffstat (limited to '')
-rw-r--r-- | src/args.rs | 14 | ||||
-rw-r--r-- | src/main.rs | 4 | ||||
-rw-r--r-- | src/renderer.rs | 35 | ||||
-rw-r--r-- | src/themes.rs | 36 |
4 files changed, 20 insertions, 69 deletions
diff --git a/src/args.rs b/src/args.rs index 2ffbdc5..78f9ce3 100644 --- a/src/args.rs +++ b/src/args.rs @@ -5,7 +5,6 @@ use structopt::StructOpt; use crate::auth; use crate::errors::ContextualError; -use crate::themes; /// Possible characters for random routes const ROUTE_ALPHABET: [char; 16] = [ @@ -67,16 +66,6 @@ struct CLIArgs { #[structopt(short = "P", long = "no-symlinks")] no_symlinks: bool, - /// Default color scheme - #[structopt( - short = "c", - long = "color-scheme", - default_value = "Squirrel", - possible_values = &themes::ColorScheme::variants(), - case_insensitive = true, - )] - color_scheme: themes::ColorScheme, - /// Enable QR code display #[structopt(short = "q", long = "qrcode")] qrcode: bool, @@ -180,8 +169,6 @@ pub fn parse_args() -> crate::MiniserveConfig { let favicon_route = nanoid::nanoid!(10, &ROUTE_ALPHABET); let css_route = nanoid::nanoid!(10, &ROUTE_ALPHABET); - let default_color_scheme = args.color_scheme; - let path_explicitly_chosen = args.path.is_some(); let port = match args.port { @@ -200,7 +187,6 @@ pub fn parse_args() -> crate::MiniserveConfig { random_route, favicon_route, css_route, - default_color_scheme, index: args.index, overwrite_files: args.overwrite_files, show_qrcode: args.qrcode, diff --git a/src/main.rs b/src/main.rs index 5b53070..1f63e10 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,7 +22,6 @@ mod file_upload; mod listing; mod pipe; mod renderer; -mod themes; use crate::errors::ContextualError; @@ -59,9 +58,6 @@ pub struct MiniserveConfig { /// Randomly generated css route pub css_route: String, - /// Default color scheme - pub default_color_scheme: themes::ColorScheme, - /// The name of a directory index file to serve, like "index.html" /// /// Normally, when miniserve serves a directory, it creates a listing for that directory. diff --git a/src/renderer.rs b/src/renderer.rs index 0f11c25..2ebe214 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -7,7 +7,6 @@ use strum::IntoEnumIterator; use crate::archive::CompressionMethod; use crate::listing::{Breadcrumb, Entry, SortingMethod, SortingOrder}; -use crate::themes::ColorScheme; /// Renders the file listing #[allow(clippy::too_many_arguments)] @@ -44,13 +43,17 @@ pub fn page( const body = document.body; var theme = localStorage.getItem('theme'); - if (theme != null) { + if (theme != null && theme != 'default') { body.classList.add('theme_' + theme); } function updateColorScheme(name) { body.classList.remove.apply(body.classList, Array.from(body.classList).filter(v=>v.startsWith("theme_"))); - body.classList.add('theme_' + name); + + if (name != "default") { + body.classList.add('theme_' + name); + } + localStorage.setItem('theme', name); } </script> @@ -150,6 +153,14 @@ fn build_upload_action( upload_action } +const THEMES: &[(&str, &str)] = &[ + ("Default (light/dark)", "default"), + ("Squirrel (light)", "squirrel"), + ("Archlinux (dark)", "archlinux"), + ("Zenburn (dark)", "zenburn"), + ("Monokai (dark)", "monokai"), +]; + /// Partial: color scheme selector fn color_scheme_selector(show_qrcode: bool) -> Markup { html! { @@ -169,8 +180,8 @@ fn color_scheme_selector(show_qrcode: bool) -> Markup { "Change theme..." } ul.theme { - @for color_scheme in ColorScheme::iter() { - li { + @for color_scheme in THEMES { + li.(format!("theme_{}", color_scheme.1)) { (color_scheme_link(color_scheme)) } } @@ -181,18 +192,12 @@ fn color_scheme_selector(show_qrcode: bool) -> Markup { } // /// Partial: color scheme link -fn color_scheme_link(color_scheme: ColorScheme) -> Markup { - let title = format!("Switch to {} theme", color_scheme); +fn color_scheme_link(color_scheme: &(&str, &str)) -> Markup { + let title = format!("Switch to {} theme", color_scheme.0); html! { - a href=(format!("javascript:updateColorScheme(\"{}\")", color_scheme.to_slug())) title=(title) { - (color_scheme) - " " - @if color_scheme.is_dark() { - "(dark)" - } @else { - "(light)" - } + a href=(format!("javascript:updateColorScheme(\"{}\")", color_scheme.1)) title=(title) { + (color_scheme.0) } } } diff --git a/src/themes.rs b/src/themes.rs deleted file mode 100644 index 1b6707b..0000000 --- a/src/themes.rs +++ /dev/null @@ -1,36 +0,0 @@ -use serde::Deserialize; -use structopt::clap::arg_enum; -use strum_macros::EnumIter; - -arg_enum! { - #[derive(PartialEq, Deserialize, Clone, EnumIter, Copy)] - #[serde(rename_all = "lowercase")] - pub enum ColorScheme { - Archlinux, - Zenburn, - Monokai, - Squirrel, - } -} - -impl ColorScheme { - /// Returns the name identifying the theme - pub fn to_slug(self) -> &'static str { - match self { - ColorScheme::Archlinux => "archlinux", - ColorScheme::Zenburn => "zenburn", - ColorScheme::Monokai => "monokai", - ColorScheme::Squirrel => "squirrel", - } - } - - /// Returns wether a color scheme is dark - pub fn is_dark(self) -> bool { - match self { - ColorScheme::Archlinux => true, - ColorScheme::Zenburn => true, - ColorScheme::Monokai => true, - ColorScheme::Squirrel => false, - } - } -} |