diff --git a/lapon-common/src/action.rs b/lapon-common/src/action.rs index 85416d3..229979d 100644 --- a/lapon-common/src/action.rs +++ b/lapon-common/src/action.rs @@ -31,6 +31,7 @@ pub enum ActionMessage { pub struct ActionData { pub id: ActionId, pub name: String, + pub action: String, pub input: Vec, } diff --git a/lapon-node/src/action/data.rs b/lapon-node/src/action/data.rs index bbeb085..480cf50 100644 --- a/lapon-node/src/action/data.rs +++ b/lapon-node/src/action/data.rs @@ -39,6 +39,15 @@ pub fn parse_value(cwd: &Path, value: &Value) -> Result> { return Err(anyhow!("action key should be string")); }; + let name = if let Some(name) = dict.get(&Value::String("name".into())) { + let Value::String(name) = name else { + return Err(anyhow!("name should be string")); + }; + Some(name.to_string()) + } else { + None + }; + if action_name.as_ref() == "job" { let Some(params) = dict.get(&Value::String("params".into())) else { return Err(anyhow!("job needs params")); @@ -62,7 +71,8 @@ pub fn parse_value(cwd: &Path, value: &Value) -> Result> { let input = action.input(cwd, params)?; actions.push(ActionData { id: ActionId::new(), - name: action_name.to_string(), + name: name.unwrap_or_else(|| action_name.to_string()), + action: action_name.to_string(), input, }); } diff --git a/lapon-node/src/node.rs b/lapon-node/src/node.rs index 8947a35..fb4dd86 100644 --- a/lapon-node/src/node.rs +++ b/lapon-node/src/node.rs @@ -74,11 +74,11 @@ fn node_run_action( data: &ActionData, tx: &Sender, ) -> Result { - let result = if let Some(action) = all_actions.get(&data.name) { + let result = if let Some(action) = all_actions.get(&data.action) { let _ = tx.send(ActionMessage::ActionStarted { id: data.id }); action.execute(data.id, &data.input, tx)? } else { - return Err(anyhow!("can't find action name {}", data.name)); + return Err(anyhow!("can't find action name {}", data.action)); }; Ok(result) } diff --git a/lapon-tui/src/app.rs b/lapon-tui/src/app.rs index 8eaeb0d..239c2cc 100644 --- a/lapon-tui/src/app.rs +++ b/lapon-tui/src/app.rs @@ -3,14 +3,10 @@ use crossbeam_channel::{Receiver, Sender}; use lapon_common::action::ActionMessage; use ratatui::{ buffer::Buffer, - layout::{Alignment, Constraint, Direction, Layout, Rect}, + layout::{Constraint, Direction, Layout, Rect}, style::{Style, Stylize}, - symbols, text::{Line, Text}, - widgets::{ - block::{Position, Title}, - Block, Borders, Paragraph, Tabs, Widget, - }, + widgets::{Block, Borders, Paragraph, Widget}, Frame, }; use uuid::Uuid; @@ -133,54 +129,26 @@ impl App { impl Widget for &App { fn render(self, area: Rect, buf: &mut Buffer) { - let title = Title::from(" Counter App Tutorial ".bold()); - let instructions = Title::from(Line::from(vec![ - " Decrement ".blue(), - "".into(), - " Increment ".into(), - "".into(), - " Quit ".into(), - " ".into(), - ])); - let block = Block::default() - .title(title.alignment(Alignment::Center)) - .title( - instructions - .alignment(Alignment::Center) - .position(Position::Bottom), - ) - .borders(Borders::ALL); - 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![Constraint::Length(20), Constraint::Fill(1)]) + .constraints(vec![ + Constraint::Length(20), + Constraint::Fill(1), + Constraint::Length(20), + ]) .split(area); - // Paragraph::new(counter_text.clone()) - // .wrap(Wrap { trim: false }) - // // .on_gray() - // .block(block.clone()) - // .scroll((self.scroll_offset.0, 0)) - // .render(layout[1], buf); - // let mut run = RunPanel::new(); - // run.actions.push(ActionSection::new("This is the first task This is the first task This is the first task This is the first task".to_string())); - // run.render(layout[1], buf); if let Some(run) = self.runs.first() { run.render(layout[1], buf); } - Paragraph::new(counter_text) - .block(block) + Paragraph::new(counter_text.clone()) + .block(Block::default().borders(Borders::RIGHT)) .render(layout[0], buf); - - Tabs::new(vec!["Tab1", "Tab2", "Tab3", "Tab4"]) - .block(Block::default().title("Tabs").borders(Borders::ALL)) - .style(Style::default().white()) - .highlight_style(Style::default().yellow()) - .select(2) - .divider(symbols::DOT) - .padding("->", "<-"); + Paragraph::new(counter_text) + .block(Block::default().borders(Borders::LEFT)) + .render(layout[2], buf); } } diff --git a/lapon-tui/src/run.rs b/lapon-tui/src/run.rs index 8a0b16c..54088e8 100644 --- a/lapon-tui/src/run.rs +++ b/lapon-tui/src/run.rs @@ -30,10 +30,18 @@ impl HostSection { } fn render(&self, area: Rect, buf: &mut Buffer) { + let area = Rect::new( + area.left() + 1, + area.top() + 1, + area.width.saturating_sub(2), + area.height.saturating_sub(2), + ); + let mut y = 0; for action in &self.actions { action.render(area, buf, &mut y, self.scroll); + y += 1; if y >= area.height + self.scroll { break; } @@ -130,6 +138,7 @@ impl ActionSection { Color::Gray }; self.render_line(area, buf, y, scroll, &self.name, None, Some(bg)); + *y += 1; if self.folded { return; } diff --git a/lapon/src/run.rs b/lapon/src/run.rs index 997490d..7a466d9 100644 --- a/lapon/src/run.rs +++ b/lapon/src/run.rs @@ -130,8 +130,8 @@ impl Run { let all_actions = all_actions(); for action_data in &self.actions { - let Some(_) = all_actions.get(&action_data.name) else { - return Err(anyhow!("action {} can't be found", action_data.name)); + let Some(_) = all_actions.get(&action_data.action) else { + return Err(anyhow!("action {} can't be found", action_data.action)); }; for (tx, _) in &senders { tx.send(NodeMessage::Action(action_data.clone()))?;