diff --git a/src/list.rs b/src/list.rs index 7329d2b..ce809ef 100644 --- a/src/list.rs +++ b/src/list.rs @@ -8,7 +8,7 @@ use ratatui::{ backend::CrosstermBackend, layout::{Constraint, Rect}, style::{Style, Stylize}, - text::{Line, Span}, + text::Span, widgets::{Block, Borders, HighlightSpacing, Row, Table, TableState}, Terminal, }; @@ -17,7 +17,7 @@ use std::io; use crate::{exercise::Exercise, state::State}; fn table<'a>(state: &State, exercises: &'a [Exercise]) -> Table<'a> { - let header = Row::new(["State", "Name", "Path"]); + let header = Row::new(["Next", "State", "Name", "Path"]); let max_name_len = exercises .iter() @@ -26,6 +26,7 @@ fn table<'a>(state: &State, exercises: &'a [Exercise]) -> Table<'a> { .unwrap_or(4) as u16; let widths = [ + Constraint::Length(4), Constraint::Length(7), Constraint::Length(max_name_len), Constraint::Fill(1), @@ -34,14 +35,23 @@ fn table<'a>(state: &State, exercises: &'a [Exercise]) -> Table<'a> { let rows = exercises .iter() .zip(&state.progress) - .map(|(exercise, done)| { - let state = if *done { + .enumerate() + .map(|(ind, (exercise, done))| { + let exercise_state = if *done { "DONE".green() } else { "PENDING".yellow() }; + + let next = if ind == state.next_exercise_ind { + ">>>>".bold().red() + } else { + Span::default() + }; + Row::new([ - state, + next, + exercise_state, Span::raw(&exercise.name), Span::raw(exercise.path.to_string_lossy()), ]) diff --git a/src/state.rs b/src/state.rs index 60f6a37..f29dc13 100644 --- a/src/state.rs +++ b/src/state.rs @@ -6,6 +6,7 @@ use crate::exercise::Exercise; #[derive(Serialize, Deserialize)] pub struct State { + pub next_exercise_ind: usize, pub progress: Vec, } @@ -15,7 +16,7 @@ impl State { let slf: Self = serde_json::de::from_slice(&file_content).ok()?; - if slf.progress.len() != exercises.len() { + if slf.progress.len() != exercises.len() || slf.next_exercise_ind >= exercises.len() { return None; } @@ -24,6 +25,7 @@ impl State { pub fn read_or_default(exercises: &[Exercise]) -> Self { Self::read(exercises).unwrap_or_else(|| Self { + next_exercise_ind: 0, progress: vec![false; exercises.len()], }) }