xwmx / nb

CLI and local web plain text note‑taking, bookmarking, and archiving with linking, tagging, filtering, search, Git versioning & syncing, Pandoc conversion, + more, in a single portable script.
https://xwmx.github.io/nb
GNU Affero General Public License v3.0
6.43k stars 180 forks source link

Minor issue: nb sync UI updates broken, "homDone!" #269

Closed eblume closed 9 months ago

eblume commented 10 months ago

When I run nb sync, stdout receives streamed messages that include control characters for backspace, so that the text output appears to update in real time - a common pattern for net sync operations like this. However, it seems like something goes awry right away, as there is a brief flash of some sort of error message (far too brief to read), and then some of the UI seems to go 'stale' and it results in the final message shown on process exit as follows:

➜ nb sync
Syncing: homDone!

Is there a way to turn off the control characters briefly to see what error message was being displayed? This may help me trace it down.

eblume commented 10 months ago

I was able to get further with unbuffer nb sync > output.txt, which produces this output when viewed in vim (which renders control sequences in ASCII):

Syncing: (Bhome(B... (B[|](B        Done!

I don't know how well github's UI will preserve that output, so here it is in hex:

❯ xxd output.txt
00000000: 5379 6e63 696e 673a 201b 2842 1b5b 6d1b  Syncing: .(B.[m.
00000010: 5b33 383b 353b 3639 6d68 6f6d 651b 2842  [38;5;69mhome.(B
00000020: 1b5b 6d2e 2e2e 201b 2842 1b5b 6d1b 5b39  .[m... .(B.[m.[9
00000030: 306d 5b1b 5b33 383b 353b 3639 6d7c 1b5b  0m[.[38;5;69m|.[
00000040: 3930 6d5d 1b28 421b 5b6d 0808 0808 0808  90m].(B.[m......
00000050: 0808 2020 2020 2020 2020 0808 0808 0808  ..        ......
00000060: 0808 446f 6e65 210a                      ..Done!.
xwmx commented 10 months ago

@eblume Thanks for the information. nb sync --no-color will skip the spinner. Let me know if that works for you.

I noticed that the spinner behavior differed from what was intended and just pushed an update with improved behavior, which I hope to include in a patch release soon.

eblume commented 10 months ago

Hmm, I'm not sure if it's fixed or not. Check this out, it's very interesting:

➜ unbuffer nb sync | hexyl
┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐
│00000000│ 53 79 6e 63 69 6e 67 3a ┊ 20 1b 28 42 1b 5b 6d 1b │Syncing:┊ •(B•[m•│
│00000010│ 5b 33 38 3b 35 3b 36 39 ┊ 6d 68 6f 6d 65 1b 28 42 │[38;5;69┊mhome•(B│
│00000020│ 1b 5b 6d 2e 2e 2e 20 1b ┊ 28 42 1b 5b 6d 1b 5b 39 │•[m... •┊(B•[m•[9│
│00000030│ 30 6d 5b 1b 5b 33 38 3b ┊ 35 3b 36 39 6d 7c 1b 5b │0m[•[38;┊5;69m|•[│
│00000040│ 39 30 6d 5d 1b 28 42 1b ┊ 5b 6d 08 08 08 08 08 08 │90m]•(B•┊[m••••••│
│00000050│ 08 08 20 20 20 20 20 20 ┊ 20 20 08 08 08 08 08 08 │••      ┊  ••••••│
│00000060│ 08 08 44 6f 6e 65 21 0a ┊                         │••Done!_┊        │
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘

➜ unbuffer nb sync --no-color | hexyl
┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐
│00000000│ 53 79 6e 63 69 6e 67 3a ┊ 20 68 6f 6d 65 2e 2e 2e │Syncing:┊ home...│
│00000010│ 44 6f 6e 65 21 0a       ┊                         │Done!_  ┊        │
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘

Can you see it? It took me ages. In the no-color output, the three ellipses 2e 2e 2e are followed immediately by the message "Done!", but in the with-color output they are followed by a single space 2e 2e 2e 20.

In the --no-color output, there is no misspelling, but the space is missing and looks a bit off to me. Can I say it is "fixed"? Perhaps. Your call. It just really seems to me like there's an off-by-one error lurking in the math somewhere. Maybe your new throbber code will fix it, thanks very much for the rapid response. Love the tool!

eblume commented 10 months ago

I added a note to the relevant commit, but I wanted to put it here as well in case you would otherwise miss it - I think perhaps the solution here is to emit 7 backspaces, not 8. I think maybe the fact that there is a space after the ellipses was missed at some point. Just taking a shot in the dark here though, I don't have an easy way to test as I'm not set up as a developer for nb (yet)

xwmx commented 10 months ago

Yeah, it seems like it's due to the issue I just resolved in the latest changes above. This is what the final output now looks like for me with a notebook named example3 (in the terminal, the first example3 is highlighted in color):

❯ nb sync   
Syncing: example3...Done!
❯ nb sync --no-color
Syncing: example3...Done!

I'll try to make this change available in a new release version later today. I'm glad you like nb!

xwmx commented 9 months ago

@eblume This should be working as expected in the latest version, 7.5.9. Let me know if you encounter any more issues with it. Thanks!