From 8ed18a551696ba4f89d7dfbdeaa879b21e079d33 Mon Sep 17 00:00:00 2001 From: boasting-squirrel Date: Mon, 1 Apr 2019 20:36:35 +0200 Subject: Color schemes --- src/archive.rs | 5 + src/listing.rs | 37 +++- src/main.rs | 2 + src/renderer.rs | 541 ++++++++++++++++++++++++++++++++++++++++---------------- src/themes.rs | 193 ++++++++++++++++++++ 5 files changed, 625 insertions(+), 153 deletions(-) create mode 100644 src/themes.rs diff --git a/src/archive.rs b/src/archive.rs index 206d252..b1119f0 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -25,6 +25,11 @@ impl CompressionMethod { .to_string() } + /// Lists compression methods + pub fn get_compression_methods() -> Vec { + vec![CompressionMethod::TarGz] + } + pub fn extension(&self) -> String { match &self { CompressionMethod::TarGz => "tar.gz", diff --git a/src/listing.rs b/src/listing.rs index c4daf88..0746f5c 100644 --- a/src/listing.rs +++ b/src/listing.rs @@ -11,6 +11,10 @@ use std::time::SystemTime; use crate::archive; use crate::errors; use crate::renderer; +use crate::themes; + +/// Default color scheme, when none is set through query parameters +const DEFAULT_COLORSCHEME: themes::ColorScheme = themes::ColorScheme::ArchLinux; /// Query parameters #[derive(Debug, Deserialize)] @@ -18,6 +22,7 @@ struct QueryParameters { sort: Option, order: Option, download: Option, + theme: Option, } /// Available sorting methods @@ -77,6 +82,9 @@ pub enum EntryType { /// Entry is a file File, + + /// Entry is a symlink + Symlink, } /// Entry @@ -114,9 +122,20 @@ impl Entry { } } + /// Returns wether the entry is a directory pub fn is_dir(&self) -> bool { self.entry_type == EntryType::Directory } + + /// Returns wether the entry is a file + pub fn is_file(&self) -> bool { + self.entry_type == EntryType::File + } + + /// Returns wether the entry is a symlink + pub fn is_symlink(&self) -> bool { + self.entry_type == EntryType::Symlink + } } pub fn file_handler(req: &HttpRequest) -> Result { @@ -138,15 +157,16 @@ pub fn directory_listing( let is_root = base.parent().is_none() || req.path() == random_route; let page_parent = base.parent().map(|p| p.display().to_string()); - let (sort_method, sort_order, download) = + let (sort_method, sort_order, download, color_scheme) = if let Ok(query) = Query::::extract(req) { ( query.sort.clone(), query.order.clone(), query.download.clone(), + query.theme.clone(), ) } else { - (None, None, None) + (None, None, None, None) }; let mut entries: Vec = Vec::new(); @@ -174,7 +194,15 @@ pub fn directory_listing( Err(_) => None, }; - if metadata.is_dir() { + if metadata.file_type().is_symlink() { + entries.push(Entry::new( + file_name, + EntryType::Symlink, + file_url, + None, + last_modification_date, + )); + } else if metadata.is_dir() { entries.push(Entry::new( file_name, EntryType::Directory, @@ -227,6 +255,8 @@ pub fn directory_listing( } } + let color_scheme = color_scheme.unwrap_or(DEFAULT_COLORSCHEME); + if let Some(compression_method) = &download { log::info!( "Creating an archive ({extension}) of {path}...", @@ -265,6 +295,7 @@ pub fn directory_listing( page_parent, sort_method, sort_order, + color_scheme, ) .into_string(), )) diff --git a/src/main.rs b/src/main.rs index f662a73..92f4352 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ #![feature(proc_macro_hygiene)] +#![feature(custom_attribute)] use actix_web::{fs, middleware, server, App}; use clap::crate_version; @@ -15,6 +16,7 @@ mod auth; mod errors; mod listing; mod renderer; +mod themes; #[derive(Clone, Debug)] /// Configuration of the Miniserve application diff --git a/src/renderer.rs b/src/renderer.rs index 66fc714..56935d8 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -5,6 +5,7 @@ use std::time::SystemTime; use crate::archive; use crate::listing; +use crate::themes; /// Renders the file listing pub fn page( @@ -14,41 +15,101 @@ pub fn page( page_parent: Option, sort_method: Option, sort_order: Option, + color_scheme: themes::ColorScheme, ) -> Markup { html! { - (page_header(page_title)) + (page_header(page_title, &color_scheme)) body { - span #top { } - h1.title { (page_title) } - div.download { - (archive_button(archive::CompressionMethod::TarGz)) - } - table { - thead { - th { (build_link("name", "Name", &sort_method, &sort_order)) } - th { (build_link("size", "Size", &sort_method, &sort_order)) } - th { (build_link("date", "Last modification", &sort_method, &sort_order)) } + (color_scheme_selector(&sort_method, &sort_order, &color_scheme)) + div.container { + span #top { } + h1.title { (page_title) } + div.download { + @for compression_method in archive::CompressionMethod::get_compression_methods() { + (archive_button(compression_method)) + } } - tbody { - @if !is_root { - @if let Some(parent) = page_parent { - tr { - td colspan="3" { - span.chevron { (chevron_left()) } - a.root href=(parent) { - "Parent directory" + table { + thead { + th { (build_link("name", "Name", &sort_method, &sort_order, &color_scheme)) } + th { (build_link("size", "Size", &sort_method, &sort_order, &color_scheme)) } + th { (build_link("date", "Last modification", &sort_method, &sort_order, &color_scheme)) } + } + tbody { + @if !is_root { + @if let Some(parent) = page_parent { + tr { + td colspan="3" { + span.root-chevron { (chevron_left()) } + a.root href=(parametrized_link(&parent, &sort_method, &sort_order, &color_scheme)) { + "Parent directory" + } } } } } + @for entry in entries { + (entry_row(entry, &sort_method, &sort_order, &color_scheme)) + } + } + } + a.back href="#top" { + (arrow_up()) + } + } + } + } +} + +/// Partial: color scheme selector +fn color_scheme_selector( + sort_method: &Option, + sort_order: &Option, + active_color_scheme: &themes::ColorScheme, +) -> Markup { + html! { + nav { + ul { + li { + a.change-theme href="#" title="Change theme" { + "Change theme..." } - @for entry in entries { - (entry_row(entry)) + ul { + @for color_scheme in themes::ColorScheme::get_color_schemes() { + @if active_color_scheme.get_name() == color_scheme.get_name() { + li.active { + (color_scheme_link(&sort_method, &sort_order, &color_scheme)) + } + } @else { + li { + (color_scheme_link(&sort_method, &sort_order, &color_scheme)) + } + } + } } } } - a.back href="#top" { - (arrow_up()) + } + } +} + +/// Partial: color scheme link +fn color_scheme_link( + sort_method: &Option, + sort_order: &Option, + 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()); + + html! { + a href=(link) title=(title) { + (color_scheme.get_name()) + " " + @if color_scheme.is_dark() { + "(dark)" + } @ else { + "(light)" } } } @@ -66,12 +127,35 @@ fn archive_button(compress_method: archive::CompressionMethod) -> Markup { } } +/// If they are set, adds query parameters to links to keep them across pages +fn parametrized_link( + link: &str, + sort_method: &Option, + sort_order: &Option, + color_scheme: &themes::ColorScheme, +) -> String { + if let Some(method) = sort_method { + if let Some(order) = sort_order { + return format!( + "{}?sort={}&order={}&theme={}", + link, + method.to_string(), + order.to_string(), + color_scheme.to_string() + ); + } + } + + format!("{}?theme={}", link.to_string(), color_scheme.to_string()) +} + /// Partial: table header link fn build_link( name: &str, title: &str, sort_method: &Option, sort_order: &Option, + color_scheme: &themes::ColorScheme, ) -> Markup { let mut link = format!("?sort={}&order=asc", name); let mut help = format!("Sort by {} in ascending order", name); @@ -94,31 +178,40 @@ fn build_link( html! { span class=(class) { span.chevron { (chevron) } - a href=(link) title=(help) { (title) } + a href=(format!("{}&theme={}", &link, color_scheme.to_string())) title=(help) { (title) } } } } /// Partial: row for an entry -fn entry_row(entry: listing::Entry) -> Markup { +fn entry_row( + entry: listing::Entry, + sort_method: &Option, + sort_order: &Option, + color_scheme: &themes::ColorScheme, +) -> Markup { html! { tr { td { p { @if entry.is_dir() { - a.directory href=(entry.link) { + a.directory href=(parametrized_link(&entry.link, &sort_method, &sort_order, &color_scheme)) { (entry.name) "/" } - } @else { - a.file href=(entry.link) { + } @else if entry.is_file() { + a.file href=(parametrized_link(&entry.link, &sort_method, &sort_order, &color_scheme)) { (entry.name) } + } @ else if entry.is_symlink() { + a.symlink href=(parametrized_link(&entry.link, &sort_method, &sort_order, &color_scheme)) { + (entry.name) span.symlink-symbol { "⇢" } + } } } @if !entry.is_dir() { @if let Some(size) = entry.size { span .mobile-info { - strong { "Size: " } + strong.field { "Size: " } (size) (br()) } @@ -126,8 +219,9 @@ fn entry_row(entry: listing::Entry) -> Markup { } span .mobile-info { @if let Some(modification_date) = convert_to_utc(entry.last_modification_date) { - strong { "Last modification: " } + strong.field { "Last modification: " } (modification_date.0) " " + span.at { " at " } (modification_date.1) " " } @if let Some(modification_timer) = humanize_systemtime(entry.last_modification_date) { @@ -146,14 +240,13 @@ fn entry_row(entry: listing::Entry) -> Markup { @if let Some(modification_date) = convert_to_utc(entry.last_modification_date) { span { (modification_date.0) " " - } - span { + span.at { " at " } (modification_date.1) " " } } @if let Some(modification_timer) = humanize_systemtime(entry.last_modification_date) { - span { - "(" (modification_timer) ")" + span.history { + (modification_timer) } } } @@ -162,162 +255,310 @@ fn entry_row(entry: listing::Entry) -> Markup { } /// Partial: CSS -fn css() -> Markup { - (PreEscaped(r#" - html { +fn css(color_scheme: &themes::ColorScheme) -> Markup { + let theme = color_scheme.clone().get_theme(); + + let css = format!(" + html {{ font-smoothing: antialiased; text-rendering: optimizeLegibility; - } - body { + }} + body {{ margin: 0; - font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,"Helvetica Neue", Helvetica, Arial, sans-serif; + font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto,\"Helvetica Neue\", Helvetica, Arial, sans-serif; font-weight: 300; - color: #444444; - padding: 0.125rem; - } - strong { + color: {text_color}; + background: {background}; + }} + .container {{ + padding: 1.5rem 5rem; + }} + a {{ + text-decoration: none; + }} + a.root, a.root:visited, .root-chevron {{ font-weight: bold; - } - p { + color: {root_link_color}; + }} + a:hover {{ + text-decoration: underline; + }} + a.directory, a.directory:visited {{ + font-weight: bold; + color: {directory_link_color}; + }} + a.file, a.file:visited {{ + color: {file_link_color}; + }} + a.symlink, a.symlink:visited {{ + color: {symlink_link_color}; + }} + a.directory:hover {{ + color: {directory_link_color}; + }} + a.file:hover {{ + color: {file_link_color}; + }} + a.symlink:hover {{ + color: {symlink_link_color}; + }} + .symlink-symbol {{ + display: inline-block; + border: 1px solid {symlink_link_color}; + margin-left: 0.5rem; + border-radius: .2rem; + padding: 0 0.1rem; + }} + nav {{ + padding: 0 5rem; + }} + nav ul {{ + text-align: right; + list-style: none; margin: 0; padding: 0; - } - h1 { + }} + nav ul li {{ + display: block; + transition-duration: 0.5s; + float: right; + position: relative; + padding: 0.5rem 1rem; + background: {switch_theme_background}; + width: 8rem; + text-align: center; + }} + nav ul li:hover {{ + cursor: pointer; + text-decoration: none; + color: {change_theme_link_color} + }} + nav ul li a:hover {{ + text-decoration: none; + color: {change_theme_link_color_hover}; + }} + nav ul li ul {{ + visibility: hidden; + opacity: 0; + position: absolute; + transition: all 0.5s ease; + margin-top: 0.5rem; + left: 0; + display: none; + text-align: center; + }} + nav ul li:hover > ul, + nav ul li ul:hover {{ + visibility: visible; + opacity: 1; + display: block; + }} + nav ul li ul li:first-of-type {{ + border-top: 1px solid {switch_theme_border}; + }} + nav ul li ul li {{ + clear: both; + width: 8rem; + padding-top: 0.5rem; + padding-bottom: 0.5rem; + }} + nav ul li ul li a:hover {{ + text-decoration: underline; + }} + nav ul li a, nav ul li ul li a, nav ul li a:visited, nav ul li ul li a:visited {{ + color: {switch_theme_link_color} + }} + nav ul li ul li.active a {{ + font-weight: bold; + color: {switch_theme_active}; + }} + strong {{ + font-weight: bold; + }} + .field {{ + color: {field_color} + }} + p {{ + margin: 0; + padding: 0; + }} + h1 {{ + margin-top: 0; font-size: 1.5rem; - } - table { + }} + table {{ margin-top: 2rem; width: 100%; - background: white; border: 0; table-layout: auto; - } - table thead { - background: #efefef; - } - table tr th, - table tr td { + background: {table_background}; + }} + table thead tr th, + table tbody tr td {{ padding: 0.5625rem 0.625rem; font-size: 0.875rem; - color: #777c82; + color: {table_text_color}; text-align: left; line-height: 1.125rem; width: 33.333%; - } - table tr th { + }} + table thead tr th {{ padding: 0.5rem 0.625rem 0.625rem; font-weight: bold; - color: #444444; - } - table tr:nth-child(even) { - background: #f6f6f6; - } - table tr:hover { - background: #deeef7a6; - } - a { - text-decoration: none; - color: #3498db; - } - a.root, a.root:visited { - font-weight: bold; - color: #777c82; - } - a.directory { - font-weight: bold; - } - a:hover { - text-decoration: underline; - } - a:visited { - color: #8e44ad; - } - td.date-cell { + }} + table tbody tr:nth-child(odd) {{ + background: {odd_row_background}; + }} + table tbody tr:nth-child(even) {{ + background: {even_row_background}; + }} + table thead {{ + background: {table_header_background}; + }} + table tbody tr:hover {{ + background: {active_row_color}; + }} + td.date-cell {{ display: flex; width: calc(100% - 1.25rem); - } - td.date-cell span:first-of-type, - td.date-cell span:nth-of-type(2) { - flex-basis:4.5rem; - } - td.date-cell span:nth-of-type(3), .history { - color: #c5c5c5; - } - .file, .directory { + justify-content: space-between; + }} + .at {{ + color: {at_color}; + }} + .history {{ + color: {date_text_color}; + }} + .file, .directory, .symlink {{ display: block; - } - .mobile-info { + }} + .mobile-info {{ display: none; - } - th a, th a:visited, .chevron { - color: #777c82; - } - .chevron { + }} + th a, th a:visited, .chevron {{ + color: {table_header_text_color}; + }} + .chevron, .root-chevron {{ margin-right: .5rem; font-size: 1.2em; font-weight: bold; - } - th span.active a, th span.active span { - color: #444444; - } - .back { + }} + th span.active a, th span.active span {{ + color: {table_header_active_color}; + }} + .back {{ position: fixed; - bottom: 1.1rem; - right: 0.625rem; - background: #e0e0e0; + bottom: 3rem; + right: 3.75rem; + background: {back_button_background}; border-radius: 100%; box-shadow: 0 0 8px -4px #888888; - opacity: 0.8; - padding: 1rem 1.1rem; - color: #444444; - } - .back:visited { - color: #444444; - } - .back:hover { - color: #3498db; + padding: 1.4rem 1.5rem; + color: {back_button_link_color}; + display: none; + }} + .back:visited {{ + color: {back_button_link_color}; + }} + .back:hover {{ + color: {back_button_link_color_hover}; + font-weight: bold; text-decoration: none; - } - .download { + background: {back_button_background_hover}; + }} + .download {{ display: flex; flex-wrap: wrap; margin-top: .5rem; padding: 0.125rem; - } - .download a, .download a:visited { - color: #3498db; - } - .download a { - background: #efefef; + }} + .download a, .download a:visited {{ + color: {download_button_link_color}; + }} + .download a {{ + background: {download_button_background}; padding: 0.5rem; border-radius: 0.2rem; margin-top: 1rem; - } - .download a:hover { - background: #deeef7a6; - } - .download a:not(:last-of-type) { + }} + .download a:hover {{ + background: {download_button_background_hover}; + color: {download_button_link_color_hover}; + }} + .download a:not(:last-of-type) {{ margin-right: 1rem; - } - @media (max-width: 600px) { - h1 { + }} + @media (max-width: 760px) {{ + nav {{ + padding: 0 2.5rem; + }} + .container {{ + padding: 1.5rem 2.5rem; + }} + h1 {{ font-size: 1.375em; - } - td:not(:nth-child(1)), th:not(:nth-child(1)){ + }} + td:not(:nth-child(1)), th:not(:nth-child(1)){{ display: none; - } - .mobile-info { + }} + .mobile-info {{ display: block; - } - .file, .directory{ + }} + .file, .directory, .symlink{{ padding-bottom: 1rem; - } - } - @media (max-width: 400px) { - h1 { + }} + .back {{ + right: 1.5rem; + }} + .back {{ + display: initial; + }} + }} + @media (max-width: 400px) {{ + nav {{ + padding: 0 0.5rem; + }} + .container {{ + padding: 0.5rem; + }} + h1 {{ font-size: 1.375em; - } - }"#.to_string())) + }} + .back {{ + right: 1.5rem; + }} + }}", background = theme.background, + text_color = theme.text_color, + directory_link_color = theme.directory_link_color, + file_link_color = theme.file_link_color, + symlink_link_color = theme.symlink_link_color, + table_background = theme.table_background, + table_text_color = theme.table_text_color, + table_header_background = theme.table_header_background, + table_header_text_color = theme.table_header_text_color, + table_header_active_color = theme.table_header_active_color, + active_row_color = theme.active_row_color, + odd_row_background = theme.odd_row_background, + even_row_background = theme.even_row_background, + root_link_color = theme.root_link_color, + download_button_background = theme.download_button_background, + download_button_background_hover = theme.download_button_background_hover, + download_button_link_color = theme.download_button_link_color, + download_button_link_color_hover = theme.download_button_link_color_hover, + back_button_background = theme.back_button_background, + back_button_background_hover = theme.back_button_background_hover, + back_button_link_color = theme.back_button_link_color, + back_button_link_color_hover = theme.back_button_link_color_hover, + date_text_color = theme.date_text_color, + at_color = theme.at_color, + switch_theme_background = theme.switch_theme_background, + switch_theme_link_color = theme.switch_theme_link_color, + switch_theme_active = theme.switch_theme_active, + switch_theme_border = theme.switch_theme_border, + change_theme_link_color = theme.change_theme_link_color, + change_theme_link_color_hover = theme.change_theme_link_color_hover, + field_color = theme.field_color); + (PreEscaped(css)) } /// Partial: up arrow @@ -346,7 +587,7 @@ fn chevron_down() -> Markup { } /// Partial: page header -fn page_header(page_title: &str) -> Markup { +fn page_header(page_title: &str, color_scheme: &themes::ColorScheme) -> Markup { html! { (DOCTYPE) html { @@ -354,7 +595,7 @@ fn page_header(page_title: &str) -> Markup { meta http-equiv="X-UA-Compatible" content="IE=edge"; meta name="viewport" content="width=device-width, initial-scale=1"; title { (page_title) } - style { (css()) } + style { (css(&color_scheme)) } } } } @@ -365,7 +606,7 @@ fn page_header(page_title: &str) -> Markup { fn convert_to_utc(src_time: Option) -> Option<(String, String)> { src_time.map(DateTime::::from).map(|date_time| { ( - date_time.format("%e %b").to_string(), + date_time.format("%b %e").to_string(), date_time.format("%R").to_string(), ) }) diff --git a/src/themes.rs b/src/themes.rs new file mode 100644 index 0000000..5e8dc00 --- /dev/null +++ b/src/themes.rs @@ -0,0 +1,193 @@ +use serde::Deserialize; + +#[derive(Debug, Deserialize, Clone)] +pub enum ColorScheme { + #[serde(alias = "archlinux")] + ArchLinux, + + #[serde(alias = "zenburn")] + Zenburn, + + #[serde(alias = "monokai")] + Monokai, +} + +impl ColorScheme { + /// Returns the URL-compatible name of a color scheme + pub fn to_string(&self) -> String { + match &self { + ColorScheme::ArchLinux => "archlinux", + ColorScheme::Zenburn => "zenburn", + ColorScheme::Monokai => "monokai", + } + .to_string() + } + + /// Returns wether a color scheme is dark + pub fn is_dark(&self) -> bool { + match &self { + ColorScheme::ArchLinux => true, + ColorScheme::Zenburn => true, + ColorScheme::Monokai => true, + } + } + + /// Returns the name of a color scheme + pub fn get_name(&self) -> String { + match &self { + ColorScheme::ArchLinux => "Archlinux", + ColorScheme::Zenburn => "Zenburn", + ColorScheme::Monokai => "Monokai", + } + .to_string() + } + + /// Lists available color schemes + pub fn get_color_schemes() -> Vec { + vec![ + ColorScheme::ArchLinux, + ColorScheme::Zenburn, + ColorScheme::Monokai, + ] + } + + /// Retrieves the color palette associated to a color scheme + pub fn get_theme(self) -> Theme { + match self { + ColorScheme::ArchLinux => Theme { + background: "#383c4a".to_string(), + text_color: "#fefefe".to_string(), + directory_link_color: "#03a9f4".to_string(), + file_link_color: "#ea95ff".to_string(), + symlink_link_color: "#ff9800".to_string(), + table_background: "#353946".to_string(), + table_text_color: "#eeeeee".to_string(), + table_header_background: "#5294e2".to_string(), + table_header_text_color: "#eeeeee".to_string(), + table_header_active_color: "#ffffff".to_string(), + active_row_color: "#5194e259".to_string(), + odd_row_background: "#404552".to_string(), + even_row_background: "#4b5162".to_string(), + root_link_color: "#abb2bb".to_string(), + download_button_background: "#ea95ff".to_string(), + download_button_background_hover: "#eea7ff".to_string(), + download_button_link_color: "#ffffff".to_string(), + download_button_link_color_hover: "#ffffff".to_string(), + back_button_background: "#ea95ff".to_string(), + back_button_background_hover: "#ea95ff".to_string(), + back_button_link_color: "#ffffff".to_string(), + back_button_link_color_hover: "#ffffff".to_string(), + date_text_color: "#9ebbdc".to_string(), + at_color: "#9ebbdc".to_string(), + switch_theme_background: "#4b5162".to_string(), + switch_theme_link_color: "#fefefe".to_string(), + switch_theme_active: "#ea95ff".to_string(), + switch_theme_border: "#6a728a".to_string(), + change_theme_link_color: "#fefefe".to_string(), + change_theme_link_color_hover: "#fefefe".to_string(), + field_color: "#859cb9".to_string(), + }, + ColorScheme::Zenburn => Theme { + background: "#3f3f3f".to_string(), + text_color: "#efefef".to_string(), + directory_link_color: "#f0dfaf".to_string(), + file_link_color: "#87D6D5".to_string(), + symlink_link_color: "#FFCCEE".to_string(), + table_background: "#4a4949".to_string(), + table_text_color: "#efefef".to_string(), + table_header_background: "#7f9f7f".to_string(), + table_header_text_color: "#efefef".to_string(), + table_header_active_color: "#efef8f".to_string(), + active_row_color: "#7e9f7f9c".to_string(), + odd_row_background: "#777777".to_string(), + even_row_background: "#5a5a5a".to_string(), + root_link_color: "#dca3a3".to_string(), + download_button_background: "#cc9393".to_string(), + download_button_background_hover: "#dca3a3".to_string(), + download_button_link_color: "#efefef".to_string(), + download_button_link_color_hover: "#efefef".to_string(), + back_button_background: "#cc9393".to_string(), + back_button_background_hover: "#cc9393".to_string(), + back_button_link_color: "#efefef".to_string(), + back_button_link_color_hover: "#efefef".to_string(), + date_text_color: "#cfbfaf".to_string(), + at_color: "#cfbfaf".to_string(), + switch_theme_background: "#4a4949".to_string(), + switch_theme_link_color: "#efefef".to_string(), + switch_theme_active: "#efef8f".to_string(), + switch_theme_border: "#5a5a5a".to_string(), + change_theme_link_color: "#efefef".to_string(), + change_theme_link_color_hover: "#efefef".to_string(), + field_color: "#9fc3a1".to_string(), + }, + ColorScheme::Monokai => Theme { + background: "#272822".to_string(), + text_color: "#F8F8F2".to_string(), + directory_link_color: "#F92672".to_string(), + file_link_color: "#A6E22E".to_string(), + symlink_link_color: "#FD971F".to_string(), + table_background: "#3B3A32".to_string(), + table_text_color: "#F8F8F0".to_string(), + table_header_background: "#75715E".to_string(), + table_header_text_color: "#F8F8F2".to_string(), + table_header_active_color: "#E6DB74".to_string(), + active_row_color: "#ae81fe3d".to_string(), + odd_row_background: "#3E3D32".to_string(), + even_row_background: "#49483E".to_string(), + root_link_color: "#66D9EF".to_string(), + download_button_background: "#AE81FF".to_string(), + download_button_background_hover: "#c6a6ff".to_string(), + download_button_link_color: "#F8F8F0".to_string(), + download_button_link_color_hover: "#F8F8F0".to_string(), + back_button_background: "#AE81FF".to_string(), + back_button_background_hover: "#AE81FF".to_string(), + back_button_link_color: "#F8F8F0".to_string(), + back_button_link_color_hover: "#F8F8F0".to_string(), + date_text_color: "#66D9EF".to_string(), + at_color: "#66D9EF".to_string(), + switch_theme_background: "#3B3A32".to_string(), + switch_theme_link_color: "#F8F8F2".to_string(), + switch_theme_active: "#A6E22E".to_string(), + switch_theme_border: "#49483E".to_string(), + change_theme_link_color: "#F8F8F2".to_string(), + change_theme_link_color_hover: "#F8F8F2".to_string(), + field_color: "#ccc7a7".to_string(), + }, + } + } +} + +/// Describes a theme +pub struct Theme { + pub background: String, + pub text_color: String, + pub directory_link_color: String, + pub file_link_color: String, + pub symlink_link_color: String, + pub table_background: String, + pub table_text_color: String, + pub table_header_background: String, + pub table_header_text_color: String, + pub table_header_active_color: String, + pub active_row_color: String, + pub odd_row_background: String, + pub even_row_background: String, + pub root_link_color: String, + pub download_button_background: String, + pub download_button_background_hover: String, + pub download_button_link_color: String, + pub download_button_link_color_hover: String, + pub back_button_background: String, + pub back_button_background_hover: String, + pub back_button_link_color: String, + pub back_button_link_color_hover: String, + pub date_text_color: String, + pub at_color: String, + pub switch_theme_background: String, + pub switch_theme_link_color: String, + pub switch_theme_active: String, + pub switch_theme_border: String, + pub change_theme_link_color: String, + pub change_theme_link_color_hover: String, + pub field_color: String, +} -- cgit v1.2.3 From ab36fd82b6b02f967e577adfdfdd6dce982bb3d2 Mon Sep 17 00:00:00 2001 From: boasting-squirrel Date: Mon, 1 Apr 2019 20:57:57 +0200 Subject: Removed useless feature --- src/main.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 92f4352..1a4a68f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,4 @@ #![feature(proc_macro_hygiene)] -#![feature(custom_attribute)] use actix_web::{fs, middleware, server, App}; use clap::crate_version; -- cgit v1.2.3 From fae39ac193c9a0b55f85095f2cd4e53149c9c128 Mon Sep 17 00:00:00 2001 From: boasting-squirrel Date: Tue, 2 Apr 2019 07:24:49 +0200 Subject: Renamed ArchLinux to Archlinux --- src/listing.rs | 2 +- src/themes.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/listing.rs b/src/listing.rs index 0746f5c..4a20db2 100644 --- a/src/listing.rs +++ b/src/listing.rs @@ -14,7 +14,7 @@ use crate::renderer; use crate::themes; /// Default color scheme, when none is set through query parameters -const DEFAULT_COLORSCHEME: themes::ColorScheme = themes::ColorScheme::ArchLinux; +const DEFAULT_COLORSCHEME: themes::ColorScheme = themes::ColorScheme::Archlinux; /// Query parameters #[derive(Debug, Deserialize)] diff --git a/src/themes.rs b/src/themes.rs index 5e8dc00..885c628 100644 --- a/src/themes.rs +++ b/src/themes.rs @@ -3,7 +3,7 @@ use serde::Deserialize; #[derive(Debug, Deserialize, Clone)] pub enum ColorScheme { #[serde(alias = "archlinux")] - ArchLinux, + Archlinux, #[serde(alias = "zenburn")] Zenburn, @@ -16,7 +16,7 @@ impl ColorScheme { /// Returns the URL-compatible name of a color scheme pub fn to_string(&self) -> String { match &self { - ColorScheme::ArchLinux => "archlinux", + ColorScheme::Archlinux => "archlinux", ColorScheme::Zenburn => "zenburn", ColorScheme::Monokai => "monokai", } @@ -26,7 +26,7 @@ impl ColorScheme { /// Returns wether a color scheme is dark pub fn is_dark(&self) -> bool { match &self { - ColorScheme::ArchLinux => true, + ColorScheme::Archlinux => true, ColorScheme::Zenburn => true, ColorScheme::Monokai => true, } @@ -35,7 +35,7 @@ impl ColorScheme { /// Returns the name of a color scheme pub fn get_name(&self) -> String { match &self { - ColorScheme::ArchLinux => "Archlinux", + ColorScheme::Archlinux => "Archlinux", ColorScheme::Zenburn => "Zenburn", ColorScheme::Monokai => "Monokai", } @@ -45,7 +45,7 @@ impl ColorScheme { /// Lists available color schemes pub fn get_color_schemes() -> Vec { vec![ - ColorScheme::ArchLinux, + ColorScheme::Archlinux, ColorScheme::Zenburn, ColorScheme::Monokai, ] @@ -54,7 +54,7 @@ impl ColorScheme { /// Retrieves the color palette associated to a color scheme pub fn get_theme(self) -> Theme { match self { - ColorScheme::ArchLinux => Theme { + ColorScheme::Archlinux => Theme { background: "#383c4a".to_string(), text_color: "#fefefe".to_string(), directory_link_color: "#03a9f4".to_string(), -- cgit v1.2.3 From 5d743481eb595c0d3c60313058ddbcb444a2926e Mon Sep 17 00:00:00 2001 From: boasting-squirrel Date: Tue, 2 Apr 2019 07:26:56 +0200 Subject: Removed query params when clicking on a file --- src/renderer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer.rs b/src/renderer.rs index 56935d8..abb8730 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -199,7 +199,7 @@ fn entry_row( (entry.name) "/" } } @else if entry.is_file() { - a.file href=(parametrized_link(&entry.link, &sort_method, &sort_order, &color_scheme)) { + a.file href=(&entry.link) { (entry.name) } } @ else if entry.is_symlink() { -- cgit v1.2.3 From 9f20b666a595e7c844d9707b7ccf202662d8322f Mon Sep 17 00:00:00 2001 From: boasting-squirrel Date: Tue, 2 Apr 2019 20:18:37 +0200 Subject: Added light theme --- src/themes.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/themes.rs b/src/themes.rs index 885c628..f38814e 100644 --- a/src/themes.rs +++ b/src/themes.rs @@ -10,6 +10,9 @@ pub enum ColorScheme { #[serde(alias = "monokai")] Monokai, + + #[serde(alias = "squirrel")] + Squirrel, } impl ColorScheme { @@ -19,6 +22,7 @@ impl ColorScheme { ColorScheme::Archlinux => "archlinux", ColorScheme::Zenburn => "zenburn", ColorScheme::Monokai => "monokai", + ColorScheme::Squirrel => "squirrel", } .to_string() } @@ -29,6 +33,7 @@ impl ColorScheme { ColorScheme::Archlinux => true, ColorScheme::Zenburn => true, ColorScheme::Monokai => true, + ColorScheme::Squirrel => false, } } @@ -38,6 +43,7 @@ impl ColorScheme { ColorScheme::Archlinux => "Archlinux", ColorScheme::Zenburn => "Zenburn", ColorScheme::Monokai => "Monokai", + ColorScheme::Squirrel => "Squirrel", } .to_string() } @@ -48,6 +54,7 @@ impl ColorScheme { ColorScheme::Archlinux, ColorScheme::Zenburn, ColorScheme::Monokai, + ColorScheme::Squirrel, ] } @@ -153,6 +160,39 @@ impl ColorScheme { change_theme_link_color_hover: "#F8F8F2".to_string(), field_color: "#ccc7a7".to_string(), }, + ColorScheme::Squirrel => Theme { + background: "#FFFFFF".to_string(), + text_color: "#323232".to_string(), + directory_link_color: "#d02474".to_string(), + file_link_color: "#0086B3".to_string(), + symlink_link_color: "#ED6A43".to_string(), + table_background: "#F5F5F5".to_string(), + table_text_color: "#323232".to_string(), + table_header_background: "#323232".to_string(), + table_header_text_color: "#F5F5F5".to_string(), + table_header_active_color: "#FFFFFF".to_string(), + active_row_color: "#f6f8fa".to_string(), + odd_row_background: "#fbfbfb".to_string(), + even_row_background: "#f2f2f2".to_string(), + root_link_color: "#323232".to_string(), + download_button_background: "#d02474".to_string(), + download_button_background_hover: "#f52d8a".to_string(), + download_button_link_color: "#F8F8F0".to_string(), + download_button_link_color_hover: "#F8F8F0".to_string(), + back_button_background: "#d02474".to_string(), + back_button_background_hover: "#d02474".to_string(), + back_button_link_color: "#F8F8F0".to_string(), + back_button_link_color_hover: "#F8F8F0".to_string(), + date_text_color: "#797979".to_string(), + at_color: "#797979".to_string(), + switch_theme_background: "#323232".to_string(), + switch_theme_link_color: "#F5F5F5".to_string(), + switch_theme_active: "#d02474".to_string(), + switch_theme_border: "#49483E".to_string(), + change_theme_link_color: "#F5F5F5".to_string(), + change_theme_link_color_hover: "#F5F5F5".to_string(), + field_color: "#797979".to_string(), + }, } } } -- cgit v1.2.3 From 0304ea92390c06ccbbd7d29a88ecedc9718d72c2 Mon Sep 17 00:00:00 2001 From: boasting-squirrel Date: Wed, 3 Apr 2019 20:07:33 +0200 Subject: Added CLI argument to set default theme --- src/args.rs | 16 ++++++++++++++++ src/listing.rs | 6 ++---- src/main.rs | 12 +++++++++++- src/themes.rs | 23 ++++++++++------------- 4 files changed, 39 insertions(+), 18 deletions(-) diff --git a/src/args.rs b/src/args.rs index 4f0dbf7..bcee0bc 100644 --- a/src/args.rs +++ b/src/args.rs @@ -3,6 +3,7 @@ use std::path::PathBuf; use structopt::StructOpt; use crate::auth; +use crate::themes; /// Possible characters for random routes const ROUTE_ALPHABET: [char; 16] = [ @@ -47,6 +48,18 @@ struct CLIArgs { /// Do not follow symbolic links #[structopt(short = "P", long = "no-symlinks")] no_symlinks: bool, + + /// Default color scheme + #[structopt( + short = "c", + long = "color-scheme", + default_value = "Squirrel", + raw( + possible_values = "&themes::ColorScheme::variants()", + case_insensitive = "true", + ) + )] + color_scheme: themes::ColorScheme, } /// Checks wether an interface is valid, i.e. it can be parsed into an IP address @@ -89,6 +102,8 @@ pub fn parse_args() -> crate::MiniserveConfig { None }; + let default_color_scheme = args.color_scheme; + let path_explicitly_chosen = args.path.is_some(); crate::MiniserveConfig { @@ -100,5 +115,6 @@ pub fn parse_args() -> crate::MiniserveConfig { path_explicitly_chosen, no_symlinks: args.no_symlinks, random_route, + default_color_scheme, } } diff --git a/src/listing.rs b/src/listing.rs index 4a20db2..64eb575 100644 --- a/src/listing.rs +++ b/src/listing.rs @@ -13,9 +13,6 @@ use crate::errors; use crate::renderer; use crate::themes; -/// Default color scheme, when none is set through query parameters -const DEFAULT_COLORSCHEME: themes::ColorScheme = themes::ColorScheme::Archlinux; - /// Query parameters #[derive(Debug, Deserialize)] struct QueryParameters { @@ -150,6 +147,7 @@ pub fn directory_listing( req: &HttpRequest, skip_symlinks: bool, random_route: Option, + default_color_scheme: themes::ColorScheme, ) -> Result { let title = format!("Index of {}", req.path()); let base = Path::new(req.path()); @@ -255,7 +253,7 @@ pub fn directory_listing( } } - let color_scheme = color_scheme.unwrap_or(DEFAULT_COLORSCHEME); + let color_scheme = color_scheme.unwrap_or(default_color_scheme); if let Some(compression_method) = &download { log::info!( diff --git a/src/main.rs b/src/main.rs index 1a4a68f..79a5db2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -43,6 +43,9 @@ pub struct MiniserveConfig { /// Enable random route generation pub random_route: Option, + + /// Default color scheme + pub default_color_scheme: themes::ColorScheme, } fn main() { @@ -179,6 +182,7 @@ fn configure_app(app: App) -> App { let path = &app.state().path; let no_symlinks = app.state().no_symlinks; let random_route = app.state().random_route.clone(); + let default_color_scheme = app.state().default_color_scheme.clone(); if path.is_file() { None } else { @@ -187,7 +191,13 @@ fn configure_app(app: App) -> App { .expect("Couldn't create path") .show_files_listing() .files_listing_renderer(move |dir, req| { - listing::directory_listing(dir, req, no_symlinks, random_route.clone()) + listing::directory_listing( + dir, + req, + no_symlinks, + random_route.clone(), + default_color_scheme.clone(), + ) }), ) } diff --git a/src/themes.rs b/src/themes.rs index f38814e..d04eab2 100644 --- a/src/themes.rs +++ b/src/themes.rs @@ -1,18 +1,15 @@ use serde::Deserialize; +use structopt::clap::{_clap_count_exprs, arg_enum}; -#[derive(Debug, Deserialize, Clone)] -pub enum ColorScheme { - #[serde(alias = "archlinux")] - Archlinux, - - #[serde(alias = "zenburn")] - Zenburn, - - #[serde(alias = "monokai")] - Monokai, - - #[serde(alias = "squirrel")] - Squirrel, +arg_enum! { + #[derive(Debug, Deserialize, Clone)] + #[serde(rename_all = "lowercase")] + pub enum ColorScheme { + Archlinux, + Zenburn, + Monokai, + Squirrel, + } } impl ColorScheme { -- cgit v1.2.3 From 4e43a1b76cbf8582c9da15eda866b5d2d0d5975a Mon Sep 17 00:00:00 2001 From: boasting-squirrel Date: Wed, 3 Apr 2019 22:55:36 +0200 Subject: Use serde lowercase for SortingMethods enum --- src/listing.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/listing.rs b/src/listing.rs index 64eb575..de84dc6 100644 --- a/src/listing.rs +++ b/src/listing.rs @@ -24,17 +24,15 @@ struct QueryParameters { /// Available sorting methods #[derive(Debug, Deserialize, Clone)] +#[serde(rename_all = "lowercase")] pub enum SortingMethod { /// Sort by name - #[serde(alias = "name")] Name, /// Sort by size - #[serde(alias = "size")] Size, /// Sort by last modification date (natural sort: follows alphanumerical order) - #[serde(alias = "date")] Date, } -- cgit v1.2.3 From bab561849d27f6c9be756c16d2201ac065f4cb7f Mon Sep 17 00:00:00 2001 From: boasting-squirrel Date: Sat, 6 Apr 2019 16:47:42 +0200 Subject: Changed link description in case of upload error --- src/renderer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer.rs b/src/renderer.rs index bd7b272..a4f003d 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -748,7 +748,7 @@ pub fn file_upload_error(error_description: &str, return_address: &str) -> Marku h1 { "File uploading failed" } p { (error_description) } a href=(return_address) { - "back" + "Go back to file listing" } } } -- cgit v1.2.3 From 7d5a5a79f63deb68aaeb98472e4277871cc691a8 Mon Sep 17 00:00:00 2001 From: boasting-squirrel Date: Sat, 6 Apr 2019 18:38:08 +0200 Subject: Improved design --- src/renderer.rs | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/renderer.rs b/src/renderer.rs index a4f003d..5a85c35 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -32,18 +32,20 @@ pub fn page( div.container { span#top { } h1.title { (page_title) } - div.download { - @for compression_method in archive::CompressionMethod::get_compression_methods() { - (archive_button(compression_method)) + div.toolbar { + div.download { + @for compression_method in archive::CompressionMethod::get_compression_methods() { + (archive_button(compression_method)) + } } - } - @if file_upload { - div.upload { - form id="file_submit" action={(upload_route) "?path=" (current_dir)} method="POST" enctype="multipart/form-data" { - p { "Select a file to upload or drag it anywhere into the window" } - div { - input#file-input type="file" name="file_to_upload" {} - button type="submit" { "Upload file" } + @if file_upload { + div.upload { + form id="file_submit" action={(upload_route) "?path=" (current_dir)} method="POST" enctype="multipart/form-data" { + p { "Select a file to upload or drag it anywhere into the window" } + div { + input#file-input type="file" name="file_to_upload" {} + button type="submit" { "Upload file" } + } } } } @@ -486,11 +488,17 @@ fn css(color_scheme: &themes::ColorScheme) -> Markup { text-decoration: none; background: {back_button_background_hover}; }} + .toolbar {{ + margin-top: 2rem; + display: flex; + justify-content: space-between; + }} .download {{ + padding: 0.125rem; display: flex; + flex-direction: row; + align-items: flex-start; flex-wrap: wrap; - margin-top: .5rem; - padding: 0.125rem; }} .download a, .download a:visited {{ color: {download_button_link_color}; @@ -499,7 +507,6 @@ fn css(color_scheme: &themes::ColorScheme) -> Markup { background: {download_button_background}; padding: 0.5rem; border-radius: 0.2rem; - margin-top: 1rem; }} .download a:hover {{ background: {download_button_background_hover}; @@ -511,7 +518,6 @@ fn css(color_scheme: &themes::ColorScheme) -> Markup { .upload {{ display: flex; justify-content: flex-end; - margin-top: 1rem; }} .upload p {{ font-size: 0.8rem; @@ -574,9 +580,6 @@ fn css(color_scheme: &themes::ColorScheme) -> Markup { .back {{ display: initial; }} - .upload {{ - margin-top: 2rem; - }} .upload form {{ width: 100%; }} -- cgit v1.2.3 From 61cae15740fbbe8da48349e22f440956df960c2f Mon Sep 17 00:00:00 2001 From: boasting-squirrel Date: Sat, 6 Apr 2019 18:43:57 +0200 Subject: Added flex wrap to handle overflow on mobile --- src/renderer.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/renderer.rs b/src/renderer.rs index 5a85c35..9fa977e 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -489,11 +489,12 @@ fn css(color_scheme: &themes::ColorScheme) -> Markup { background: {back_button_background_hover}; }} .toolbar {{ - margin-top: 2rem; display: flex; justify-content: space-between; + flex-wrap: wrap; }} .download {{ + margin-top: 1rem; padding: 0.125rem; display: flex; flex-direction: row; @@ -516,6 +517,7 @@ fn css(color_scheme: &themes::ColorScheme) -> Markup { margin-right: 1rem; }} .upload {{ + margin-top: 1rem; display: flex; justify-content: flex-end; }} -- cgit v1.2.3 From b0ead295996015fef9ea285bbed78509a85c5bbe Mon Sep 17 00:00:00 2001 From: boasting-squirrel Date: Sat, 6 Apr 2019 20:49:02 +0200 Subject: Improved mobile view --- src/renderer.rs | 67 +++++++++++++++++++-------------------------------------- src/themes.rs | 16 +++++++++----- 2 files changed, 33 insertions(+), 50 deletions(-) diff --git a/src/renderer.rs b/src/renderer.rs index 9fa977e..a0da81e 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -220,8 +220,15 @@ fn entry_row( (entry.name) "/" } } @else if entry.is_file() { - a.file href=(&entry.link) { - (entry.name) + div.file-entry { + a.file href=(&entry.link) { + (entry.name) + } + @if let Some(size) = entry.size { + span.mobile-info.size { + (size) + } + } } } @ else if entry.is_symlink() { a.symlink href=(parametrized_link(&entry.link, &sort_method, &sort_order, &color_scheme)) { @@ -229,28 +236,6 @@ fn entry_row( } } } - @if !entry.is_dir() { - @if let Some(size) = entry.size { - span .mobile-info { - strong.field { "Size: " } - (size) - (br()) - } - } - } - span .mobile-info { - @if let Some(modification_date) = convert_to_utc(entry.last_modification_date) { - strong.field { "Last modification: " } - (modification_date.0) " " - span.at { " at " } - (modification_date.1) " " - } - @if let Some(modification_timer) = humanize_systemtime(entry.last_modification_date) { - span .history { "(" (modification_timer) ")" } - (br()) - } - - } } td { @if let Some(size) = entry.size { @@ -394,12 +379,6 @@ fn css(color_scheme: &themes::ColorScheme) -> Markup { font-weight: bold; color: {switch_theme_active}; }} - strong {{ - font-weight: bold; - }} - .field {{ - color: {field_color} - }} p {{ margin: 0; padding: 0; @@ -451,8 +430,16 @@ fn css(color_scheme: &themes::ColorScheme) -> Markup { .history {{ color: {date_text_color}; }} - .file, .directory, .symlink {{ - display: block; + .file-entry {{ + display: flex; + justify-content: space-between; + }} + span.size {{ + border-radius: 1rem; + background: {size_background_color}; + padding: 0 0.25rem; + font-size: 0.7rem; + color: {size_text_color} }} .mobile-info {{ display: none; @@ -576,15 +563,9 @@ fn css(color_scheme: &themes::ColorScheme) -> Markup { .mobile-info {{ display: block; }} - .file, .directory, .symlink{{ - padding-bottom: 1rem; - }} .back {{ display: initial; }} - .upload form {{ - width: 100%; - }} .back {{ right: 1.5rem; }} @@ -637,7 +618,6 @@ fn css(color_scheme: &themes::ColorScheme) -> Markup { switch_theme_border = theme.switch_theme_border, change_theme_link_color = theme.change_theme_link_color, change_theme_link_color_hover = theme.change_theme_link_color_hover, - field_color = theme.field_color, upload_text_color = theme.upload_text_color, upload_form_border_color = theme.upload_form_border_color, upload_form_background = theme.upload_form_background, @@ -645,7 +625,9 @@ fn css(color_scheme: &themes::ColorScheme) -> Markup { upload_button_text_color = theme.upload_button_text_color, drag_background = theme.drag_background, drag_border_color = theme.drag_border_color, - drag_text_color = theme.drag_text_color); + drag_text_color = theme.drag_text_color, + size_background_color = theme.size_background_color, + size_text_color = theme.size_text_color); (PreEscaped(css)) } @@ -654,11 +636,6 @@ fn arrow_up() -> Markup { (PreEscaped("⇪".to_string())) } -/// Partial: new line -fn br() -> Markup { - (PreEscaped("
".to_string())) -} - /// Partial: chevron left fn chevron_left() -> Markup { (PreEscaped("◂".to_string())) diff --git a/src/themes.rs b/src/themes.rs index 917e56e..72bdcfa 100644 --- a/src/themes.rs +++ b/src/themes.rs @@ -89,7 +89,6 @@ impl ColorScheme { switch_theme_border: "#6a728a".to_string(), change_theme_link_color: "#fefefe".to_string(), change_theme_link_color_hover: "#fefefe".to_string(), - field_color: "#859cb9".to_string(), upload_text_color: "#fefefe".to_string(), upload_form_border_color: "#353946".to_string(), upload_form_background: "#4b5162".to_string(), @@ -98,6 +97,8 @@ impl ColorScheme { drag_background: "#3333338f".to_string(), drag_border_color: "#fefefe".to_string(), drag_text_color: "#fefefe".to_string(), + size_background_color: "#5294e2".to_string(), + size_text_color: "#fefefe".to_string(), }, ColorScheme::Zenburn => Theme { background: "#3f3f3f".to_string(), @@ -130,7 +131,6 @@ impl ColorScheme { switch_theme_border: "#5a5a5a".to_string(), change_theme_link_color: "#efefef".to_string(), change_theme_link_color_hover: "#efefef".to_string(), - field_color: "#9fc3a1".to_string(), upload_text_color: "#efefef".to_string(), upload_form_border_color: "#4a4949".to_string(), upload_form_background: "#777777".to_string(), @@ -139,6 +139,8 @@ impl ColorScheme { drag_background: "#3333338f".to_string(), drag_border_color: "#efefef".to_string(), drag_text_color: "#efefef".to_string(), + size_background_color: "#7f9f7f".to_string(), + size_text_color: "#efefef".to_string(), }, ColorScheme::Monokai => Theme { background: "#272822".to_string(), @@ -171,7 +173,6 @@ impl ColorScheme { switch_theme_border: "#49483E".to_string(), change_theme_link_color: "#F8F8F2".to_string(), change_theme_link_color_hover: "#F8F8F2".to_string(), - field_color: "#ccc7a7".to_string(), upload_text_color: "#F8F8F2".to_string(), upload_form_border_color: "#3B3A32".to_string(), upload_form_background: "#49483E".to_string(), @@ -180,6 +181,8 @@ impl ColorScheme { drag_background: "#3333338f".to_string(), drag_border_color: "#F8F8F2".to_string(), drag_text_color: "#F8F8F2".to_string(), + size_background_color: "#75715E".to_string(), + size_text_color: "#F8F8F2".to_string(), }, ColorScheme::Squirrel => Theme { background: "#FFFFFF".to_string(), @@ -212,7 +215,6 @@ impl ColorScheme { switch_theme_border: "#49483E".to_string(), change_theme_link_color: "#F5F5F5".to_string(), change_theme_link_color_hover: "#F5F5F5".to_string(), - field_color: "#797979".to_string(), upload_text_color: "#323232".to_string(), upload_form_border_color: "#d2d2d2".to_string(), upload_form_background: "#f2f2f2".to_string(), @@ -221,6 +223,8 @@ impl ColorScheme { drag_background: "#3333338f".to_string(), drag_border_color: "#ffffff".to_string(), drag_text_color: "#ffffff".to_string(), + size_background_color: "#323232".to_string(), + size_text_color: "#FFFFFF".to_string(), }, } } @@ -258,7 +262,6 @@ pub struct Theme { pub switch_theme_border: String, pub change_theme_link_color: String, pub change_theme_link_color_hover: String, - pub field_color: String, pub upload_text_color: String, pub upload_form_border_color: String, pub upload_form_background: String, @@ -267,4 +270,7 @@ pub struct Theme { pub drag_background: String, pub drag_border_color: String, pub drag_text_color: String, + pub size_background_color: String, + pub size_text_color: String, + } -- cgit v1.2.3 From 9e173a8d503287ff9aef8156adc7f4a4fd3892df Mon Sep 17 00:00:00 2001 From: boasting-squirrel Date: Sat, 6 Apr 2019 20:50:25 +0200 Subject: Cargo fmt --- src/themes.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/themes.rs b/src/themes.rs index 72bdcfa..dca656d 100644 --- a/src/themes.rs +++ b/src/themes.rs @@ -272,5 +272,4 @@ pub struct Theme { pub drag_text_color: String, pub size_background_color: String, pub size_text_color: String, - } -- cgit v1.2.3 From c40c30aaf2bc27a39caeb23ee61b9e4a6801e287 Mon Sep 17 00:00:00 2001 From: boasting-squirrel Date: Sun, 7 Apr 2019 08:55:06 +0200 Subject: Fixed upload bug + refactored @ else in templates --- src/renderer.rs | 84 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 44 insertions(+), 40 deletions(-) diff --git a/src/renderer.rs b/src/renderer.rs index a0da81e..2d6fd88 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -21,11 +21,13 @@ pub fn page( current_dir: &str, ) -> Markup { html! { - (page_header(page_title, &color_scheme)) + (page_header(page_title, &color_scheme, file_upload)) body#drop-container { - div.drag-form { - div.drag-title { - h1 { "Drop your file here to upload it" } + @if file_upload { + div.drag-form { + div.drag-title { + h1 { "Drop your file here to upload it" } + } } } (color_scheme_selector(&sort_method, &sort_order, &color_scheme)) @@ -129,7 +131,7 @@ fn color_scheme_link( " " @if color_scheme.is_dark() { "(dark)" - } @ else { + } @else { "(light)" } } @@ -230,7 +232,7 @@ fn entry_row( } } } - } @ else if entry.is_symlink() { + } @else if entry.is_symlink() { a.symlink href=(parametrized_link(&entry.link, &sort_method, &sort_order, &color_scheme)) { (entry.name) span.symlink-symbol { "⇢" } } @@ -652,7 +654,7 @@ fn chevron_down() -> Markup { } /// Partial: page header -fn page_header(page_title: &str, color_scheme: &themes::ColorScheme) -> Markup { +fn page_header(page_title: &str, color_scheme: &themes::ColorScheme, file_upload: bool) -> Markup { html! { (DOCTYPE) html { @@ -661,43 +663,45 @@ fn page_header(page_title: &str, color_scheme: &themes::ColorScheme) -> Markup { meta name="viewport" content="width=device-width, initial-scale=1"; title { (page_title) } style { (css(&color_scheme)) } - (PreEscaped(r#" - - "#)) + dropContainer.ondragleave = function(e) { + e.preventDefault(); + collection.splice(collection.indexOf(e.target), 1); + if (collection.length === 0) { + dragForm.style.display = 'none'; + } + }; + + dropContainer.ondrop = function(e) { + e.preventDefault(); + fileInput.files = e.dataTransfer.files; + file_submit.submit(); + dragForm.style.display = 'none'; + }; + } + + "#)) + } } } } -- cgit v1.2.3 From c24986640589df2aa5b2f7360cc8bea71ed49fbb Mon Sep 17 00:00:00 2001 From: boasting-squirrel Date: Sun, 7 Apr 2019 12:21:58 +0200 Subject: Use strum_macros::EnumIter instead of manually listing Enum variants --- Cargo.lock | 20 ++++++++++++++++++++ Cargo.toml | 2 ++ src/archive.rs | 8 ++------ src/renderer.rs | 5 +++-- src/themes.rs | 13 ++----------- 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index db2959b..dec9413 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -781,6 +781,8 @@ dependencies = [ "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", "simplelog 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "structopt 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)", + "strum 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", + "strum_macros 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "tar 0.4.22 (registry+https://github.com/rust-lang/crates.io-index)", "yansi 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1341,6 +1343,22 @@ dependencies = [ "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "strum" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "strum_macros" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "syn" version = "0.15.29" @@ -2029,6 +2047,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" "checksum structopt 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)" = "3d0760c312538987d363c36c42339b55f5ee176ea8808bbe4543d484a291c8d1" "checksum structopt-derive 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)" = "528aeb7351d042e6ffbc2a6fb76a86f9b622fdf7c25932798e7a82cb03bc94c6" +"checksum strum 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e5d1c33039533f051704951680f1adfd468fd37ac46816ded0d9ee068e60f05f" +"checksum strum_macros 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "47cd23f5c7dee395a00fa20135e2ec0fffcdfa151c56182966d7a3261343432e" "checksum syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)" = "1825685f977249735d510a242a6727b46efe914bb67e38d30c071b1b72b1d5c2" "checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" "checksum tar 0.4.22 (registry+https://github.com/rust-lang/crates.io-index)" = "c2167ff53da2a661702b3299f71a91b61b1dffef36b4b2884b1f9c67254c0133" diff --git a/Cargo.toml b/Cargo.toml index 5384ee7..94b7455 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,3 +43,5 @@ futures = "0.1.26" libflate = "0.1.21" failure = "0.1.5" log = "0.4.6" +strum = "0.15.0" +strum_macros = "0.15.0" \ No newline at end of file diff --git a/src/archive.rs b/src/archive.rs index b1119f0..f588d56 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -6,11 +6,12 @@ use serde::Deserialize; use std::io; use std::path::PathBuf; use tar::Builder; +use strum_macros::EnumIter; use crate::errors; /// Available compression methods -#[derive(Debug, Deserialize, Clone)] +#[derive(Debug, Deserialize, Clone, EnumIter)] pub enum CompressionMethod { /// TAR GZ #[serde(alias = "targz")] @@ -25,11 +26,6 @@ impl CompressionMethod { .to_string() } - /// Lists compression methods - pub fn get_compression_methods() -> Vec { - vec![CompressionMethod::TarGz] - } - pub fn extension(&self) -> String { match &self { CompressionMethod::TarGz => "tar.gz", diff --git a/src/renderer.rs b/src/renderer.rs index 2d6fd88..1371ab6 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -2,6 +2,7 @@ use chrono::{DateTime, Duration, Utc}; use chrono_humanize::{Accuracy, HumanTime, Tense}; use maud::{html, Markup, PreEscaped, DOCTYPE}; use std::time::SystemTime; +use strum::IntoEnumIterator; use crate::archive; use crate::listing; @@ -36,7 +37,7 @@ pub fn page( h1.title { (page_title) } div.toolbar { div.download { - @for compression_method in archive::CompressionMethod::get_compression_methods() { + @for compression_method in archive::CompressionMethod::iter() { (archive_button(compression_method)) } } @@ -98,7 +99,7 @@ fn color_scheme_selector( "Change theme..." } ul { - @for color_scheme in themes::ColorScheme::get_color_schemes() { + @for color_scheme in themes::ColorScheme::iter() { @if active_color_scheme.get_name() == color_scheme.get_name() { li.active { (color_scheme_link(&sort_method, &sort_order, &color_scheme)) diff --git a/src/themes.rs b/src/themes.rs index dca656d..8635c8f 100644 --- a/src/themes.rs +++ b/src/themes.rs @@ -1,8 +1,9 @@ use serde::Deserialize; use structopt::clap::{_clap_count_exprs, arg_enum}; +use strum_macros::EnumIter; arg_enum! { - #[derive(Debug, Deserialize, Clone)] + #[derive(Debug, Deserialize, Clone, EnumIter)] #[serde(rename_all = "lowercase")] pub enum ColorScheme { Archlinux, @@ -45,16 +46,6 @@ impl ColorScheme { .to_string() } - /// Lists available color schemes - pub fn get_color_schemes() -> Vec { - vec![ - ColorScheme::Archlinux, - ColorScheme::Zenburn, - ColorScheme::Monokai, - ColorScheme::Squirrel, - ] - } - /// Retrieves the color palette associated to a color scheme pub fn get_theme(self) -> Theme { match self { -- cgit v1.2.3 From 2d717e4d0e78bd2132886a3339804f05f816f67a Mon Sep 17 00:00:00 2001 From: boasting-squirrel Date: Sun, 7 Apr 2019 13:15:48 +0200 Subject: Use strum on Enums to reduce boilerplate --- src/archive.rs | 12 +++--------- src/listing.rs | 33 +++++++++------------------------ src/renderer.rs | 6 +++--- 3 files changed, 15 insertions(+), 36 deletions(-) diff --git a/src/archive.rs b/src/archive.rs index f588d56..55a80b5 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -5,27 +5,21 @@ use libflate::gzip::Encoder; use serde::Deserialize; use std::io; use std::path::PathBuf; +use strum_macros::{Display, EnumIter, EnumString}; use tar::Builder; -use strum_macros::EnumIter; use crate::errors; /// Available compression methods -#[derive(Debug, Deserialize, Clone, EnumIter)] +#[derive(Deserialize, Clone, EnumIter, EnumString, Display)] pub enum CompressionMethod { /// TAR GZ #[serde(alias = "targz")] + #[strum(serialize = "targz")] TarGz, } impl CompressionMethod { - pub fn to_string(&self) -> String { - match &self { - CompressionMethod::TarGz => "targz", - } - .to_string() - } - pub fn extension(&self) -> String { match &self { CompressionMethod::TarGz => "tar.gz", diff --git a/src/listing.rs b/src/listing.rs index b7070f3..5096c73 100644 --- a/src/listing.rs +++ b/src/listing.rs @@ -7,6 +7,7 @@ use serde::Deserialize; use std::io; use std::path::Path; use std::time::SystemTime; +use strum_macros::{Display, EnumString}; use crate::archive; use crate::errors; @@ -14,7 +15,7 @@ use crate::renderer; use crate::themes; /// Query parameters -#[derive(Debug, Deserialize)] +#[derive(Deserialize)] struct QueryParameters { sort: Option, order: Option, @@ -23,52 +24,36 @@ struct QueryParameters { } /// Available sorting methods -#[derive(Debug, Deserialize, Clone)] +#[derive(Deserialize, Clone, EnumString, Display)] #[serde(rename_all = "lowercase")] pub enum SortingMethod { /// Sort by name + #[strum(serialize = "name")] Name, /// Sort by size + #[strum(serialize = "size")] Size, /// Sort by last modification date (natural sort: follows alphanumerical order) + #[strum(serialize = "date")] Date, } -impl SortingMethod { - pub fn to_string(&self) -> String { - match &self { - SortingMethod::Name => "name", - SortingMethod::Size => "size", - SortingMethod::Date => "date", - } - .to_string() - } -} - /// Available sorting orders -#[derive(Debug, Deserialize, Clone)] +#[derive(Deserialize, Clone, EnumString, Display)] pub enum SortingOrder { /// Ascending order #[serde(alias = "asc")] + #[strum(serialize = "asc")] Ascending, /// Descending order #[serde(alias = "desc")] + #[strum(serialize = "desc")] Descending, } -impl SortingOrder { - pub fn to_string(&self) -> String { - match &self { - SortingOrder::Ascending => "asc", - SortingOrder::Descending => "desc", - } - .to_string() - } -} - #[derive(PartialEq)] /// Possible entry types pub enum EntryType { diff --git a/src/renderer.rs b/src/renderer.rs index 1371ab6..909ee75 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -141,7 +141,7 @@ fn color_scheme_link( /// Partial: archive button fn archive_button(compress_method: archive::CompressionMethod) -> Markup { - let link = format!("?download={}", compress_method.to_string()); + let link = format!("?download={}", compress_method); let text = format!("Download .{}", compress_method.extension()); html! { @@ -163,8 +163,8 @@ fn parametrized_link( return format!( "{}?sort={}&order={}&theme={}", link, - method.to_string(), - order.to_string(), + method, + order, color_scheme.to_string() ); } -- cgit v1.2.3 From e7e183e75794cfdb899ce1762d3d9ba38a923cc3 Mon Sep 17 00:00:00 2001 From: boasting-squirrel Date: Sun, 7 Apr 2019 13:16:06 +0200 Subject: Fix CSS bug --- src/renderer.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/renderer.rs b/src/renderer.rs index 909ee75..d682ee4 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -271,6 +271,8 @@ fn css(color_scheme: &themes::ColorScheme) -> Markup { html {{ font-smoothing: antialiased; text-rendering: optimizeLegibility; + width: 100%; + height: 100%; }} body {{ margin: 0; @@ -279,6 +281,8 @@ fn css(color_scheme: &themes::ColorScheme) -> Markup { color: {text_color}; background: {background}; position: relative; + width: 100%; + height: 100%; }} .container {{ padding: 1.5rem 5rem; -- cgit v1.2.3 From bbdafc3e121942c95ba81db1cba30fe438d88dfb Mon Sep 17 00:00:00 2001 From: boasting-squirrel Date: Sun, 7 Apr 2019 13:27:25 +0200 Subject: Use strum to reduce boilerplate on ColorScheme enum + removed useless Debug derives --- src/args.rs | 2 +- src/main.rs | 2 +- src/renderer.rs | 12 ++++++------ src/themes.rs | 17 ++++------------- 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 { -- cgit v1.2.3 From 8a98a8dfa4479fcbfad364343b727891b3e41a11 Mon Sep 17 00:00:00 2001 From: boasting-squirrel Date: Sun, 7 Apr 2019 13:39:26 +0200 Subject: Use serialize_all --- src/listing.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/listing.rs b/src/listing.rs index 5096c73..fee81a2 100644 --- a/src/listing.rs +++ b/src/listing.rs @@ -26,17 +26,15 @@ struct QueryParameters { /// Available sorting methods #[derive(Deserialize, Clone, EnumString, Display)] #[serde(rename_all = "lowercase")] +#[strum(serialize_all = "snake_case")] pub enum SortingMethod { /// Sort by name - #[strum(serialize = "name")] Name, /// Sort by size - #[strum(serialize = "size")] Size, /// Sort by last modification date (natural sort: follows alphanumerical order) - #[strum(serialize = "date")] Date, } -- cgit v1.2.3 From 5eda00377ad2b97856dc4cfb301bd0f238ac1a05 Mon Sep 17 00:00:00 2001 From: boasting-squirrel Date: Sun, 7 Apr 2019 13:40:16 +0200 Subject: Fix CSS bug --- src/renderer.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/renderer.rs b/src/renderer.rs index 9fb9372..21dfe4e 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -281,8 +281,6 @@ fn css(color_scheme: &themes::ColorScheme) -> Markup { color: {text_color}; background: {background}; position: relative; - width: 100%; - height: 100%; }} .container {{ padding: 1.5rem 5rem; -- cgit v1.2.3 From 1f9d59249d13ee9c20c02c1055a243e223ac9f2a Mon Sep 17 00:00:00 2001 From: boasting-squirrel Date: Sun, 7 Apr 2019 14:00:02 +0200 Subject: Use serialize_all on CompressionMethods enum --- src/archive.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/archive.rs b/src/archive.rs index 55a80b5..7cde5d8 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -12,10 +12,11 @@ use crate::errors; /// Available compression methods #[derive(Deserialize, Clone, EnumIter, EnumString, Display)] +#[serde(rename_all = "snake_case")] +#[strum(serialize_all = "snake_case")] pub enum CompressionMethod { + /// TAR GZ - #[serde(alias = "targz")] - #[strum(serialize = "targz")] TarGz, } -- cgit v1.2.3 From 2c4d35560d794af286a4cef1a27964ad97260e85 Mon Sep 17 00:00:00 2001 From: boasting-squirrel Date: Sun, 7 Apr 2019 14:00:22 +0200 Subject: Make body take 100% height in HTML --- src/renderer.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/renderer.rs b/src/renderer.rs index 21dfe4e..cf30d4a 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -281,6 +281,7 @@ fn css(color_scheme: &themes::ColorScheme) -> Markup { color: {text_color}; background: {background}; position: relative; + min-height: 100%; }} .container {{ padding: 1.5rem 5rem; -- cgit v1.2.3 From fb12cde5a0682cddf731929a5536c9d895b518ec Mon Sep 17 00:00:00 2001 From: boasting-squirrel Date: Sun, 7 Apr 2019 14:05:16 +0200 Subject: Fixed serde's rename strategy for CompressionMethods enum --- src/listing.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/listing.rs b/src/listing.rs index fee81a2..fdabc48 100644 --- a/src/listing.rs +++ b/src/listing.rs @@ -25,7 +25,7 @@ struct QueryParameters { /// Available sorting methods #[derive(Deserialize, Clone, EnumString, Display)] -#[serde(rename_all = "lowercase")] +#[serde(rename_all = "snake_case")] #[strum(serialize_all = "snake_case")] pub enum SortingMethod { /// Sort by name -- cgit v1.2.3 From 8c4e98adb7981f6a832d0ce1d25c131d70929a84 Mon Sep 17 00:00:00 2001 From: boasting-squirrel Date: Sun, 7 Apr 2019 14:09:01 +0200 Subject: Cargo fmt --- src/archive.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/archive.rs b/src/archive.rs index 7cde5d8..4703c0d 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -15,7 +15,6 @@ use crate::errors; #[serde(rename_all = "snake_case")] #[strum(serialize_all = "snake_case")] pub enum CompressionMethod { - /// TAR GZ TarGz, } -- cgit v1.2.3