diff options
Diffstat (limited to 'src/gui/util.rs')
-rw-r--r-- | src/gui/util.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/gui/util.rs b/src/gui/util.rs new file mode 100644 index 0000000..38ed1e7 --- /dev/null +++ b/src/gui/util.rs @@ -0,0 +1,21 @@ +use tui::{ + layout::{Alignment, Rect}, + style::{Color, Modifier, Style}, + widgets::Paragraph, +}; + +pub fn title(str: &str) -> Paragraph { + Paragraph::new(str).alignment(Alignment::Center).style( + Style::default() + .fg(Color::Blue) + .add_modifier(Modifier::BOLD), + ) +} + +pub fn center_vertically(chunk: Rect, text: &String) -> String { + let text_lines = text.lines().count(); + let chunk_inner_lines: usize = (chunk.height - 2).into(); + let blank_lines = chunk_inner_lines - text_lines; + let newlines = "\n".repeat(blank_lines / 2); + format!("{}{}", newlines, text) +} |