mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-25 08:47:18 +02:00
WIP
This commit is contained in:
parent
8302c8839e
commit
c02a3fd630
2 changed files with 26 additions and 112 deletions
|
@ -410,9 +410,12 @@ impl TaskReport {
|
||||||
if output.status.success() {
|
if output.status.success() {
|
||||||
let imported = import(data.as_bytes());
|
let imported = import(data.as_bytes());
|
||||||
if imported.is_ok() {
|
if imported.is_ok() {
|
||||||
|
let highlight_first_element = if self.tasks.is_empty() { true } else { false };
|
||||||
self.tasks = imported?;
|
self.tasks = imported?;
|
||||||
log::debug!("Imported {} tasks", self.tasks.len());
|
log::debug!("Imported {} tasks", self.tasks.len());
|
||||||
self.send_action(Action::ShowTaskReport)?;
|
if highlight_first_element {
|
||||||
|
self.state.select(Some(0));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
imported?;
|
imported?;
|
||||||
}
|
}
|
||||||
|
@ -513,23 +516,23 @@ impl TaskReport {
|
||||||
for tag_name in virtual_tag_names_in_precedence.iter().rev() {
|
for tag_name in virtual_tag_names_in_precedence.iter().rev() {
|
||||||
if tag_name == "uda." || tag_name == "priority" {
|
if tag_name == "uda." || tag_name == "priority" {
|
||||||
if let Some(p) = task.priority() {
|
if let Some(p) = task.priority() {
|
||||||
let s = self.config.taskwarrior.color.uda_priority.get(p).copied().unwrap_or_default();
|
let s = self.config.taskwarrior.color.get(&format!("color.priority.{p}")).copied().unwrap_or_default();
|
||||||
style = style.patch(s);
|
style = style.patch(s);
|
||||||
}
|
}
|
||||||
} else if tag_name == "tag." {
|
} else if tag_name == "tag." {
|
||||||
if let Some(tags) = task.tags() {
|
if let Some(tags) = task.tags() {
|
||||||
for t in tags {
|
for t in tags {
|
||||||
let s = self.config.taskwarrior.color.tag.get(t).copied().unwrap_or_default();
|
let s = self.config.taskwarrior.color.get(&format!("color.tag.{t}")).copied().unwrap_or_default();
|
||||||
style = style.patch(s);
|
style = style.patch(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if tag_name == "project." {
|
} else if tag_name == "project." {
|
||||||
if let Some(p) = task.project() {
|
if let Some(p) = task.project() {
|
||||||
let s = self.config.taskwarrior.color.project.get(p).copied().unwrap_or_default();
|
let s = self.config.taskwarrior.color.get(&format!("color.project.{p}")).copied().unwrap_or_default();
|
||||||
style = style.patch(s);
|
style = style.patch(s);
|
||||||
}
|
}
|
||||||
} else if task.tags().unwrap_or(&vec![]).contains(&tag_name.to_string().replace('.', "").to_uppercase()) {
|
} else if task.tags().unwrap_or(&vec![]).contains(&tag_name.to_string().replace('.', "").to_uppercase()) {
|
||||||
let s = self.config.taskwarrior.color.tag.get(tag_name).copied().unwrap_or_default();
|
let s = self.config.taskwarrior.color.get(&format!("color.{tag_name}")).copied().unwrap_or_default();
|
||||||
style = style.patch(s);
|
style = style.patch(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -573,7 +576,7 @@ impl Component for TaskReport {
|
||||||
let constraints: Vec<Constraint> = widths.iter().map(|i| Constraint::Min(*i as u16)).collect();
|
let constraints: Vec<Constraint> = widths.iter().map(|i| Constraint::Min(*i as u16)).collect();
|
||||||
let rows = self.rows.iter().enumerate().map(|(i, row)| {
|
let rows = self.rows.iter().enumerate().map(|(i, row)| {
|
||||||
let style = self.style_for_task(&self.tasks[i]);
|
let style = self.style_for_task(&self.tasks[i]);
|
||||||
Row::new(row.clone())
|
Row::new(row.clone()).style(style)
|
||||||
});
|
});
|
||||||
let table = Table::new(rows)
|
let table = Table::new(rows)
|
||||||
.header(Row::new(self.labels.iter().map(|l| Cell::from(l.clone()).underlined())))
|
.header(Row::new(self.labels.iter().map(|l| Cell::from(l.clone()).underlined())))
|
||||||
|
|
123
src/config.rs
123
src/config.rs
|
@ -13,59 +13,6 @@ use crate::{action::Action, app::Mode};
|
||||||
|
|
||||||
const CONFIG: &str = include_str!("../.config/config.json5");
|
const CONFIG: &str = include_str!("../.config/config.json5");
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
|
|
||||||
pub struct TaskwarriorColorConfig {
|
|
||||||
pub active: Style,
|
|
||||||
pub alternate: Style,
|
|
||||||
pub blocked: Style,
|
|
||||||
pub blocking: Style,
|
|
||||||
pub burndown_done: Style,
|
|
||||||
pub burndown_pending: Style,
|
|
||||||
pub burndown_started: Style,
|
|
||||||
pub calendar_due: Style,
|
|
||||||
pub calendar_due_today: Style,
|
|
||||||
pub calendar_holiday: Style,
|
|
||||||
pub calendar_overdue: Style,
|
|
||||||
pub calendar_scheduled: Style,
|
|
||||||
pub calendar_today: Style,
|
|
||||||
pub calendar_weekend: Style,
|
|
||||||
pub calendar_weeknumber: Style,
|
|
||||||
pub completed: Style,
|
|
||||||
pub debug: Style,
|
|
||||||
pub deleted: Style,
|
|
||||||
pub due: Style,
|
|
||||||
pub due_today: Style,
|
|
||||||
pub error: Style,
|
|
||||||
pub footnote: Style,
|
|
||||||
pub header: Style,
|
|
||||||
pub history_add: Style,
|
|
||||||
pub history_delete: Style,
|
|
||||||
pub history_done: Style,
|
|
||||||
pub label: Style,
|
|
||||||
pub label_sort: Style,
|
|
||||||
pub overdue: Style,
|
|
||||||
pub project_basics: Style,
|
|
||||||
pub project_none: Style,
|
|
||||||
pub project_wth: Style,
|
|
||||||
pub recurring: Style,
|
|
||||||
pub scheduled: Style,
|
|
||||||
pub summary_background: Style,
|
|
||||||
pub summary_bar: Style,
|
|
||||||
pub sync_added: Style,
|
|
||||||
pub sync_changed: Style,
|
|
||||||
pub sync_rejected: Style,
|
|
||||||
pub tag_next: Style,
|
|
||||||
pub tag_none: Style,
|
|
||||||
pub tagged: Style,
|
|
||||||
pub uda_priority: HashMap<String, Style>,
|
|
||||||
pub tag: HashMap<String, Style>,
|
|
||||||
pub project: HashMap<String, Style>,
|
|
||||||
pub undo_after: Style,
|
|
||||||
pub undo_before: Style,
|
|
||||||
pub until: Style,
|
|
||||||
pub warning: Style,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
|
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
|
||||||
pub struct TaskwarriorConfig {
|
pub struct TaskwarriorConfig {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
|
@ -77,7 +24,7 @@ pub struct TaskwarriorConfig {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub due: usize,
|
pub due: usize,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub color: TaskwarriorColorConfig,
|
pub color: HashMap<String, Style>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub data_location: String,
|
pub data_location: String,
|
||||||
}
|
}
|
||||||
|
@ -209,61 +156,25 @@ impl Config {
|
||||||
self.weekstart(&data);
|
self.weekstart(&data);
|
||||||
self.due(&data);
|
self.due(&data);
|
||||||
self.data_location(&data);
|
self.data_location(&data);
|
||||||
|
self.color(&data);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn color(&mut self, data: &str) -> Result<()> {
|
fn color(&mut self, data: &str) {
|
||||||
self.taskwarrior.color.active = parse_style(&get_config("color.active", data)?);
|
let mut color = HashMap::new();
|
||||||
self.taskwarrior.color.alternate = parse_style(&get_config("color.alternate", data)?);
|
for line in data.split('\n') {
|
||||||
self.taskwarrior.color.blocked = parse_style(&get_config("color.blocked", data)?);
|
if line.starts_with("color.") {
|
||||||
self.taskwarrior.color.blocking = parse_style(&get_config("color.blocking", data)?);
|
let mut i = line.split(' ');
|
||||||
self.taskwarrior.color.burndown_done = parse_style(&get_config("color.burndown.done", data)?);
|
let attribute = i.next();
|
||||||
self.taskwarrior.color.burndown_pending = parse_style(&get_config("color.burndown.pending", data)?);
|
let line = i.collect::<Vec<_>>().join(" ");
|
||||||
self.taskwarrior.color.burndown_started = parse_style(&get_config("color.burndown.started", data)?);
|
let line = line.trim_start_matches(' ');
|
||||||
self.taskwarrior.color.calendar_due = parse_style(&get_config("color.calendar.due", data)?);
|
let style = parse_style(line);
|
||||||
self.taskwarrior.color.calendar_due_today = parse_style(&get_config("color.calendar.due.today", data)?);
|
if let Some(attr) = attribute {
|
||||||
self.taskwarrior.color.calendar_holiday = parse_style(&get_config("color.calendar.holiday", data)?);
|
color.insert(attr.to_string(), style);
|
||||||
self.taskwarrior.color.calendar_overdue = parse_style(&get_config("color.calendar.overdue", data)?);
|
};
|
||||||
self.taskwarrior.color.calendar_scheduled = parse_style(&get_config("color.calendar.scheduled", data)?);
|
}
|
||||||
self.taskwarrior.color.calendar_today = parse_style(&get_config("color.calendar.today", data)?);
|
}
|
||||||
self.taskwarrior.color.calendar_weekend = parse_style(&get_config("color.calendar.weekend", data)?);
|
self.taskwarrior.color = color;
|
||||||
self.taskwarrior.color.calendar_weeknumber = parse_style(&get_config("color.calendar.weeknumber", data)?);
|
|
||||||
self.taskwarrior.color.completed = parse_style(&get_config("color.completed", data)?);
|
|
||||||
self.taskwarrior.color.debug = parse_style(&get_config("color.debug", data)?);
|
|
||||||
self.taskwarrior.color.deleted = parse_style(&get_config("color.deleted", data)?);
|
|
||||||
self.taskwarrior.color.due = parse_style(&get_config("color.due", data)?);
|
|
||||||
self.taskwarrior.color.due_today = parse_style(&get_config("color.due.today", data)?);
|
|
||||||
self.taskwarrior.color.error = parse_style(&get_config("color.error", data)?);
|
|
||||||
self.taskwarrior.color.footnote = parse_style(&get_config("color.footnote", data)?);
|
|
||||||
self.taskwarrior.color.header = parse_style(&get_config("color.header", data)?);
|
|
||||||
self.taskwarrior.color.history_add = parse_style(&get_config("color.history.add", data)?);
|
|
||||||
self.taskwarrior.color.history_delete = parse_style(&get_config("color.history.delete", data)?);
|
|
||||||
self.taskwarrior.color.history_done = parse_style(&get_config("color.history.done", data)?);
|
|
||||||
self.taskwarrior.color.label = parse_style(&get_config("color.label", data)?);
|
|
||||||
self.taskwarrior.color.label_sort = parse_style(&get_config("color.label.sort", data)?);
|
|
||||||
self.taskwarrior.color.overdue = parse_style(&get_config("color.overdue", data)?);
|
|
||||||
self.taskwarrior.color.project_basics = parse_style(&get_config("color.project.basics", data)?);
|
|
||||||
self.taskwarrior.color.project_none = parse_style(&get_config("color.project.none", data)?);
|
|
||||||
self.taskwarrior.color.project_wth = parse_style(&get_config("color.project.wth", data)?);
|
|
||||||
self.taskwarrior.color.recurring = parse_style(&get_config("color.recurring", data)?);
|
|
||||||
self.taskwarrior.color.scheduled = parse_style(&get_config("color.scheduled", data)?);
|
|
||||||
self.taskwarrior.color.summary_background = parse_style(&get_config("color.summary.background", data)?);
|
|
||||||
self.taskwarrior.color.summary_bar = parse_style(&get_config("color.summary.bar", data)?);
|
|
||||||
self.taskwarrior.color.sync_added = parse_style(&get_config("color.sync.added", data)?);
|
|
||||||
self.taskwarrior.color.sync_changed = parse_style(&get_config("color.sync.changed", data)?);
|
|
||||||
self.taskwarrior.color.sync_rejected = parse_style(&get_config("color.sync.rejected", data)?);
|
|
||||||
self.taskwarrior.color.tag_next = parse_style(&get_config("color.tag.next", data)?);
|
|
||||||
self.taskwarrior.color.tag_none = parse_style(&get_config("color.tag.none", data)?);
|
|
||||||
self.taskwarrior.color.tagged = parse_style(&get_config("color.tagged", data)?);
|
|
||||||
self.taskwarrior.color.uda_priority.insert("H".into(), parse_style(&get_config("color.uda.priority.H", data)?));
|
|
||||||
self.taskwarrior.color.uda_priority.insert("L".into(), parse_style(&get_config("color.uda.priority.L", data)?));
|
|
||||||
self.taskwarrior.color.uda_priority.insert("M".into(), parse_style(&get_config("color.uda.priority.M", data)?));
|
|
||||||
self.taskwarrior.color.uda_priority.insert("U".into(), parse_style(&get_config("color.uda.priority.U", data)?));
|
|
||||||
self.taskwarrior.color.undo_after = parse_style(&get_config("color.undo.after", data)?);
|
|
||||||
self.taskwarrior.color.undo_before = parse_style(&get_config("color.undo.before", data)?);
|
|
||||||
self.taskwarrior.color.until = parse_style(&get_config("color.until", data)?);
|
|
||||||
self.taskwarrior.color.warning = parse_style(&get_config("color.warning", data)?);
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn data_location(&mut self, data: &str) {
|
fn data_location(&mut self, data: &str) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue