Skip to content

Commit

Permalink
use action name
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhou121 committed Apr 5, 2024
1 parent a851f70 commit 8a182c1
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 49 deletions.
1 change: 1 addition & 0 deletions lapon-common/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub enum ActionMessage {
pub struct ActionData {
pub id: ActionId,
pub name: String,
pub action: String,
pub input: Vec<u8>,
}

Expand Down
12 changes: 11 additions & 1 deletion lapon-node/src/action/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ pub fn parse_value(cwd: &Path, value: &Value) -> Result<Vec<ActionData>> {
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"));
Expand All @@ -62,7 +71,8 @@ pub fn parse_value(cwd: &Path, value: &Value) -> Result<Vec<ActionData>> {
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,
});
}
Expand Down
4 changes: 2 additions & 2 deletions lapon-node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ fn node_run_action(
data: &ActionData,
tx: &Sender<ActionMessage>,
) -> Result<String> {
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)
}
56 changes: 12 additions & 44 deletions lapon-tui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
"<Left>".into(),
" Increment ".into(),
"<Right>".into(),
" Quit ".into(),
"<Q> ".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);
}
}
9 changes: 9 additions & 0 deletions lapon-tui/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions lapon/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))?;
Expand Down

0 comments on commit 8a182c1

Please sign in to comment.