aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorboasting-squirrel <boasting.squirrel@gmail.com>2019-04-07 11:27:25 +0000
committerboasting-squirrel <boasting.squirrel@gmail.com>2019-04-07 11:27:25 +0000
commitbbdafc3e121942c95ba81db1cba30fe438d88dfb (patch)
tree26edf6679242462eff4d97c0ee14f84b055003ae
parentFix CSS bug (diff)
downloadminiserve-bbdafc3e121942c95ba81db1cba30fe438d88dfb.tar.gz
miniserve-bbdafc3e121942c95ba81db1cba30fe438d88dfb.zip
Use strum to reduce boilerplate on ColorScheme enum + removed useless Debug derives
-rw-r--r--src/args.rs2
-rw-r--r--src/main.rs2
-rw-r--r--src/renderer.rs12
-rw-r--r--src/themes.rs17
4 files changed, 12 insertions, 21 deletions
diff --git a/src/args.rs b/src/args.rs
index 3e54d08..516e0b6 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -10,7 +10,7 @@ const ROUTE_ALPHABET: [char; 16] = [
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'a', 'b', 'c', 'd', 'e', 'f',
];
-#[derive(StructOpt, Debug)]
+#[derive(StructOpt)]
#[structopt(
name = "miniserve",
raw(global_settings = "&[structopt::clap::AppSettings::ColoredHelp]")
diff --git a/src/main.rs b/src/main.rs
index 64de8d3..a703b00 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -19,7 +19,7 @@ mod listing;
mod renderer;
mod themes;
-#[derive(Clone, Debug)]
+#[derive(Clone)]
/// Configuration of the Miniserve application
pub struct MiniserveConfig {
/// Enable verbose mode
diff --git a/src/renderer.rs b/src/renderer.rs
index d682ee4..9fb9372 100644
--- a/src/renderer.rs
+++ b/src/renderer.rs
@@ -100,7 +100,7 @@ fn color_scheme_selector(
}
ul {
@for color_scheme in themes::ColorScheme::iter() {
- @if active_color_scheme.get_name() == color_scheme.get_name() {
+ @if active_color_scheme == &color_scheme {
li.active {
(color_scheme_link(&sort_method, &sort_order, &color_scheme))
}
@@ -124,11 +124,11 @@ fn color_scheme_link(
color_scheme: &themes::ColorScheme,
) -> Markup {
let link = parametrized_link("", &sort_method, &sort_order, &color_scheme);
- let title = format!("Switch to {} theme", color_scheme.get_name());
+ let title = format!("Switch to {} theme", color_scheme);
html! {
a href=(link) title=(title) {
- (color_scheme.get_name())
+ (color_scheme)
" "
@if color_scheme.is_dark() {
"(dark)"
@@ -165,12 +165,12 @@ fn parametrized_link(
link,
method,
order,
- color_scheme.to_string()
+ color_scheme.to_slug()
);
}
}
- format!("{}?theme={}", link.to_string(), color_scheme.to_string())
+ format!("{}?theme={}", link.to_string(), color_scheme.to_slug())
}
/// Partial: table header link
@@ -202,7 +202,7 @@ fn build_link(
html! {
span class=(class) {
span.chevron { (chevron) }
- a href=(format!("{}&theme={}", &link, color_scheme.to_string())) title=(help) { (title) }
+ a href=(format!("{}&theme={}", &link, color_scheme.to_slug())) title=(help) { (title) }
}
}
}
diff --git a/src/themes.rs b/src/themes.rs
index 8635c8f..328a2e8 100644
--- a/src/themes.rs
+++ b/src/themes.rs
@@ -3,7 +3,7 @@ use structopt::clap::{_clap_count_exprs, arg_enum};
use strum_macros::EnumIter;
arg_enum! {
- #[derive(Debug, Deserialize, Clone, EnumIter)]
+ #[derive(PartialEq, Deserialize, Clone, EnumIter)]
#[serde(rename_all = "lowercase")]
pub enum ColorScheme {
Archlinux,
@@ -15,7 +15,9 @@ arg_enum! {
impl ColorScheme {
/// Returns the URL-compatible name of a color scheme
- pub fn to_string(&self) -> String {
+ /// This must correspond to the name of the variant, in lowercase
+ /// See https://github.com/svenstaro/miniserve/pull/55 for explanations
+ pub fn to_slug(&self) -> String {
match &self {
ColorScheme::Archlinux => "archlinux",
ColorScheme::Zenburn => "zenburn",
@@ -35,17 +37,6 @@ impl ColorScheme {
}
}
- /// Returns the name of a color scheme
- pub fn get_name(&self) -> String {
- match &self {
- ColorScheme::Archlinux => "Archlinux",
- ColorScheme::Zenburn => "Zenburn",
- ColorScheme::Monokai => "Monokai",
- ColorScheme::Squirrel => "Squirrel",
- }
- .to_string()
- }
-
/// Retrieves the color palette associated to a color scheme
pub fn get_theme(self) -> Theme {
match self {