blob: c62c755246455ed9292f4caba877e7f43d86fcc3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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: &str) -> 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}")
}
|