-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathworkload_list.rs
More file actions
84 lines (80 loc) · 2.97 KB
/
workload_list.rs
File metadata and controls
84 lines (80 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
use tui_realm_stdlib::List;
use tuirealm::{
AttrValue, Attribute, Component, Event, MockComponent,
command::{Cmd, CmdResult, Direction, Position},
event::{Key, KeyEvent},
props::{Alignment, BorderType, Borders, Color, TableBuilder, TextSpan},
};
use crate::app::{
messages::Msg,
user_events::{CscsEvent, UserEvent},
};
#[derive(MockComponent)]
pub(crate) struct WorkloadList {
component: List,
}
impl Default for WorkloadList {
fn default() -> Self {
Self {
component: List::default()
.borders(
Borders::default()
.modifiers(BorderType::Rounded)
.color(Color::Yellow),
)
.title("Workloads", Alignment::Center)
.scroll(true)
.highlighted_color(Color::LightYellow)
.highlighted_str("-")
.rewind(true)
.step(4),
}
}
}
impl Component<Msg, UserEvent> for WorkloadList {
fn on(&mut self, ev: tuirealm::Event<UserEvent>) -> Option<Msg> {
let _ = match ev {
Event::Keyboard(KeyEvent {
code: Key::Down, ..
}) => self.perform(Cmd::Move(Direction::Down)),
Event::Keyboard(KeyEvent { code: Key::Up, .. }) => {
self.perform(Cmd::Move(Direction::Up))
}
Event::Keyboard(KeyEvent {
code: Key::PageDown,
..
}) => self.perform(Cmd::Scroll(Direction::Down)),
Event::Keyboard(KeyEvent {
code: Key::PageUp, ..
}) => self.perform(Cmd::Scroll(Direction::Up)),
Event::Keyboard(KeyEvent {
code: Key::Home, ..
}) => self.perform(Cmd::GoTo(Position::Begin)),
Event::Keyboard(KeyEvent { code: Key::End, .. }) => {
self.perform(Cmd::GoTo(Position::End))
}
Event::User(UserEvent::Cscs(CscsEvent::GotWorkloadData(data))) => {
if data.len() == 0 {
self.attr(Attribute::Content, AttrValue::Table(vec![]));
} else {
let mut table = TableBuilder::default();
for (idx, job) in data.iter().enumerate() {
if idx > 0 {
table.add_row();
}
table
.add_col(TextSpan::from(job.name.clone()).bold())
.add_col(TextSpan::from(" "))
.add_col(TextSpan::from(job.status.to_string()))
.add_col(TextSpan::from(" "))
.add_col(TextSpan::from(job.id.to_string()));
}
self.attr(Attribute::Content, AttrValue::Table(table.build()));
}
self.perform(Cmd::Change)
}
_ => CmdResult::None,
};
Some(Msg::None)
}
}