|
1 | 1 | use std::process::Command; |
2 | 2 |
|
3 | | -use tui::layout::{Constraint, Direction, Layout}; |
| 3 | +use tui::{ |
| 4 | + layout::{Constraint, Direction, Layout}, |
| 5 | + style::{Color, Style}, |
| 6 | + text::Spans, |
| 7 | + widgets::{Block, Borders, Paragraph}, |
| 8 | +}; |
4 | 9 |
|
5 | 10 | mod app; |
6 | 11 | mod database; |
@@ -43,26 +48,66 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { |
43 | 48 | .constraints([Constraint::Length(3), Constraint::Percentage(90)].as_ref()) |
44 | 49 | .split(frame.size()); |
45 | 50 |
|
46 | | - let chunk_b = Layout::default() |
| 51 | + let chunk_t = Layout::default() |
47 | 52 | .direction(Direction::Horizontal) |
48 | | - .margin(1) |
49 | | - .horizontal_margin(0) |
| 53 | + .margin(0) |
50 | 54 | .constraints( |
51 | 55 | [ |
| 56 | + Constraint::Percentage(80), |
| 57 | + Constraint::Length(2), |
| 58 | + Constraint::Length(10), |
| 59 | + ] |
| 60 | + .as_ref(), |
| 61 | + ) |
| 62 | + .split(chunks[0]); |
| 63 | + |
| 64 | + let constraints = match app.show_help { |
| 65 | + false => { |
| 66 | + vec![ |
| 67 | + Constraint::Percentage(50), |
| 68 | + Constraint::Length(2), |
| 69 | + Constraint::Percentage(50), |
| 70 | + ] |
| 71 | + } |
| 72 | + true => { |
| 73 | + vec![ |
52 | 74 | Constraint::Percentage(40), |
53 | 75 | Constraint::Length(2), |
54 | 76 | Constraint::Percentage(30), |
55 | 77 | Constraint::Length(2), |
56 | 78 | Constraint::Percentage(30), |
57 | 79 | ] |
58 | | - .as_ref(), |
59 | | - ) |
| 80 | + } |
| 81 | + }; |
| 82 | + |
| 83 | + let chunk_b = Layout::default() |
| 84 | + .direction(Direction::Horizontal) |
| 85 | + .margin(1) |
| 86 | + .horizontal_margin(0) |
| 87 | + .constraints(constraints.as_ref()) |
60 | 88 | .split(chunks[1]); |
61 | 89 |
|
62 | | - render_group_tabs(&app, chunks[0], frame); |
| 90 | + let block = Block::default() |
| 91 | + .borders(Borders::ALL) |
| 92 | + .border_type(tui::widgets::BorderType::Rounded) |
| 93 | + .border_style(Style::default().fg(Color::LightMagenta)) |
| 94 | + .title_alignment(tui::layout::Alignment::Center); |
| 95 | + |
| 96 | + let help_span = Spans::from("'h' Show help"); |
| 97 | + frame.render_widget( |
| 98 | + Paragraph::new(help_span) |
| 99 | + .block(block) |
| 100 | + .alignment(tui::layout::Alignment::Center), |
| 101 | + chunk_t[2], |
| 102 | + ); |
| 103 | + |
| 104 | + render_group_tabs(&app, chunk_t[0], frame); |
63 | 105 | render_host_table(&mut app, chunk_b[0], frame); |
64 | 106 | render_config(&mut app, chunk_b[2], frame); |
65 | | - render_shortcuts(&app, chunk_b[4], frame); |
| 107 | + |
| 108 | + if app.show_help { |
| 109 | + render_shortcuts(&app, chunk_b[4], frame); |
| 110 | + } |
66 | 111 | })?; |
67 | 112 |
|
68 | 113 | handle_inputs(&mut app)?; |
|
0 commit comments