VladimirMarkelov / ttdl

TTDL - Terminal Todo List Manager
MIT License
202 stars 17 forks source link

How To/Feature Request/Bug?: Ignore empty lines. #66

Closed TommyCox closed 1 year ago

TommyCox commented 1 year ago

Hello, just started using this tool and it's great. I've been using it in addition to other methods of editing my todo.txt file and noticed that empty lines (both \n and \r\n) are being interpreted as tasks. Not sure if this is intended behavior or a bug.

It would be nice to at least have the option to ignore empty lines. If it's already an option and I simply missed it, apologies in advance for my ignorance.

VladimirMarkelov commented 1 year ago

Hi, no, at this moment there is no way to ignore empty lines in todo.txt. I manage my todo.txt only with TTDL, so I did not ran into that issue 😄 Anyway, I agree that displaying empty lines does not make much sense - it only wastes the terminal space.

Here is a question that looks simple at the first time: should TTDL keep existing empty lines when modifying todo.txt?

If no, the solution would be simple. I do not think it takes much time.

If yes, more questions arise:

  1. What about numbering? E.g, we have a todo.txt with three lines:
open an issue about empty lines

pay credit card

When doing ttdl list, what we want to see as the output to a terminal:

Way A

1 open an issue about empty lines
3 pay credit card

or

Way B

1 open an issue about empty lines
2 pay credit card

?

The former case is easy to implement: just add an extra filter that always filters out empty todos. The latter needs some redesign of the library about numbering. Another question is: do we ever want to display empty lines? If yes, then the only former way makes sense. But then we have to introduce a command-line option to enable displaying empty lines.

  1. I guess, sooner or later one wants to remove empty lines because they pile up (unless one deletes them in an external application). What is the good way to do it? Add a command rm-empty? Add a command-line option like --rm-empty? An extra option looks better, especially in combination with the command archive or rm. e.g. ttdl rm --rm-empty or ttdl rm --empty also looks natural. In case of we choose Way B, we do not need any extra option, we can remove empty lines by their IDs (first, we needs to show empty lines that needs a new option - see the previous paragraph).
TommyCox commented 1 year ago

My initial instinct is that keeping existing empty lines should be the default behavior, but an option like autoremove_empty_lines should exist and be fairly easy to implement.

As far as the subsequent questions:

  1. Way B definitely seems more natural, although it is more complex to implement as you stated. I can't immediately think of a use case for displaying empty lines. How is the numbering implemented? Could you drop a link to the file(s) and line(s) where it lives right now?
  2. This is a good point I didn't consider. I agree that ttdl rm --empty looks very natural. Additionally, maybe adding a configuration option archive_removes_empty and ttdl archive --preserve-empty or ttdl archive --keep-empty (assuming archive_removes_empty defaults to enabled).
VladimirMarkelov commented 1 year ago

How is the numbering implemented?

At this moment the numbering is dead simple: the file is loaded into a vector and then the ID of a todo is both 1) its index in the vector 2) its line number in the file . It has some advantage(though, I am not sure if anyone uses it): when you see ID in ttdl list output, you can open todo.txt in any editor and go to the corresponding line easily. Another advantage of the way A is that all the commands like rm or edit uses simple vector index. In the way B, if we want to keep empty lines after modifying a todo list, every todo item must have its "user-defined" ID and every command must do extra conversion between "user ID"(that is displayed in the screen) and internal ID(that is just the index of a line in the file).

VladimirMarkelov commented 1 year ago

As of numbering. I still think that ttdl list -a should show all lines including empty ones. Otherwise, a user has no way to get to know that the file contains empty lines. In this case, only way A numbering makes sense.

TommyCox commented 1 year ago

Yes, that would simplify things as well and prevent possible incompatibilities with plugins if one were to rely on todo ID and line number matching.

VladimirMarkelov commented 1 year ago

OK. It sounds like a plan: I can start working on hiding empty lines by default and displaying them with -a command-line flag. --archive removes empty lines by deafult, and --keep-empty flag preserves the empty lines. Maybe, I'll ad also a flag --empty-lines to rm command to just tidy up todo.txt and remove empty stuff. Does it sounds good to you?