From e4a840d7e4fc9f3d44479c3f70d14522835d88e6 Mon Sep 17 00:00:00 2001 From: Nickiel12 Date: Wed, 31 May 2023 21:15:12 -0700 Subject: [PATCH] feat: added a ui/ to hold ui functions --- src/lib.rs | 2 ++ src/ui.rs | 32 +++++++++++++++++++++----------- src/uis/history.rs | 12 ++++++++++++ src/uis/mod.rs | 4 ++++ 4 files changed, 39 insertions(+), 11 deletions(-) create mode 100644 src/uis/history.rs create mode 100644 src/uis/mod.rs diff --git a/src/lib.rs b/src/lib.rs index 717054c..eaa7080 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,3 +4,5 @@ pub mod app; pub mod tui; pub mod ui; + +pub mod uis; diff --git a/src/ui.rs b/src/ui.rs index 7d2830f..e0afaa9 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -1,6 +1,4 @@ -use std::rc::Rc; - -use crate::app::{AppResult, App}; +use crate::app::App; use ratatui::{ backend::Backend, layout::{Constraint, Direction, Layout, Rect}, @@ -10,6 +8,8 @@ use ratatui::{ Frame, }; +use crate::uis::render_history_tab; + pub fn render (f: &mut Frame, app: &App) { @@ -19,24 +19,33 @@ pub fn render (f: &mut Frame, app: &App) { .constraints([Constraint::Length(3), Constraint::Min(0)].as_ref()) .split(size); - let bottom_block = Block::default(); + let bottom_block = Block::default() + .borders(Borders::ALL); f.render_widget(bottom_block, chunks[1]); render_statusbar(f, chunks[0], app); + + let bottom_chunk = Layout::default() + .direction(Direction::Vertical) + .margin(1) + .constraints([Constraint::Percentage(100)]) + .split(chunks[1]); + // if app.tabs selected == history, + render_history_tab(f, bottom_chunk[0], app); } pub fn render_statusbar (f: &mut Frame, status_rect: Rect, app: &App) { let status_bar_chunks = Layout::default() .direction(Direction::Horizontal) - .constraints([Constraint::Percentage(50), Constraint::Min(10)]) - .margin(1) + .constraints([Constraint::Percentage(75), Constraint::Min(10)]) .split(status_rect); - let top_block = Block::default() + let left_block = Block::default() + .borders(Borders::ALL); + let right_block = Block::default() .borders(Borders::ALL); - f.render_widget(top_block, status_rect); let titles = app .tabs @@ -46,9 +55,10 @@ pub fn render_statusbar (f: &mut Frame, status_rect: Rect, app: & .collect(); let tabs = Tabs::new(titles) - .block(Block::default().borders(Borders::NONE)) + //.block(Block::default().borders(Borders::NONE)) + .block(left_block) .select(app.tab_index) - .style(Style::default().fg(Color::Cyan)) + //.style(Style::default().fg(Color::Cyan)) .highlight_style( Style::default() .fg(Color::White) @@ -62,7 +72,7 @@ pub fn render_statusbar (f: &mut Frame, status_rect: Rect, app: & Text::styled("Aurora", Style::default().fg(Color::Green) ) - ); + ).block(right_block); f.render_widget(connection_paragraph, status_bar_chunks[1]); } diff --git a/src/uis/history.rs b/src/uis/history.rs new file mode 100644 index 0000000..b6e58e7 --- /dev/null +++ b/src/uis/history.rs @@ -0,0 +1,12 @@ +use ratatui::{backend::Backend, Frame, layout::Rect, widgets::Paragraph, text::Text, style::{Style, Color}}; +use crate::app::App; + + +pub fn render_history_tab (f: &mut Frame, status_rect: Rect, app: &App) { + let connection_paragraph = Paragraph::new( + Text::styled("I'm a ghost!", + Style::default().fg(Color::Green) + ) + ); + f.render_widget(connection_paragraph, status_rect); +} diff --git a/src/uis/mod.rs b/src/uis/mod.rs new file mode 100644 index 0000000..8a5c59a --- /dev/null +++ b/src/uis/mod.rs @@ -0,0 +1,4 @@ + + +pub mod history; +pub use self::history::render_history_tab;