diff --git a/README.md b/README.md index a1043db..7ffee46 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ $ 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 @@ -28,7 +28,7 @@ $ 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 diff --git a/linetasker/core.py b/linetasker/core.py index 43c7ce8..260d298 100644 --- a/linetasker/core.py +++ b/linetasker/core.py @@ -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 \"\"'[/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""" diff --git a/tests/.test.json b/tests/.test.json new file mode 100644 index 0000000..6c1a210 --- /dev/null +++ b/tests/.test.json @@ -0,0 +1,14 @@ +{ + "tasks": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9 + ] +} \ No newline at end of file diff --git a/tests/test_core.py b/tests/test_core.py index bb48ec6..3aff8e9 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -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