feat: hide Tasks attributes for feedback logs and make column interaction 1-indexed

This commit is contained in:
xeruf 2024-08-07 00:06:09 +03:00
parent b66089fc94
commit 6932e1f257
3 changed files with 44 additions and 24 deletions

View File

@ -99,7 +99,7 @@ when the application is terminated regularly.
Dots can be repeated to move to parent tasks.
- `:[IND][COL]` - add property column COL at IND or end, if it already exists remove property column COL or IND
- `:[IND][COL]` - add property column COL at IND or end, if it already exists remove property column COL or IND (1-indexed)
- `*[TIME]` - add timetracking with the specified offset
- `>[TEXT]` - complete active task and move to parent, with optional state description
- `<[TEXT]` - close active task and move to parent, with optional state description

View File

@ -252,18 +252,14 @@ async fn main() {
Some(':') => match iter.next().and_then(|s| s.to_digit(10)) {
Some(digit) => {
let index = digit as usize;
let index = (digit as usize).saturating_sub(1);
let remaining = iter.collect::<String>().trim().to_string();
if remaining.is_empty() {
tasks.properties.remove(index);
tasks.remove_column(index);
continue;
}
let value = input[2..].trim().to_string();
if tasks.properties.get(index) == Some(&value) {
tasks.properties.remove(index);
} else {
tasks.properties.insert(index, value);
}
tasks.add_or_remove_property_column_at_index(value, index);
}
None => {
if arg.is_empty() {
@ -284,15 +280,7 @@ async fn main() {
- `subtasks` - how many direct subtasks are complete");
continue;
}
let pos = tasks.properties.iter().position(|s| s == arg);
match pos {
None => {
tasks.properties.push(arg.to_string());
}
Some(i) => {
tasks.properties.remove(i);
}
}
tasks.add_or_remove_property_column(arg);
}
},
@ -363,7 +351,7 @@ async fn main() {
}
if let Ok(depth) = slice.parse::<i8>() {
tasks.move_to(pos);
tasks.depth = depth;
tasks.set_depth(depth);
} else {
tasks.filter_or_create(slice).map(|id| tasks.move_to(Some(id)));
}
@ -383,7 +371,7 @@ async fn main() {
}
if let Ok(depth) = slice.parse::<i8>() {
tasks.move_to(pos);
tasks.depth = depth;
tasks.set_depth(depth);
} else {
let filtered = tasks
.children_of(pos)

View File

@ -23,11 +23,11 @@ pub(crate) struct Tasks {
/// History of active tasks by PubKey
history: HashMap<PublicKey, BTreeSet<Event>>,
/// The task properties currently visible
pub(crate) properties: Vec<String>,
properties: Vec<String>,
/// Negative: Only Leaf nodes
/// Zero: Only Active node
/// Positive: Go down the respective level
pub(crate) depth: i8,
depth: i8,
/// Currently active task
position: Option<EventId>,
@ -62,9 +62,7 @@ impl Tasks {
sender,
}
}
}
impl Tasks {
// Accessors
#[inline]
@ -183,7 +181,7 @@ impl Tasks {
.unwrap_or(String::new())
}
pub(crate) fn traverse_up_from(&self, id: Option<EventId>) -> ParentIterator {
fn traverse_up_from(&self, id: Option<EventId>) -> ParentIterator {
ParentIterator {
tasks: &self.tasks,
current: id,
@ -593,6 +591,40 @@ impl Tasks {
}
}
}
// Properties
pub(crate) fn set_depth(&mut self, depth: i8) {
self.depth = depth;
info!("Changed view depth to {depth}");
}
pub(crate) fn remove_column(&mut self, index: usize) {
let col = self.properties.remove(index);
info!("Removed property column \"{col}\"");
}
pub(crate) fn add_or_remove_property_column(&mut self, property: &str) {
match self.properties.iter().position(|s| s == property) {
None => {
self.properties.push(property.to_string());
info!("Added property column \"{property}\"");
}
Some(index) => {
self.properties.remove(index);
}
}
}
pub(crate) fn add_or_remove_property_column_at_index(&mut self, property: String, index: usize) {
if self.properties.get(index) == Some(&property) {
self.properties.remove(index);
} else {
info!("Added property column \"{property}\" at position {}", index + 1);
self.properties.insert(index, property);
}
}
}
/// Formats the given seconds according to the given format.