forked from janek/mostr
1
0
Fork 0

Display nested tasks in prompt

This commit is contained in:
xeruf 2024-07-18 00:38:27 +03:00
parent 660f9a248c
commit a0c46b6ea1
1 changed files with 9 additions and 1 deletions

View File

@ -92,7 +92,15 @@ async fn repl() {
let mut tasks: HashMap<EventId, Task> = HashMap::new();
let mut position: Option<EventId> = None;
loop {
print!(" {}> ", position.map_or(String::from(""), |id| tasks.get(&id).map_or(id.to_string(), |t| t.event.content.clone())));
let mut prompt = String::from("");
let mut pos = position;
while pos.is_some() {
let id = pos.unwrap();
let task = tasks.get(&id);
prompt = task.map_or(id.to_string(), |t| t.event.content.clone()) + " " + &prompt;
pos = task.and_then(|t| t.parent_id());
}
print!(" {}> ", prompt);
stdout().flush().unwrap();
match stdin().lines().next() {
Some(Ok(input)) => {