Skip to content

Commit aa85882

Browse files
committed
feat: add pausing and unpausing states
Signed-off-by: Rustin170506 <[email protected]>
1 parent efe9bbe commit aa85882

File tree

2 files changed

+53
-6
lines changed

2 files changed

+53
-6
lines changed

tokio-console/src/main.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use color_eyre::{eyre::eyre, Help, SectionExt};
22
use console_api::tasks::TaskDetails;
3-
use state::State;
3+
use state::{State, Temporality};
44

55
use futures::stream::StreamExt;
66
use ratatui::{
@@ -95,8 +95,10 @@ async fn main() -> color_eyre::Result<()> {
9595
if input::is_space(&input) {
9696
if state.is_paused() {
9797
conn.resume().await;
98+
state.start_unpausing();
9899
} else {
99100
conn.pause().await;
101+
state.start_pausing();
100102
}
101103
}
102104

@@ -153,8 +155,17 @@ async fn main() -> color_eyre::Result<()> {
153155
.split(f.size());
154156

155157
let mut header_text = conn.render(&view.styles);
156-
if state.is_paused() {
157-
header_text.push_span(Span::styled(" PAUSED", view.styles.fg(Color::Red)));
158+
match state.temporality() {
159+
Temporality::Paused => {
160+
header_text.push_span(Span::styled(" PAUSED", view.styles.fg(Color::Red)));
161+
}
162+
Temporality::Pausing => {
163+
header_text.push_span(Span::styled(" PAUSING", view.styles.fg(Color::Yellow)));
164+
}
165+
Temporality::Unpausing => {
166+
header_text.push_span(Span::styled(" UNPAUSING", view.styles.fg(Color::Green)));
167+
}
168+
Temporality::Live => {}
158169
}
159170
let dropped_async_ops_state = state.async_ops_state().dropped_events();
160171
let dropped_tasks_state = state.tasks_state().dropped_events();

tokio-console/src/state/mod.rs

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub(crate) type DetailsRef = Rc<RefCell<Option<Details>>>;
3434
pub(crate) struct State {
3535
metas: HashMap<u64, Metadata>,
3636
last_updated_at: Option<SystemTime>,
37-
temporality: proto::instrument::Temporality,
37+
temporality: Temporality,
3838
tasks_state: TasksState,
3939
resources_state: ResourcesState,
4040
async_ops_state: AsyncOpsState,
@@ -71,6 +71,29 @@ pub(crate) enum FieldValue {
7171
Debug(String),
7272
}
7373

74+
#[derive(Debug)]
75+
pub(crate) enum Temporality {
76+
Unpausing,
77+
Live,
78+
Pausing,
79+
Paused,
80+
}
81+
82+
impl Default for Temporality {
83+
fn default() -> Self {
84+
Self::Live
85+
}
86+
}
87+
88+
impl From<proto::instrument::Temporality> for Temporality {
89+
fn from(pb: proto::instrument::Temporality) -> Self {
90+
match pb {
91+
proto::instrument::Temporality::Live => Self::Live,
92+
proto::instrument::Temporality::Paused => Self::Paused,
93+
}
94+
}
95+
}
96+
7497
#[derive(Debug, Eq, PartialEq)]
7598
pub(crate) struct Attribute {
7699
field: Field,
@@ -230,13 +253,26 @@ impl State {
230253
}
231254

232255
// temporality methods
256+
pub(crate) fn temporality(&self) -> &Temporality {
257+
&self.temporality
258+
}
259+
260+
pub(crate) fn start_unpausing(&mut self) {
261+
self.temporality = Temporality::Unpausing;
262+
}
263+
264+
pub(crate) fn start_pausing(&mut self) {
265+
self.temporality = Temporality::Pausing;
266+
}
233267

234268
pub(crate) fn update_state(&mut self, state: proto::instrument::State) {
235-
self.temporality = proto::instrument::Temporality::try_from(state.temporality).unwrap();
269+
self.temporality = proto::instrument::Temporality::try_from(state.temporality)
270+
.expect("invalid temporality")
271+
.into();
236272
}
237273

238274
pub(crate) fn is_paused(&self) -> bool {
239-
matches!(self.temporality, proto::instrument::Temporality::Paused)
275+
matches!(self.temporality, Temporality::Paused | Temporality::Pausing)
240276
}
241277
}
242278

0 commit comments

Comments
 (0)