mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-25 08:47:18 +02:00
Add default report command line argument
This commit is contained in:
parent
73a3dca579
commit
00989a0eb5
4 changed files with 36 additions and 19 deletions
10
src/app.rs
10
src/app.rs
|
@ -199,10 +199,11 @@ pub struct TaskwarriorTuiApp {
|
|||
pub command_history_context: HistoryContext,
|
||||
pub completion_list: CompletionList,
|
||||
pub show_completion_pane: bool,
|
||||
pub report: String,
|
||||
}
|
||||
|
||||
impl TaskwarriorTuiApp {
|
||||
pub fn new() -> Result<Self> {
|
||||
pub fn new(report: &str) -> Result<Self> {
|
||||
let output = std::process::Command::new("task")
|
||||
.arg("rc.color=off")
|
||||
.arg("show")
|
||||
|
@ -224,7 +225,7 @@ impl TaskwarriorTuiApp {
|
|||
}
|
||||
|
||||
let data = String::from_utf8_lossy(&output.stdout);
|
||||
let c = Config::new(&data)?;
|
||||
let c = Config::new(&data, report)?;
|
||||
let kc = KeyConfig::new(&data)?;
|
||||
|
||||
let (w, h) = crossterm::terminal::size()?;
|
||||
|
@ -251,7 +252,7 @@ impl TaskwarriorTuiApp {
|
|||
task_details_scroll: 0,
|
||||
task_report_show_info: c.uda_task_report_show_info,
|
||||
config: c,
|
||||
task_report_table: TaskReportTable::new(&data)?,
|
||||
task_report_table: TaskReportTable::new(&data, report)?,
|
||||
calendar_year: Local::today().year(),
|
||||
help_popup: Help::new(),
|
||||
contexts: vec![],
|
||||
|
@ -263,6 +264,7 @@ impl TaskwarriorTuiApp {
|
|||
command_history_context: HistoryContext::new("command.history"),
|
||||
completion_list: CompletionList::with_items(vec![]),
|
||||
show_completion_pane: false,
|
||||
report: report.to_string(),
|
||||
};
|
||||
|
||||
for c in app.config.filter.chars() {
|
||||
|
@ -998,7 +1000,7 @@ impl TaskwarriorTuiApp {
|
|||
pub fn update(&mut self, force: bool) -> Result<()> {
|
||||
if force || self.dirty || self.tasks_changed_since(self.last_export)? {
|
||||
self.last_export = Some(std::time::SystemTime::now());
|
||||
self.task_report_table.export_headers(None)?;
|
||||
self.task_report_table.export_headers(None, &self.report)?;
|
||||
let _ = self.export_tasks();
|
||||
self.export_contexts()?;
|
||||
self.update_tags();
|
||||
|
|
|
@ -64,7 +64,7 @@ pub struct Config {
|
|||
}
|
||||
|
||||
impl Config {
|
||||
pub fn new(data: &str) -> Result<Self> {
|
||||
pub fn new(data: &str, report: &str) -> Result<Self> {
|
||||
let bool_collection = Self::get_bool_collection();
|
||||
|
||||
let enabled = true;
|
||||
|
@ -72,7 +72,7 @@ impl Config {
|
|||
let print_empty_columns = bool_collection.get("print_empty_columns").cloned().unwrap_or(false);
|
||||
|
||||
let color = Self::get_color_collection(data);
|
||||
let filter = Self::get_filter(data);
|
||||
let filter = Self::get_filter(data, report);
|
||||
let data_location = Self::get_data_location(data);
|
||||
let due = Self::get_due(data);
|
||||
let rule_precedence_color = Self::get_rule_precedence_color(data);
|
||||
|
@ -339,9 +339,9 @@ impl Config {
|
|||
data.split(',').map(|s| s.to_string()).collect::<Vec<_>>()
|
||||
}
|
||||
|
||||
fn get_filter(data: &str) -> String {
|
||||
let filter = Self::get_config("report.next.filter", data)
|
||||
.context("Unable to parse `task show report.next.filter`.")
|
||||
fn get_filter(data: &str, report: &str) -> String {
|
||||
let filter = Self::get_config(format!("report.{}.filter", report).as_str(), data)
|
||||
.context(format!("Unable to parse `task show report.{}.filter`.", report))
|
||||
.unwrap();
|
||||
format!("{} ", filter)
|
||||
}
|
||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -70,21 +70,30 @@ fn main() {
|
|||
.help("Sets a custom config file")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("report")
|
||||
.short("r")
|
||||
.long("report")
|
||||
.value_name("STRING")
|
||||
.help("Sets default report")
|
||||
.takes_value(true),
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
let config = matches.value_of("config").unwrap_or("~/.taskrc");
|
||||
task::block_on(tui_main(config)).expect(
|
||||
let report = matches.value_of("report").unwrap_or("next");
|
||||
task::block_on(tui_main(config, report)).expect(
|
||||
"[taskwarrior-tui error]. Please report as a github issue on https://github.com/kdheepak/taskwarrior-tui",
|
||||
);
|
||||
}
|
||||
|
||||
async fn tui_main(_config: &str) -> Result<()> {
|
||||
async fn tui_main(_config: &str, report: &str) -> Result<()> {
|
||||
panic::set_hook(Box::new(|panic_info| {
|
||||
destruct_terminal();
|
||||
better_panic::Settings::auto().create_panic_handler()(panic_info);
|
||||
}));
|
||||
|
||||
let maybeapp = TaskwarriorTuiApp::new();
|
||||
let maybeapp = TaskwarriorTuiApp::new(report);
|
||||
if maybeapp.is_err() {
|
||||
destruct_terminal();
|
||||
return Err(maybeapp.err().unwrap());
|
||||
|
|
|
@ -43,7 +43,7 @@ pub struct TaskReportTable {
|
|||
}
|
||||
|
||||
impl TaskReportTable {
|
||||
pub fn new(data: &str) -> Result<Self> {
|
||||
pub fn new(data: &str, report: &str) -> Result<Self> {
|
||||
let virtual_tags = vec![
|
||||
"PROJECT",
|
||||
"BLOCKED",
|
||||
|
@ -86,24 +86,27 @@ impl TaskReportTable {
|
|||
virtual_tags: virtual_tags.iter().map(|s| s.to_string()).collect::<Vec<_>>(),
|
||||
description_width: 100,
|
||||
};
|
||||
task_report_table.export_headers(Some(data))?;
|
||||
task_report_table.export_headers(Some(data), report)?;
|
||||
Ok(task_report_table)
|
||||
}
|
||||
|
||||
pub fn export_headers(&mut self, data: Option<&str>) -> Result<()> {
|
||||
pub fn export_headers(&mut self, data: Option<&str>, report: &str) -> Result<()> {
|
||||
self.columns = vec![];
|
||||
self.labels = vec![];
|
||||
|
||||
let data = match data {
|
||||
Some(s) => s.to_string(),
|
||||
None => {
|
||||
let output = Command::new("task").arg("show").arg("report.next.columns").output()?;
|
||||
let output = Command::new("task")
|
||||
.arg("show")
|
||||
.arg(format!("report.{}.columns", report))
|
||||
.output()?;
|
||||
String::from_utf8_lossy(&output.stdout).into_owned()
|
||||
}
|
||||
};
|
||||
|
||||
for line in data.split('\n') {
|
||||
if line.starts_with("report.next.columns") {
|
||||
if line.starts_with(format!("report.{}.columns", report).as_str()) {
|
||||
let column_names = line.split(' ').collect::<Vec<_>>()[1];
|
||||
for column in column_names.split(',') {
|
||||
self.columns.push(column.to_string());
|
||||
|
@ -111,11 +114,14 @@ impl TaskReportTable {
|
|||
}
|
||||
}
|
||||
|
||||
let output = Command::new("task").arg("show").arg("report.next.labels").output()?;
|
||||
let output = Command::new("task")
|
||||
.arg("show")
|
||||
.arg(format!("report.{}.labels", report))
|
||||
.output()?;
|
||||
let data = String::from_utf8_lossy(&output.stdout);
|
||||
|
||||
for line in data.split('\n') {
|
||||
if line.starts_with("report.next.labels") {
|
||||
if line.starts_with(format!("report.{}.labels", report).as_str()) {
|
||||
let label_names = line.split(' ').collect::<Vec<_>>()[1];
|
||||
for label in label_names.split(',') {
|
||||
self.labels.push(label.to_string());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue