1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
extern crate tui; use tui::{Frame, Terminal}; use tui::backend::Backend; use tui::layout::{Alignment, Rect}; use tui::style::{Color, Style}; use tui::text::{Span, Spans}; use tui::widgets::{Block, Borders, Paragraph}; use crate::userinterface::widgets::{BORDERS, EMPTY_SPACES}; const EXTRA_SPACES: u16 = 3; const LARGER_ROW: u16 = 37; pub const WIN_WIDTH: u16 = LARGER_ROW + (EMPTY_SPACES + EXTRA_SPACES) * 2 + BORDERS; const TEXT_HEIGHT: u16 = 3; pub const WIN_HEIGHT: u16 = TEXT_HEIGHT + EMPTY_SPACES + BORDERS; pub fn render<B: Backend>(terminal: &mut Terminal<B>, text_error: &String) { terminal.draw(|frame| { let frame_area = frame.size(); let frame_left = frame_area.left(); let frame_top = frame_area.top(); let frame_width = frame_area.right() - frame_left; let frame_height = frame_area.bottom() - frame_top; let window_area = Rect::new(frame_left + frame_width/2 - WIN_WIDTH/2, frame_top + frame_height/2 - WIN_HEIGHT/2, WIN_WIDTH, WIN_HEIGHT); let window_left = window_area.left(); let window_top = window_area.top(); let window_width = window_area.right() - window_left; let window_height = window_area.bottom() - window_top; let text_area = Rect::new(window_left + 1, window_top + 1 + window_height/2 - BORDERS, window_width - BORDERS, window_height - BORDERS); render_borders(frame, &window_area); render_text(frame, &text_area, &text_error); }).unwrap(); } fn render_borders<B: Backend>(frame: &mut Frame<B>, area: &Rect) { let block = Block::default().borders(Borders::ALL) .border_style(Style::default().fg(Color::Red)); frame.render_widget(block, *area); } fn render_text<B: Backend>(frame: &mut Frame<B>, area: &Rect, text: &str) { let generate_text = vec![ Spans::from(Span::styled(text, Style::default().fg(Color::Red))), Spans::from(Span::raw("")), Spans::from(Span::raw("< Enter > to exit")), ]; let generate_paragraph = Paragraph::new(generate_text).alignment(Alignment::Center); frame.render_widget(generate_paragraph, *area); }