Rename text-align option to greet-align and limit to greeting only

This commit is contained in:
dthelegend 2024-05-13 12:55:45 +01:00 committed by Antoine POPINEAU
parent 6239bf0f31
commit ca5762d56a
2 changed files with 20 additions and 16 deletions

View File

@ -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]...'");

View File

@ -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<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);
@ -60,7 +64,7 @@ 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]);
}
@ -68,7 +72,7 @@ pub fn draw(greeter: &mut Greeter, f: &mut Frame) -> Result<(u16, u16), Box<dyn
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")));
@ -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));
}