From ca5762d56a0e05fc5d3ace0163112c71ed1665ec Mon Sep 17 00:00:00 2001 From: dthelegend Date: Mon, 13 May 2024 12:55:45 +0100 Subject: [PATCH] Rename text-align option to greet-align and limit to greeting only --- src/greeter.rs | 16 ++++++++-------- src/ui/prompt.rs | 20 ++++++++++++-------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/greeter.rs b/src/greeter.rs index e72047d..3ccb641 100644 --- a/src/greeter.rs +++ b/src/greeter.rs @@ -92,7 +92,7 @@ impl SecretDisplay { // This enum models text alignment options #[derive(SmartDefault, Debug, Clone)] -pub enum TextAlign { +pub enum GreetAlign { #[default] Center, Left, @@ -349,15 +349,15 @@ impl Greeter { 1 } - pub fn text_align(&self) -> TextAlign { - if let Some(value) = self.option("text-align") { + pub fn greet_align(&self) -> GreetAlign { + if let Some(value) = self.option("greet-align") { match value.to_uppercase().as_str() { - "LEFT" | "L" => TextAlign::Left, - "RIGHT" | "R" => TextAlign::Right, - _ => TextAlign::Center + "left" => GreetAlign::Left, + "right" => GreetAlign::Right, + _ => GreetAlign::Center } } else { - TextAlign::default() + GreetAlign::default() } } @@ -405,7 +405,7 @@ impl Greeter { opts.optopt("", "window-padding", "padding inside the terminal area (default: 0)", "PADDING"); opts.optopt("", "container-padding", "padding inside the main prompt container (default: 1)", "PADDING"); opts.optopt("", "prompt-padding", "padding between prompt rows (default: 1)", "PADDING"); - opts.optopt("", "text-align", "alignment of text in the prompt container (default: 'center')", "[left|center|right]"); + opts.optopt("", "greet-align", "alignment of the greeting text in the main prompt container (default: 'center')", "[left|center|right]"); opts.optopt("", "power-shutdown", "command to run to shut down the system", "'CMD [ARGS]...'"); opts.optopt("", "power-reboot", "command to run to reboot the system", "'CMD [ARGS]...'"); diff --git a/src/ui/prompt.rs b/src/ui/prompt.rs index f7b9080..9d57329 100644 --- a/src/ui/prompt.rs +++ b/src/ui/prompt.rs @@ -7,7 +7,11 @@ use tui::{ widgets::{Block, BorderType, Borders, Paragraph}, }; -use crate::{info::get_hostname, ui::{prompt_value, util::*, Frame}, Greeter, Mode, SecretDisplay, TextAlign}; +use crate::{ + info::get_hostname, + ui::{prompt_value, util::*, Frame}, + Greeter, Mode, SecretDisplay, GreetAlign +}; use super::common::style::Themed; @@ -23,10 +27,10 @@ pub fn draw(greeter: &mut Greeter, f: &mut Frame) -> Result<(u16, u16), Box Alignment::Center, - TextAlign::Left => Alignment::Left, - TextAlign::Right => Alignment::Right + let greeting_alignment = match greeter.greet_align() { + GreetAlign::Center => Alignment::Center, + GreetAlign::Left => Alignment::Left, + GreetAlign::Right => Alignment::Right }; let container = Rect::new(x, y, width, height); @@ -60,7 +64,7 @@ pub fn draw(greeter: &mut Greeter, f: &mut Frame) -> Result<(u16, u16), Box Result<(u16, u16), Box Result<(u16, u16), Box