aboutsummaryrefslogtreecommitdiff
path: root/src/gui/util.rs
blob: 2314aba3515fb70bfc702642fc4833a971bf8b83 (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)
}