mirror of
https://github.com/apognu/tuigreet.git
synced 2024-09-11 15:38:04 +03:00
Move error message outside of main prompt area.
This commit is contained in:
parent
6f4bb704df
commit
29b1ba24b0
12
Cargo.lock
generated
12
Cargo.lock
generated
@ -810,18 +810,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.25"
|
||||
version = "1.0.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fa6f76457f59514c7eeb4e59d891395fab0b2fd1d40723ae737d64153392e9c6"
|
||||
checksum = "93119e4feac1cbe6c798c34d3a53ea0026b0b1de6a120deef895137c0529bfe2"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.25"
|
||||
version = "1.0.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a36768c0fbf1bb15eca10defa29526bda730a2376c2ab4393ccfa16fb1a318d"
|
||||
checksum = "060d69a0afe7796bf42e9e2ff91f5ee691fb15c53d38b4b62a9a53eb23164745"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -928,9 +928,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "unicode-segmentation"
|
||||
version = "1.7.1"
|
||||
version = "1.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796"
|
||||
checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-width"
|
||||
|
@ -15,7 +15,6 @@ use crate::{info::get_hostname, Greeter, Mode};
|
||||
const GREETING_INDEX: usize = 0;
|
||||
const USERNAME_INDEX: usize = 1;
|
||||
const ANSWER_INDEX: usize = 2;
|
||||
const MESSAGE_INDEX: usize = 3;
|
||||
|
||||
pub fn draw(greeter: &mut Greeter, f: &mut Frame<TermionBackend<RawTerminal<io::Stdout>>>) -> Result<(u16, u16), Box<dyn Error>> {
|
||||
let size = f.size();
|
||||
@ -42,10 +41,9 @@ pub fn draw(greeter: &mut Greeter, f: &mut Frame<TermionBackend<RawTerminal<io::
|
||||
let answer_padding = if prompt_padding == 0 { 1 } else { prompt_padding };
|
||||
|
||||
let constraints = [
|
||||
Constraint::Length(greeting_height), // Greeting
|
||||
Constraint::Length(1 + username_padding), // Username
|
||||
Constraint::Length(if greeter.mode == Mode::Username { message_height } else { 1 + answer_padding }), // Message or answer
|
||||
Constraint::Length(if greeter.mode == Mode::Password { message_height } else { 1 }), // Message
|
||||
Constraint::Length(greeting_height), // Greeting
|
||||
Constraint::Length(1 + username_padding), // Username
|
||||
Constraint::Length(if greeter.mode == Mode::Username { 0 } else { 1 + answer_padding }), // Answer
|
||||
];
|
||||
|
||||
let chunks = Layout::default().direction(Direction::Vertical).constraints(constraints.as_ref()).split(frame);
|
||||
@ -109,11 +107,7 @@ pub fn draw(greeter: &mut Greeter, f: &mut Frame<TermionBackend<RawTerminal<io::
|
||||
let message_text = Span::from(message);
|
||||
let message = Paragraph::new(message_text).alignment(Alignment::Center);
|
||||
|
||||
match greeter.mode {
|
||||
Mode::Username => f.render_widget(message, chunks[ANSWER_INDEX]),
|
||||
Mode::Password => f.render_widget(message, chunks[MESSAGE_INDEX]),
|
||||
Mode::Command | Mode::Sessions | Mode::Power => {}
|
||||
}
|
||||
f.render_widget(message, Rect::new(x, y + height, width, message_height));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,6 @@ pub fn titleize(message: &str) -> String {
|
||||
pub fn get_height(greeter: &Greeter) -> u16 {
|
||||
let container_padding = greeter.container_padding();
|
||||
let prompt_padding = greeter.prompt_padding();
|
||||
let (_, message_height) = get_message_height(greeter, 2, 0);
|
||||
let (_, greeting_height) = get_greeting_height(greeter, 1, 0);
|
||||
|
||||
let initial = match greeter.mode {
|
||||
@ -18,7 +17,7 @@ pub fn get_height(greeter: &Greeter) -> u16 {
|
||||
|
||||
match greeter.mode {
|
||||
Mode::Command | Mode::Sessions | Mode::Power => initial,
|
||||
_ => initial + greeting_height + message_height,
|
||||
_ => initial + greeting_height,
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user