diff --git a/contrib/man/tuigreet-1.scd b/contrib/man/tuigreet-1.scd index ca517f4..8fde4f8 100644 --- a/contrib/man/tuigreet-1.scd +++ b/contrib/man/tuigreet-1.scd @@ -105,6 +105,10 @@ tuigreet - A graphical console greeter for greetd *--prompt-padding ROWS* Add spacing between form fields. +*--greet-align [left|center|right]* + Alignment of the greeting text in the main prompt container + (default: 'center'). + *--power-shutdown CMD [ARGS]...* Customize the command run when instructed to shut down the machine. This must be a non-interactive command (sudo cannot prompt for a password, for example). diff --git a/src/greeter.rs b/src/greeter.rs index 597cc7e..c64d230 100644 --- a/src/greeter.rs +++ b/src/greeter.rs @@ -90,6 +90,15 @@ impl SecretDisplay { } } +// This enum models text alignment options +#[derive(SmartDefault, Debug, Clone)] +pub enum GreetAlign { + #[default] + Center, + Left, + Right +} + #[derive(SmartDefault)] pub struct Greeter { pub debug: bool, @@ -270,7 +279,7 @@ impl Greeter { self.connect().await; } - // Connect to `greetd` and return a strea we can safely write to. + // Connect to `greetd` and return a stream we can safely write to. pub async fn connect(&mut self) { match UnixStream::connect(&self.socket).await { Ok(stream) => self.stream = Some(Arc::new(RwLock::new(stream))), @@ -340,6 +349,18 @@ impl Greeter { 1 } + pub fn greet_align(&self) -> GreetAlign { + if let Some(value) = self.option("greet-align") { + match value.as_str() { + "left" => GreetAlign::Left, + "right" => GreetAlign::Right, + _ => GreetAlign::Center + } + } else { + GreetAlign::default() + } + } + // Sets the locale that will be used for this invocation from environment. fn set_locale(&mut self) { let locale = DesktopLanguageRequester::requested_languages() @@ -384,6 +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("", "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 53400c5..9d57329 100644 --- a/src/ui/prompt.rs +++ b/src/ui/prompt.rs @@ -10,7 +10,7 @@ use tui::{ use crate::{ info::get_hostname, ui::{prompt_value, util::*, Frame}, - Greeter, Mode, SecretDisplay, + Greeter, Mode, SecretDisplay, GreetAlign }; use super::common::style::Themed; @@ -27,6 +27,11 @@ pub fn draw(greeter: &mut Greeter, f: &mut Frame) -> Result<(u16, u16), Box Alignment::Center, + GreetAlign::Left => Alignment::Left, + GreetAlign::Right => Alignment::Right + }; let container = Rect::new(x, y, width, height); let frame = Rect::new(x + container_padding, y + container_padding, width - (2 * container_padding), height - (2 * container_padding)); @@ -59,7 +64,7 @@ pub fn draw(greeter: &mut Greeter, f: &mut Frame) -> Result<(u16, u16), Box