jless icon indicating copy to clipboard operation
jless copied to clipboard

[ feature request ] : add line number (via an option)

Open dulfox opened this issue 2 years ago • 1 comments

Can you add line number like cat -n or less -N ?

dulfox avatar Jun 14 '22 07:06 dulfox

One slight complication is that (as far as I know) both cat and less will display the numbers as they are found in the source input, right? But because jless pretty-prints its input, line numbers for lines in the console will often not correspond to line numbers in the input. (A lot of the time I use it to display files that contain a very long json string on a single line without any line breaks, for instance.) Which option did you have in mind? (Just to clarify: I'm not a contributor to this project so I don't have any say in this, but just interested to hear about your use cases!)

bryophyta avatar Aug 07 '22 20:08 bryophyta

I also felt the need for this, however I would suggest providing a way to jump to a line number in line mode would make sense. For example less lets you jump to a line with <n>g, that would work nicely with muscle memory ;)

I tend to want this when I'm comparing multiple json files. Diff gives me the exact line with the change, but jless is good to get more than the default 3 lines of context.

suvayu avatar Oct 13 '22 11:10 suvayu

Support for absolute line numbers, based on the pretty-printed input, has been added in 60b5f1b89f87c4c985c9843d7bd181e5d6337031, 89ad5d4bd1bc278b6377e7942a618e06c5a8fba7, 0bfb7472d215de99eae0f3d594146d68a912104d, 7a3a719e4eb471bae7b125c346f01f37274cb20b, cf8d48b1f034fb49792ec555418cff7e096112b1, c06fead6c825950b3f61e7aa8f59554d73ea448e, and 3500b5843edf5e7d676a32354c9f43f975ed82f9.

Absolute line numbers will be shown by default, but relative line numbers are also supported via the --relative-line-numbers flag. (This can also be changed at runtime.)

Jumping to a specific line number can be done with <n>g or <n>G. The capital letter version is more forceful, and will automatically containers as necessary to focus on given line number, where as <n>g will just focus the last visible line before the given line number.

I will close this when I create a new release (hopefully in the next week or two).

PaulJuliusMartinez avatar Jul 09 '23 05:07 PaulJuliusMartinez

This functionality is now available in v0.9.0.

PaulJuliusMartinez avatar Jul 17 '23 03:07 PaulJuliusMartinez