Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ $ linetasker new "Finish writing unit tests" -p 5 --tags urgent --tags productio
```shell
$ linetasker list
```
![Alt text](assets/list.png)
![List view](https://raw.githubusercontent.com/anthonyraf/linetasker/main/assets/list.png)
### II.2 - Filtering

```shell
$ linetasker list -n 9 -t production
```
> `-n`: number of the tasks to display from the top
> `-t`: filter by tags
![Alt text](assets/list_filtered.png)
![Filtered list view](https://raw.githubusercontent.com/anthonyraf/linetasker/main/assets/list_filtered.png)

## III - Mark as done
```shell
Expand Down
12 changes: 11 additions & 1 deletion linetasker/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,17 @@ def list_tasks(self, n: int | None = None, _filter: Filter = None):
for i in range(n):
task_list.add_rows(TaskTemplate(**self.db_dict["tasks"][i]))

console.print(task_list.render())
# Check if any tasks were added to the list
if count == 0 and _filter:
console.print(
"[yellow]No tasks found matching the specified criteria.[/yellow]"
)
elif n == 0:
console.print(
"[blue]No tasks found. Create a new task with 'linetasker new \"<task_description>\"'[/blue]"
)
else:
console.print(task_list.render())

def get_done_tasks_ids(self) -> list[int]:
"""Return a list of the id of all done tasks"""
Expand Down
14 changes: 14 additions & 0 deletions tests/.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"tasks": [
0,
1,
2,
3,
4,
5,
6,
7,
8,
9
]
}
24 changes: 24 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,27 @@ def filename(cls):

def test_register_is_created(self, register: Register):
assert isinstance(register, Register)

def test_list_tasks_empty_shows_message(self, register: Register, capsys):
"""Test that listing tasks with no tasks shows a default message"""
register.list_tasks()
captured = capsys.readouterr()

# Should show a message instead of an empty table
assert "No tasks found" in captured.out
assert "Create a new task" in captured.out

def test_list_tasks_with_filter_no_matches_shows_message(self, register: Register, capsys):
"""Test that listing tasks with filter that matches nothing shows a message"""
from linetasker.utils.filter import Filter

# Add a task first
register.create_task("Test task", 1, ["test"])

# Filter by a tag that doesn't exist
_filter = Filter(tags=["nonexistent"])
register.list_tasks(_filter=_filter)
captured = capsys.readouterr()

# Should show a message instead of an empty table
assert "No tasks found matching the specified criteria" in captured.out