mirror of
https://github.com/coastalwhite/lemurs
synced 2024-11-10 05:14:11 +00:00
Add basis for configuration
This commit is contained in:
parent
6217410416
commit
759e6a106c
4 changed files with 245 additions and 1 deletions
38
Cargo.lock
generated
38
Cargo.lock
generated
|
@ -197,6 +197,12 @@ dependencies = [
|
|||
"libc 0.2.112",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hex"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "1.7.0"
|
||||
|
@ -231,11 +237,14 @@ dependencies = [
|
|||
"clap",
|
||||
"crossterm 0.22.1",
|
||||
"fern",
|
||||
"hex",
|
||||
"log",
|
||||
"nix 0.23.1",
|
||||
"pam",
|
||||
"pgs-files",
|
||||
"rand",
|
||||
"serde",
|
||||
"toml",
|
||||
"tui",
|
||||
"unicode-width",
|
||||
]
|
||||
|
@ -542,6 +551,26 @@ version = "1.1.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.133"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "97565067517b60e2d1ea8b268e59ce036de907ac523ad83a0475da04e818989a"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.133"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed201699328568d8d08208fdd080e3ff594e6c422e438b6705905da01005d537"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "signal-hook"
|
||||
version = "0.3.13"
|
||||
|
@ -633,6 +662,15 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.5.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tui"
|
||||
version = "0.16.0"
|
||||
|
|
|
@ -28,3 +28,6 @@ rand = "0.8.4"
|
|||
chrono = "0.4"
|
||||
nix = "0.23.1"
|
||||
clap = { version = "3.0.0", features = ["derive"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
toml = "0.5"
|
||||
hex = "0.4.3"
|
||||
|
|
57
extra/config.toml
Normal file
57
extra/config.toml
Normal file
|
@ -0,0 +1,57 @@
|
|||
preview = true
|
||||
|
||||
[window_manager_selector]
|
||||
show_movers = "true"
|
||||
mover_color = "dark gray"
|
||||
mover_color_focused = "orange"
|
||||
|
||||
left_mover = "<"
|
||||
right_mover = ">"
|
||||
|
||||
mover_margin = 1
|
||||
|
||||
selected_color = "gray"
|
||||
selected_color_focused = "white"
|
||||
|
||||
selected_modifiers = "underlined"
|
||||
selected_modifiers_focused = "bold"
|
||||
|
||||
display_neighbours = true
|
||||
neighbour_color = "dark gray"
|
||||
neighbour_color_focused = "gray"
|
||||
|
||||
neighbour_modifiers = ""
|
||||
neighbour_modifiers_focused = ""
|
||||
|
||||
neighbour_margin = 1
|
||||
|
||||
max_display_length = 8
|
||||
|
||||
[username_field]
|
||||
show_title = true
|
||||
title = "Login"
|
||||
|
||||
title_color = "white"
|
||||
title_color_focused = "orange"
|
||||
|
||||
content_color = "white"
|
||||
content_color_focused = "orange"
|
||||
|
||||
show_border = true
|
||||
border_color = "white"
|
||||
border_color_focused = "orange"
|
||||
|
||||
[password_field]
|
||||
show_title = true
|
||||
title = "Login"
|
||||
|
||||
title_color = "white"
|
||||
title_color_focused = "orange"
|
||||
|
||||
content_color = "white"
|
||||
content_color_focused = "orange"
|
||||
content_replacement_character = "*"
|
||||
|
||||
show_border = true
|
||||
border_color = "white"
|
||||
border_color_focused = "orange"
|
148
src/config.rs
148
src/config.rs
|
@ -1,9 +1,155 @@
|
|||
use log::error;
|
||||
use serde::Deserialize;
|
||||
|
||||
use tui::style::{Color, Modifier};
|
||||
|
||||
pub fn get_color(color: &str) -> Color {
|
||||
if let Some(color) = str_to_color(color) {
|
||||
color
|
||||
} else {
|
||||
error!("Did not recognize the color '{}'", color);
|
||||
Color::White
|
||||
}
|
||||
}
|
||||
|
||||
fn str_to_color(color: &str) -> Option<Color> {
|
||||
use Color::*;
|
||||
|
||||
let c = color.to_lowercase();
|
||||
Some(match &c[..] {
|
||||
"black" => Black,
|
||||
"red" => Red,
|
||||
"green" => Green,
|
||||
"yellow" => Yellow,
|
||||
"blue" => Blue,
|
||||
"magenta" => Magenta,
|
||||
"cyan" => Cyan,
|
||||
"gray" => Gray,
|
||||
"dark gray" => DarkGray,
|
||||
"light red" => LightRed,
|
||||
"light green" => LightGreen,
|
||||
"light yellow" => LightYellow,
|
||||
"light blue" => LightBlue,
|
||||
"light magenta" => LightMagenta,
|
||||
"light cyan" => LightCyan,
|
||||
"white" => White,
|
||||
c => {
|
||||
if !c.starts_with("#") || c.len() != 7 {
|
||||
return None;
|
||||
}
|
||||
|
||||
let r = hex::decode(&c[1..3]).ok().and_then(|mut bytes| bytes.pop())?;
|
||||
let g = hex::decode(&c[3..5]).ok().and_then(|mut bytes| bytes.pop())?;
|
||||
let b = hex::decode(&c[5..7]).ok().and_then(|mut bytes| bytes.pop())?;
|
||||
|
||||
Rgb(r, g, b)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn get_modifier(modifier: &str) -> Option<Modifier> {
|
||||
let m = modifier.trim().to_lowercase();
|
||||
Some(match &m[..] {
|
||||
"bold" => Modifier::BOLD,
|
||||
"dim" => Modifier::DIM,
|
||||
"italic" => Modifier::ITALIC,
|
||||
"underlined" => Modifier::UNDERLINED,
|
||||
"slow blink" => Modifier::SLOW_BLINK,
|
||||
"rapid blink" => Modifier::RAPID_BLINK,
|
||||
"reversed" => Modifier::REVERSED,
|
||||
"crossed out" => Modifier::CROSSED_OUT,
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
fn str_to_modifiers(modifiers: &str) -> Vec<Modifier> {
|
||||
let mut ms = Vec::new();
|
||||
|
||||
for modifier in modifiers.split(",") {
|
||||
if let Some(modifier) = get_modifier(modifier) {
|
||||
ms.push(modifier);
|
||||
}
|
||||
}
|
||||
|
||||
ms
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Config {
|
||||
pub preview: bool,
|
||||
pub window_manager_selector: WMSelectorConfig,
|
||||
pub username_field: UsernameFieldConfig,
|
||||
pub password_field: PassswordFieldConfig,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct WMSelectorConfig {
|
||||
pub show_movers: bool,
|
||||
pub mover_color: String,
|
||||
pub mover_color_focused: String,
|
||||
|
||||
pub left_mover: String,
|
||||
pub right_mover: String,
|
||||
|
||||
pub mover_margin: u16,
|
||||
|
||||
pub selected_color: String,
|
||||
pub selected_color_focused: String,
|
||||
|
||||
pub selected_modifiers: String,
|
||||
pub selected_modifiers_focused: String,
|
||||
|
||||
pub display_neighbours: bool,
|
||||
pub neighbour_color: String,
|
||||
pub neighbour_color_focused: String,
|
||||
|
||||
pub neighbour_modifiers: String,
|
||||
pub neighbour_modifiers_focused: String,
|
||||
|
||||
pub neighbour_margin: u16,
|
||||
|
||||
pub max_display_length: u16,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct UsernameFieldConfig {
|
||||
pub show_title: bool,
|
||||
pub title: String,
|
||||
|
||||
pub show_border: bool,
|
||||
|
||||
pub title_color: String,
|
||||
pub title_color_focused: String,
|
||||
|
||||
pub content_color: String,
|
||||
pub content_color_focused: String,
|
||||
|
||||
pub border_color: String,
|
||||
pub border_color_focused: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct PassswordFieldConfig {
|
||||
pub show_title: bool,
|
||||
pub title: String,
|
||||
|
||||
pub show_border: bool,
|
||||
|
||||
pub title_color: String,
|
||||
pub title_color_focused: String,
|
||||
|
||||
pub content_color: String,
|
||||
pub content_color_focused: String,
|
||||
pub content_replacement_character: char,
|
||||
|
||||
pub border_color: String,
|
||||
pub border_color_focused: String,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Config {
|
||||
Config { preview: false }
|
||||
toml::from_str(include_str!("../extra/config.toml")).expect("Default config incorrect!")
|
||||
}
|
||||
|
||||
fn
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue