Skip to content

Commit

Permalink
actually render hosts and runs in tui
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhou121 committed Apr 5, 2024
1 parent 8a182c1 commit 5fdfe1b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
24 changes: 12 additions & 12 deletions lapon-tui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ use lapon_common::action::ActionMessage;
use ratatui::{
buffer::Buffer,
layout::{Constraint, Direction, Layout, Rect},
style::{Style, Stylize},
text::{Line, Text},
widgets::{Block, Borders, Paragraph, Widget},
widgets::{Block, Borders, List, Widget},
Frame,
};
use uuid::Uuid;
Expand Down Expand Up @@ -129,9 +127,6 @@ impl App {

impl Widget for &App {
fn render(self, area: Rect, buf: &mut Buffer) {
let counter_text = Text::from(vec![Line::from(vec!["This is the first task This is the first task This is the first task This is the first task".into()])
.style(Style::default().on_gray())]);

let layout = Layout::default()
.direction(Direction::Horizontal)
.constraints(vec![
Expand All @@ -143,12 +138,17 @@ impl Widget for &App {

if let Some(run) = self.runs.first() {
run.render(layout[1], buf);
List::new(run.hosts.iter().map(|host| host.host.clone()))
.block(Block::default().borders(Borders::RIGHT))
.render(layout[0], buf);
}
Paragraph::new(counter_text.clone())
.block(Block::default().borders(Borders::RIGHT))
.render(layout[0], buf);
Paragraph::new(counter_text)
.block(Block::default().borders(Borders::LEFT))
.render(layout[2], buf);
List::new(
self.runs
.iter()
.enumerate()
.map(|(i, run)| run.name.clone().unwrap_or_else(|| format!("Run {}", i + 1))),
)
.block(Block::default().borders(Borders::LEFT))
.render(layout[2], buf);
}
}
9 changes: 6 additions & 3 deletions lapon-tui/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::reflow::{LineComposer, WordWrapper, WrappedLine};

pub struct HostSection {
pub id: Uuid,
pub host: String,
pub actions: Vec<ActionSection>,
pub scroll: u16,
}
Expand Down Expand Up @@ -82,12 +83,13 @@ impl ActionSection {

pub struct RunPanel {
pub id: Uuid,
pub name: Option<String>,
pub hosts: Vec<HostSection>,
}

impl RunPanel {
pub fn new(id: Uuid, hosts: Vec<HostSection>) -> Self {
Self { id, hosts }
pub fn new(id: Uuid, name: Option<String>, hosts: Vec<HostSection>) -> Self {
Self { id, name, hosts }
}

pub fn render(&self, area: Rect, buf: &mut Buffer) {
Expand All @@ -106,9 +108,10 @@ const fn get_line_offset(line_width: u16, text_area_width: u16, alignment: Align
}

impl HostSection {
pub fn new(id: Uuid, actions: Vec<ActionSection>) -> Self {
pub fn new(id: Uuid, host: String, actions: Vec<ActionSection>) -> Self {
Self {
id,
host,
actions,
scroll: 0,
}
Expand Down
3 changes: 2 additions & 1 deletion lapon/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,14 @@ impl Run {
.map(|host| {
HostSection::new(
host.id,
host.host.clone(),
self.actions
.iter()
.map(|action| ActionSection::new(action.id, action.name.clone()))
.collect(),
)
})
.collect();
RunPanel::new(self.id, hosts)
RunPanel::new(self.id, None, hosts)
}
}

0 comments on commit 5fdfe1b

Please sign in to comment.