Skip to content

Commit 216ce00

Browse files
author
kiran-garre
committed
feat: Cleaned up todo list UX and removed /todos show
Updates: - As tasks are completed, only the completed tasks and next task are shown - Full todo list is only displayed on creation and after finishign - /todos show was removed (view is enough)
1 parent 814a96a commit 216ce00

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

crates/chat-cli/src/cli/chat/cli/todos.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ use crate::os::Os;
1717

1818
#[derive(Debug, PartialEq, Subcommand)]
1919
pub enum TodoSubcommand {
20-
/// Show all tracked to-do lists
21-
Show,
2220

2321
/// Delete all completed to-do lists
2422
ClearFinished,
@@ -61,17 +59,6 @@ impl std::fmt::Display for TodoDisplayEntry {
6159
impl TodoSubcommand {
6260
pub async fn execute(self, os: &mut Os, session: &mut ChatSession) -> Result<ChatState, ChatError> {
6361
match self {
64-
Self::Show => match Self::get_descriptions_and_statuses(os) {
65-
Ok(entries) => {
66-
if entries.is_empty() {
67-
execute!(session.stderr, style::Print("No to-do lists to show!\n"),)?;
68-
}
69-
for e in entries {
70-
execute!(session.stderr, style::Print(e), style::Print("\n"),)?;
71-
}
72-
},
73-
Err(_) => return Err(ChatError::Custom("Could not show to-do lists".into())),
74-
},
7562
Self::ClearFinished => {
7663
let entries = match os.database.get_all_todos() {
7764
Ok(e) => e,

crates/chat-cli/src/cli/chat/tools/todo.rs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use eyre::{
1313
Result,
1414
bail,
1515
};
16+
1617
use serde::{
1718
Deserialize,
1819
Serialize,
@@ -152,6 +153,7 @@ impl TodoInput {
152153
let new_id = TodoState::generate_new_id();
153154
state.save(os, &new_id)?;
154155
TodoState::set_current_todo_id(os, &new_id)?;
156+
state.display_list(output)?;
155157
state
156158
},
157159
TodoInput::Complete {
@@ -175,11 +177,29 @@ impl TodoInput {
175177
state.modified_files.extend_from_slice(files);
176178
}
177179
state.save(os, &current_id)?;
180+
181+
let last_completed = completed_indices.iter().max().unwrap();
182+
if *last_completed == state.tasks.len() - 1 {
183+
// Display the whole list only at the end
184+
state.display_list(output)?;
185+
} else {
186+
// Display only completed tasks and next task
187+
let mut display_list= TodoState::default();
188+
display_list.tasks = completed_indices.iter().map(|i| state.tasks[*i].clone()).collect();
189+
display_list.tasks.push(state.tasks[*last_completed + 1].clone());
190+
for _ in 0..completed_indices.len() {
191+
display_list.completed.push(true);
192+
}
193+
display_list.completed.push(false);
194+
display_list.display_list(output)?;
195+
}
178196
state
179197
},
180198
TodoInput::Load { id } => {
181199
TodoState::set_current_todo_id(os, id)?;
182-
TodoState::load(os, id)?
200+
let state= TodoState::load(os, id)?;
201+
state.display_list(output)?;
202+
state
183203
},
184204
TodoInput::Add {
185205
new_tasks,
@@ -199,6 +219,7 @@ impl TodoInput {
199219
state.task_description = description.clone();
200220
}
201221
state.save(os, &current_id)?;
222+
state.display_list(output)?;
202223
state
203224
},
204225
TodoInput::Remove {
@@ -218,11 +239,11 @@ impl TodoInput {
218239
state.task_description = description.clone();
219240
}
220241
state.save(os, &current_id)?;
242+
state.display_list(output)?;
221243
state
222244
},
223245
};
224-
state.display_list(output)?;
225-
output.flush()?;
246+
226247

227248
Ok(InvokeOutput { output: super::OutputKind::Json(serde_json::to_value(state)?) })
228249
}
@@ -255,7 +276,9 @@ impl TodoInput {
255276
None => bail!("No todo list is currently loaded"),
256277
};
257278
let state = TodoState::load(os, &current_id)?;
258-
if completed_indices.iter().any(|i| *i >= state.completed.len()) {
279+
if completed_indices.is_empty() {
280+
bail!("At least one completed index must be provided");
281+
} else if completed_indices.iter().any(|i| *i >= state.completed.len()) {
259282
bail!("Completed index is out of bounds");
260283
} else if context_update.is_empty() {
261284
bail!("No context update was provided");

0 commit comments

Comments
 (0)