Implement status window to resolve #2
A status window to tell the user the next steps. Right now only provides warnings about missing intention and invalid session duration.
This commit is contained in:
48
src/main.rs
48
src/main.rs
@@ -57,7 +57,7 @@ impl App {
|
||||
App {
|
||||
state: State::InputIntention,
|
||||
user_intention: String::new(),
|
||||
user_duration_str: String::new(),
|
||||
user_duration_str: "25".to_string(),
|
||||
user_duration: Duration::new(0, 0),
|
||||
current_window_title: window_title.into(),
|
||||
current_window_time: Instant::now(),
|
||||
@@ -81,12 +81,9 @@ impl App {
|
||||
}
|
||||
|
||||
fn to_in_progress(&mut self) {
|
||||
let Ok(user_duration) = self.user_duration_str.parse::<u64>() else {
|
||||
// TODO: Print error to the user
|
||||
if self.user_intention.len() == 0 || self.user_duration == Duration::ZERO {
|
||||
return;
|
||||
};
|
||||
|
||||
self.user_duration = Duration::from_secs(user_duration * 60);
|
||||
}
|
||||
self.state = State::InProgress;
|
||||
self.current_window_time = Instant::now();
|
||||
self.session_start = self.current_window_time;
|
||||
@@ -103,6 +100,12 @@ impl App {
|
||||
fn tick_50ms(&mut self) {
|
||||
match self.state {
|
||||
State::InputIntention | State::InputDuration => {
|
||||
if let Ok(user_duration_mins) = self.user_duration_str.parse::<u64>() {
|
||||
self.user_duration = Duration::from_secs(user_duration_mins * 60);
|
||||
} else {
|
||||
self.user_duration = Duration::ZERO;
|
||||
}
|
||||
|
||||
window::minimize_other("AntiDrift");
|
||||
}
|
||||
State::InProgress => {
|
||||
@@ -115,7 +118,9 @@ impl App {
|
||||
}
|
||||
}
|
||||
State::ShouldQuit => {}
|
||||
State::End => {}
|
||||
State::End => {
|
||||
window::minimize_other("AntiDrift");
|
||||
}
|
||||
}
|
||||
|
||||
self.last_tick_50ms = Instant::now();
|
||||
@@ -293,15 +298,16 @@ fn ui(frame: &mut Frame, app: &App) {
|
||||
Constraint::Min(3),
|
||||
Constraint::Min(3),
|
||||
Constraint::Percentage(100),
|
||||
Constraint::Min(3),
|
||||
]);
|
||||
let [layout_intention, layout_duration, layout_titles] = layout.areas(frame.size());
|
||||
let [layout_intention, layout_duration, layout_titles, layout_status] = layout.areas(frame.size());
|
||||
|
||||
let border_type_intention = if app.state == State::InputIntention {
|
||||
BorderType::Thick
|
||||
} else {
|
||||
BorderType::Plain
|
||||
};
|
||||
let input_intention: Vec<Line> = vec![Line::from(Span::raw(&app.user_intention))];
|
||||
let input_intention = Line::from(Span::raw(&app.user_intention));
|
||||
frame.render_widget(
|
||||
Paragraph::new(input_intention).block(
|
||||
Block::bordered()
|
||||
@@ -336,4 +342,28 @@ fn ui(frame: &mut Frame, app: &App) {
|
||||
Paragraph::new(stats).block(Block::bordered().title("Session")),
|
||||
layout_titles,
|
||||
);
|
||||
|
||||
let mut spans: Vec<Span> = Vec::new();
|
||||
if app.user_intention.len() == 0 {
|
||||
let span = Span::styled("Provide intention! ", Style::new().fg(Color::LightRed));
|
||||
spans.push(span);
|
||||
}
|
||||
|
||||
if app.user_duration == Duration::ZERO {
|
||||
let span = Span::styled("Provide valid duration in minutes! ", Style::new().fg(Color::LightRed));
|
||||
spans.push(span);
|
||||
}
|
||||
|
||||
if app.state == State::InProgress {
|
||||
let span = Span::styled("Session In-Progress", Style::new().fg(Color::LightGreen));
|
||||
spans.push(span);
|
||||
}
|
||||
|
||||
let input_status: Vec<Line> = vec![Line::from(spans)];
|
||||
frame.render_widget(
|
||||
Paragraph::new(input_status).block(
|
||||
Block::bordered().title("Status"),
|
||||
),
|
||||
layout_status,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user