Commit graph

23 commits

Author SHA1 Message Date
Peter Elliott
23e09eb7f4 less: Handle tabs in line wrapping
Before tabs were treated as a width of 1, which would cause issues with
man page headers.
2021-12-29 00:00:02 +01:00
Peter Elliott
20a0572de8 Userland: Port less(1) to LibMain 2021-12-29 00:00:02 +01:00
Peter Elliott
6312742257 less: Remove all formatting before printing status line 2021-12-29 00:00:02 +01:00
Peter Elliott
3677e88fb1 less: Dynamically re-wrap lines on resize
This change moves from wrapping lines at the start to operating on whole
lines and wrapping them as needed.

This has a few added benefits:
- line numbers are now always accurate.
- going to a line actually works
2021-12-29 00:00:02 +01:00
Andreas Kling
8b1108e485 Everywhere: Pass AK::StringView by value 2021-11-11 01:27:46 +01:00
Ben Wiederhake
4e1318fb0e less: Fix condition to read more data
While mathematically equivalent, the presence of a size_t forces the
comparison to work with size_t's. This means that '-1 < 0' is false,
contrary to the 'mathematically pure' interpretation of the inequality.
2021-11-01 10:55:10 +01:00
Kyle Ambroff-Kao
0329a37271 Userland: Handle terminal window resizing in less(1)
Before this patch less would query the terminal geometry only at
startup and use this information to render the file when
appropriate. If the terminal is resized then the output is broken in
several different ways because of this.

This patch adds a SIGWINCH signal handler receive notification any
time the terminal is resized. This signal handler just sets a flag to
notify the main loop that a resize has occurred.

The main loop of the program just calls get_key_sequence() to get
input from the user, interpreting keystrokes as commands like scroll
up or down. The get_key_sequence() function has been changed to return
Optional<String>, so it either returns a keystroke from the user or it
returns nothing as an empty Optional.

While the user is not pressing any keys on the keyboard, the program
is blocking on a read() system call in get_key_sequence(). When
SIGWINCH is received, this read() will return with -1 and errno is set
to EINTR since the system call was interrupted by the signal. When
this happens we just return an empty Optional.

The mainloop now checks to see if a resize has been requested by
checking the flag, and if it has it performs a resize.

init() now just calls resize() since the required logic is the same.

Setters for m_filename and m_prompt are removed because these are now
just initialized by the constructor, as they never change for the life
of the program.
2021-10-31 12:34:37 +01:00
Nico Weber
6c9bc18a79 Userland: Fix typos 2021-10-01 01:18:52 +01:00
Andreas Kling
1be4cbd639 AK: Make Utf8View constructors inline and remove C string constructor
Using StringView instead of C strings is basically always preferable.
The only reason to use a C string is because you are calling a C API.
2021-09-18 19:54:24 +02:00
Ali Mohammad Pur
97e97bccab Everywhere: Make ByteBuffer::{create_*,copy}() OOM-safe 2021-09-06 01:53:26 +02:00
Peter Elliott
33d7fdca28 Everywhere: Use my cool new @serenityos.org email address 2021-09-01 11:37:25 +04:30
Lennon Donaghy
e426e15101 Utilities: Make 'less' act more like 'more' when emulating 'more' :^) 2021-07-29 01:23:07 +02:00
Lennon Donaghy
e9bd81a6a0 Utilities: Add half-page scrolling + number modifiers to 'less'
- 'u' and 'd' now scroll up and down half a page
- Typing a number followed by 'j', 'k', 'return', 'up' or 'down' will
  scroll that many lines in the appropriate direction
- Typing a number followed by 'g' or 'G' will scroll directly to the
  line corresponding to that number
2021-07-29 01:23:07 +02:00
Lennon Donaghy
a071dba1ef Utilities: Add fix for 'less' not buffering the correct number of lines
'down_n()' now correctly buffers the needed number of lines, previously
there were issues with using it to scroll much more than the existing
buffer.
2021-07-29 01:23:07 +02:00
Lennon Donaghy
c4887882cc Utilities: Allow 'less' to scroll to top/bottom using 'G' and 'g' 2021-07-27 13:08:43 +02:00
Brandon van Houten
19d34414bc Utilities: Make less accept 'page up' and 'page down' keys 2021-07-12 16:10:01 +02:00
Ralf Donau
821b752993 Userland: Add fopen error handling to less 2021-07-10 10:32:01 +02:00
Ralf Donau
6386c2d880 Userland: Add pledge to less 2021-07-07 20:27:40 +02:00
Peter Elliott
a11658737a Userland: Less: emulate cat when stdout is not a tty
This is the most logical behavior when less is used in a pipe.
2021-07-07 20:01:15 +04:30
Peter Elliott
1ec061d666 Userland: Add pager option to man and use less by default 2021-07-07 20:01:15 +04:30
Peter Elliott
c6fa2f196a Userland: Add more(1) emulation to less(1)
This patch also removes the existing implementation of more, as it is
now redundant.
2021-07-07 20:01:15 +04:30
Peter Elliott
30aa9b837c Userland: Add minimal prompt support to less
GNU less has a pretty cool prompt format language. This patch adds
support for the language and specifiers for filename, linenumber, and
ending.
2021-07-07 20:01:15 +04:30
Peter Elliott
7ee1983db6 Userland: Add less, a better terminal pager
less is a re-implementation of gnu less, a terminal pager with backwards
scrolling and alternate screen support.
2021-07-07 20:01:15 +04:30