aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--data/style.scss17
-rw-r--r--src/args.rs14
-rw-r--r--src/main.rs4
-rw-r--r--src/renderer.rs35
-rw-r--r--src/themes.rs36
5 files changed, 30 insertions, 76 deletions
diff --git a/data/style.scss b/data/style.scss
index b2a6882..f7facc2 100644
--- a/data/style.scss
+++ b/data/style.scss
@@ -1,4 +1,8 @@
-/* theme variables can be found at the bottom */
+/* theme colors can be found at the bottom */
+$themes: squirrel, archlinux, monokai, zenburn;
+
+$default_theme: squirrel;
+$default_theme_dark: archlinux;
html {
font-smoothing: antialiased;
@@ -656,12 +660,11 @@ th span.active a, th span.active span {
}
/* theme picked by user */
-body.theme_squirrel { @include theme_squirrel; }
-body.theme_archlinux { @include theme_archlinux; }
-body.theme_zenburn { @include theme_zenburn; }
-body.theme_monokai { @include theme_monokai; }
+@each $theme in $themes {
+ body.theme_#{$theme} { @include theme_#{$theme}; }
+}
/* defaults */
-body { @include theme_squirrel; }
-@media (prefers-color-scheme: dark) { body { @include theme_archlinux; } }
+body { @include theme_#{$default_theme}; }
+@media (prefers-color-scheme: dark) { body { @include theme_#{$default_theme_dark}; } }
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,
- }
- }
-}