Skip to content

Commit

Permalink
Rename text-align option to greet-align and limit to greeting only
Browse files Browse the repository at this point in the history
  • Loading branch information
dthelegend committed May 13, 2024
1 parent 8fbef86 commit df0a669
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
16 changes: 8 additions & 8 deletions src/greeter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -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]...'");
Expand Down
20 changes: 12 additions & 8 deletions src/ui/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -23,10 +27,10 @@ pub fn draw(greeter: &mut Greeter, f: &mut Frame) -> Result<(u16, u16), Box<dyn

let container_padding = greeter.container_padding();
let prompt_padding = greeter.prompt_padding();
let text_alignment = match greeter.text_align() {
TextAlign::Center => 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);
Expand Down Expand Up @@ -60,15 +64,15 @@ pub fn draw(greeter: &mut Greeter, f: &mut Frame) -> Result<(u16, u16), Box<dyn

if let Some(greeting) = &greeting {
let greeting_text = greeting.trim_end();
let greeting_label = Paragraph::new(greeting_text).alignment(text_alignment).style(theme.of(&[Themed::Greet]));
let greeting_label = Paragraph::new(greeting_text).alignment(greeting_alignment).style(theme.of(&[Themed::Greet]));

f.render_widget(greeting_label, chunks[GREETING_INDEX]);
}

let username_label = if greeter.user_menu && greeter.username.value.is_empty() {
let prompt_text = Span::from(fl!("select_user"));

Paragraph::new(prompt_text).alignment(text_alignment)
Paragraph::new(prompt_text).alignment(Alignment::Center)
} else {
let username_text = prompt_value(theme, Some(fl!("username")));

Expand Down Expand Up @@ -134,7 +138,7 @@ pub fn draw(greeter: &mut Greeter, f: &mut Frame) -> Result<(u16, u16), Box<dyn

if let Some(message) = message {
let message_text = Text::from(message);
let message = Paragraph::new(message_text).alignment(text_alignment);
let message = Paragraph::new(message_text).alignment(Alignment::Center);

f.render_widget(message, Rect::new(x, y + height, width, message_height));
}
Expand Down

0 comments on commit df0a669

Please sign in to comment.