kdheepak / taskwarrior-tui

`taskwarrior-tui`: A terminal user interface for taskwarrior
https://kdheepak.com/taskwarrior-tui
MIT License
1.53k stars 70 forks source link

Context not working sometimes #556

Open adriangalilea opened 7 months ago

adriangalilea commented 7 months ago

Reproduction

$ task

ID  project             description                                                                                      tags p urg     
138 side-quest.e-id     redacted                                                                                                  0.5
117 side-quest.e-id.dev redacted                                                              0.5
118 side-quest.e-id.dev redacted                                   0.5
  2 side-quest.e-id     redacted                                                                       0.5
  8 side-quest.e-id     redacted L -0.00466

$ taskwarrior-tui

image

My context is side-quest could it be because of the "-"??

adriangalilea commented 6 months ago

I can guarantee that taskwarrior-tui doesn't interpret context as taskwarrior does, for instance:

context.default.read="(project.not:side-quest and tags.not:side-quest)" or urgency>5

Will work on taskwarrior-tui but fail on taskwarrior, and:

context.default.read=(project.not:side-quest and tags.not:side-quest) or urgency>5

Will work on taskwarrior but fail on taskwarrior-tui.

So I can either use one or the other, not both.

kdheepak commented 6 months ago

When you say it fails in taskwarrior-tui, does it error? Or does it just not display the correct tasks?

taskwarrior-tui calls task export as a subprocess (i.e. std::process::Command) and reads the json.

You can look at the log files of taskwarrior-tui to see the exact subprocess that is created and executed by taskwarrior-tui:

https://github.com/kdheepak/taskwarrior-tui/blob/cfedca0ad1c765dfce46576a86f1bd19b6beaec8/src/app.rs#L1714

Maybe that'll help narrow down what is going on?

I'm assuming it has something to do with how the context string is spliced into the subprocess when tasks are exported:

https://github.com/kdheepak/taskwarrior-tui/blob/cfedca0ad1c765dfce46576a86f1bd19b6beaec8/src/app.rs#L1698-L1706

adriangalilea commented 6 months ago

logging

❯ export TASKWARRIOR_TUI_LOG_LEVEL=debug
❯ taskwarrior-tui

Does not show me any logs unless they are somewhere I'm unfamiliar with.

clarifying bug

When you say it fails in taskwarrior-tui, does it error? Or does it just not display the correct tasks?

I'm having some inconsistencies, over iterations(slightly modified context) I had 3 different results:

Using context.default.read=(project.not:side-quest and tags.not:side-quest) or urgency>5 as context tests:

task output

image

taskwarrior-tui output

image

Using context.default.read='(project.not:side-quest and tags.not:side-quest)' or urgency>5 as context tests:

task output

image

taskwarrior-tui output

image
TIAcode commented 3 months ago

I've ran into the same problem.

diff /.snapshots/home-20240822_060000/user/.taskrc ~/.taskrc
46c46
< context.main.read=((tag:birthday and due.before:now+1month) or (-birthday)) and ((tag:holiday and due.before:now+1week) or (-holiday)) and project.not:ddd
---
> context.main.read=((tag:birthday and due.before:now+1month) or (-birthday)) and ((tag:holiday and due.before:now+1week) or (-holiday)) and (project.not:ddd and project.not:wfc)

This small change made taskwarrior show only 'Task not found". Using the context with task works. The log is

2024-08-22 08:42:47 | INFO | src/app.rs:1723 | Running `Command {
    program: "task",
    args: [
        "task",
        "rc.json.array=on",
        "rc.confirmation=off",
        "rc.json.depends.array=on",
        "rc.color=off",
        "rc._forcecolor=off",
        "rc.report.next.filter=status:pending -WAITING",
        "((tag:birthday",
        "and",
        "due.before:now+1month)",
        "or",
        "(-birthday))",
        "and",
        "((tag:holiday",
        "and",
        "due.before:now+1week)",
        "or",
        "(-holiday))",
        "and",
        "(project.not:ddd",
        "and",
        "project.not:wfc)",
        "export",
        "next",
    ],
    create_pidfd: false,
}`

I don't know if it helps anything, but copying these for python's subprocess, the one given by taskwarrior-tui fails with Mismatched parentheses in expression, but if I combine the context filter to one argument, it works:

>>> x=[
...         "task",
...         "rc.json.array=on",
...         "rc.confirmation=off",
...         "rc.json.depends.array=on",
...         "rc.color=off",
...         "rc._forcecolor=off",
...         "rc.report.next.filter=status:pending -WAITING",
...         "((tag:birthday",
...         "and",
...         "due.before:now+1month)",
...         "or",
...         "(-birthday))",
...         "and",
...         "((tag:holiday",
...         "and",
...         "due.before:now+1week)",
...         "or",
...         "(-holiday))",
...         "and",
...         "(project.not:ddd",
...         "and",
...         "project.not:wfc)",
...         "export",
...         "next",
...     ]
>>> z=subprocess.run(x,capture_output=True)
>>> z
CompletedProcess(args=['task', 'rc.json.array=on', 'rc.confirmation=off', 'rc.json.depends.array=on', 'rc.color=off', 'rc._forcecolor=off', 'rc.report.next.filter=status:pending -WAITING', '((tag:birthday', 'and', 'due.before:now+1month)', 'or', '(-birthday))', 'and', '((tag:holiday', 'and', 'due.before:now+1week)', 'or', '(-holiday))', 'and', '(project.not:ddd', 'and', 'project.not:wfc)', 'export', 'next'], returncode=2, stdout=b'', stderr=b'Configuration override rc.json.array=on\nConfiguration override rc.confirmation=off\nConfiguration override rc.json.depends.array=on\nConfiguration override rc.color=off\nConfiguration override rc._forcecolor=off\nConfiguration override rc.report.next.filter=status:pending -WAITING\nMismatched parentheses in expression\n')
>>> x2=[
...         "task",
...         "rc.json.array=on",
...         "rc.confirmation=off",
...         "rc.json.depends.array=on",
...         "rc.color=off",
...         "rc._forcecolor=off",
...         "rc.report.next.filter=status:pending -WAITING",
...         "((tag:birthday " +
...         "and " +
...         "due.before:now+1month) " +
...         "or " +
...         "(-birthday)) " +
...         "and " +
...         "((tag:holiday " +
...         "and " +
...         "due.before:now+1week) " +
...         "or " +
...         "(-holiday)) " +
...         "and " +
...         "(project.not:ddd " +
...         "and " +
...         "project.not:wfc)",
...         "export",
...         "next",
...     ]
>>> z2=subprocess.run(x2,capture_output=True)
>>> z2
CompletedProcess(args=['task', 'rc.json.array=on', 'rc.confirmation=off', 'rc.json.depends.array=on', 'rc.color=off', 'rc._forcecolor=off', 'rc.report.next.filter=status:pending -WAITING', '((tag:birthday and due.before:now+1month) or (-birthday)) and ((tag:holiday and due.before:now+1week) or (-holiday)) and (project.not:ddd and project.not:wfc)', 'export', 'next'], returncode=0, stdout=b'[\n{"id":43,"description":.......(all the tasks)
TIAcode commented 3 months ago

Had time to test it

      //if let Some(args) = shlex::split(&self.current_context_filter) {
      //  for arg in args {
      //    task.arg(arg);
      //  }
      //}
      task.arg(self.current_context_filter.trim());

src/app.rs, I changed that starting from line 1694 and it seems to work.