Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing Final New Line in todo.txt #730

Closed
nikbucher opened this issue Aug 23, 2024 · 5 comments
Closed

Missing Final New Line in todo.txt #730

nikbucher opened this issue Aug 23, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@nikbucher
Copy link

The current implementation does not append a final newline character when saving the todo.txt file. This behavior causes issues with the standard todo.txt CLI, which expects a final newline in the todo.txt file. As a result, a new task added by the CLI are appended to the last task instead of being placed on a new line.

Steps to Reproduce:

  1. Save a todo.txt file using the current implementation.
  2. Add a new task using the standard todo.txt CLI.
  3. Notice that the new task is appended to the last task instead of being placed on a new line.

Expected Behavior:
A final newline character is added when the todo.txt file is saved, ensuring compatibility with the standard todo.txt CLI.

Suggested Fix:
Modify the writeToFile method to ensure that a final newline character is added when writing the todo.txt file here:

function writeToFile(string: string, filePath: string, bookmark: string | null) {
const stopAccessingSecurityScopedResource = (process.mas && bookmark) ? app.startAccessingSecurityScopedResource(bookmark) : null;
fs.writeFileSync(filePath, string, 'utf-8');

That would be great. Thanks a lot in advance.

Best regards - Nik

@github-project-automation github-project-automation bot moved this to Backlog in sleek 2.x Aug 23, 2024
@ransome1 ransome1 added the bug Something isn't working label Jan 15, 2025
@ransome1 ransome1 moved this from Backlog to Bugs in sleek 2.x Jan 15, 2025
@ransome1
Copy link
Owner

ransome1 commented Mar 3, 2025

@nikbucher this should technically not be a big issue. I can add this in the next (pre-)release. However, why do you consider it a bug? It's not a todo.txt rule, if I am not mistaken. The todo.txt CLI is one of many todo.txt apps and I don't actually see a good reason why it would expect an empty line at the end of the file. Or am I not seeing something here?

@nikbucher
Copy link
Author

Hi @ransome1, thanks for your response!

You're right that it's not an explicitly stated rule. However, the sample file on todotxt.org includes a final newline, and the official todo.txt CLI expects it, suggesting it might be an unofficial convention.

Here are also a few technical reasons why adding a final newline to text files can be a good idea:

  • POSIX Compliance: Unix-based systems (Linux/macOS) follow the POSIX standard, which considers a text file as a sequence of lines, each ending with a newline. Some tools behave unexpectedly if the last line is missing one.
  • CLI Tools Behavior: Utilities like sed, awk, and grep assume each line is newline-terminated. Without it, certain operations might not work as intended.
  • Text Editors: Editors like Vim often add a final newline automatically to maintain consistency with Unix conventions.
  • Consistency with todo.txt CLI: Since the CLI expects a newline at the end, not having one causes issues like I mentioned in the initial ticket description.

Adding a final newline would improve compatibility and prevent unexpected behavior when switching between sleek and the CLI.

Hope this helps. Thanks a lot for the awesome sleek tool!

Best regards - Nik

@ransome1
Copy link
Owner

ransome1 commented Mar 5, 2025

@nikbucher I added this behavior to the latest RC: https://github.com/ransome1/sleek/releases/tag/v2.0.19-rc.4

I hope it does not create any unexpected side effects. Let me know if it works as expected.

@ransome1
Copy link
Owner

ransome1 commented Mar 6, 2025

Released as part of 2.0.19: https://github.com/ransome1/sleek/releases/tag/v2.0.19

@ransome1 ransome1 closed this as completed Mar 6, 2025
@github-project-automation github-project-automation bot moved this from Bugs to Done in sleek 2.x Mar 6, 2025
@nikbucher
Copy link
Author

Thanks alot - it works great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

No branches or pull requests

2 participants