1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2026-01-21 05:31:00 +00:00
serenity/Userland/Utilities
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
..
adjtime.cpp adjtime: Drop unnecessary privileges unconditionally 2021-10-21 15:41:22 +01:00
allocate.cpp Utilities: Use ElapsedTimer::start_new in allocate 2021-09-12 17:24:44 +00:00
aplay.cpp Userland+LibAudio: Make audio applications support dynamic sample rate 2021-08-27 23:35:27 +04:30
arp.cpp arp: Preserve error if only the first ioctl fails 2021-10-13 16:11:30 +02:00
asctl.cpp Utilities: Fix asctl volume units 2021-09-19 21:52:32 +02:00
base64.cpp AK+Everywhere: Make Base64 decoding fallible 2021-10-23 19:16:40 +01:00
basename.cpp AK+Everywhere: Use mostly StringView in LexicalPath 2021-06-30 11:13:54 +02:00
beep.cpp Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
blockdev.cpp Utilities: Add way to get a storage devices block size in blockdev 2021-10-09 12:06:47 +02:00
bt.cpp Userland: Use /proc/kernel_base to determine the kernel base address 2021-07-22 21:38:23 +02:00
cal.cpp Userland: Replace most printf-style APIs with AK::Format APIs :^) 2021-06-01 21:30:16 +01:00
cat.cpp Utilities: Use Vector<String> positional arguments in some places 2021-04-29 11:28:01 +02:00
checksum.cpp checksum: Stop reusing the same Core::File for multiple files 2021-09-21 20:36:19 +03:00
chgrp.cpp Utilities: Remove unused header includes 2021-08-01 08:10:16 +02:00
chmod.cpp Userland: Replace most printf-style APIs with AK::Format APIs :^) 2021-06-01 21:30:16 +01:00
chown.cpp Userland: Return 1 when help text is shown for insufficient args 2021-06-01 21:30:16 +01:00
chres.cpp chres: Make screen an optional parameter 2021-07-10 18:51:14 +01:00
cksum.cpp cksum: Print argv[0] on failed read 2021-08-01 19:26:57 +04:30
clear.cpp Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
CMakeLists.txt Utilities: Add fdtdump for dumping OpenFirmware Device Trees 2021-10-21 19:20:03 -07:00
comm.cpp Utilities: Add an implementation of 'comm' 2021-07-14 14:13:25 +04:30
config.cpp Config CLI: Handle missing config values correctly 2021-08-31 16:52:58 +02:00
copy.cpp Utilities: Correct non-standard assert macros includes 2021-05-17 18:14:05 +01:00
cp.cpp Utilities: Implement -p flag for cp 2021-08-18 20:30:46 +02:00
cpp-lexer.cpp Utilities: Use File.error_string() instead of perror(3) in cpp-* 2021-08-22 02:01:58 +02:00
cpp-parser.cpp Utilities: Use File.error_string() instead of perror(3) in cpp-* 2021-08-22 02:01:58 +02:00
cpp-preprocessor.cpp Utilities: Use File.error_string() instead of perror(3) in cpp-* 2021-08-22 02:01:58 +02:00
cut.cpp Userland: Replace most printf-style APIs with AK::Format APIs :^) 2021-06-01 21:30:16 +01:00
date.cpp date: Use DateTime::now() for time, cleanup duplicate returns 2021-08-15 12:20:38 +02:00
dd.cpp Utilities: Allow filenames containing '=' in dd (#8766) 2021-07-15 18:36:46 +04:30
ddate.cpp ddate: Use DateTime::now() for time 2021-08-15 12:20:38 +02:00
df.cpp Userland: Replace most printf-style APIs with AK::Format APIs :^) 2021-06-01 21:30:16 +01:00
diff.cpp diff: Only color output when stdout is a tty 2021-09-24 14:32:52 +02:00
dirname.cpp AK+Everywhere: Add and use static APIs for LexicalPath 2021-06-30 11:13:54 +02:00
disasm.cpp Everywhere: Add missing includes for <AK/OwnPtr.h> 2021-05-19 21:36:57 +02:00
disk_benchmark.cpp Utilities: Use ElapsedTimer::start_new() in disk_bechmark 2021-09-12 17:24:44 +00:00
dmesg.cpp Utilities: Remove unused header includes 2021-08-01 08:10:16 +02:00
du.cpp Utilities: Remove unused header includes 2021-08-01 08:10:16 +02:00
echo.cpp echo: Support octal, hexadecimal and unicode escape sequences 2021-08-31 16:49:45 +02:00
env.cpp Userland: Let env parse options up to first non-option 2021-06-08 11:30:58 +02:00
errno.cpp Utilities: Remove unused header includes 2021-08-01 08:10:16 +02:00
expr.cpp LibRegex+Everywhere: Make LibRegex more unicode-aware 2021-07-18 21:10:55 +04:30
false.cpp Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
fdtdump.cpp Utilities: Add fdtdump for dumping OpenFirmware Device Trees 2021-10-21 19:20:03 -07:00
fgrep.cpp Utilities: Fix -Wunreachable-code warnings from clang 2021-10-08 23:33:46 +02:00
file.cpp Userland: Teach the file utility more about ELF files 2021-10-21 01:14:09 +02:00
find.cpp Userland: Also cache d_type in find(1) 2021-08-18 18:13:59 +02:00
flock.cpp Userland: Return 1 when help text is shown for insufficient args 2021-06-01 21:30:16 +01:00
fortune.cpp Utilities: Remove unused header includes 2021-08-01 08:10:16 +02:00
functrace.cpp Utilities: Remove unused header includes 2021-08-01 08:10:16 +02:00
gml-format.cpp LibCore+Everywhere: Move OpenMode out of IODevice 2021-05-12 11:00:45 +01:00
grep.cpp Utilities: Add option to suppress errors to grep 2021-10-31 14:18:29 +03:30
gron.cpp Utilities: Remove unused header includes 2021-08-01 08:10:16 +02:00
groupadd.cpp Utilities: Remove unused header includes 2021-08-01 08:10:16 +02:00
groupdel.cpp Utilities: Fix null deref in groupdel when given a nonexistent group 2021-10-10 03:10:05 -07:00
groups.cpp Userland: Add groups program 2021-05-05 15:12:30 +01:00
gunzip.cpp Utilities: Use Vector<String> positional arguments in some places 2021-04-29 11:28:01 +02:00
gzip.cpp Utilities: Add -d option to gzip 2021-08-22 16:51:18 +02:00
head.cpp Utilities: Remove unused header includes 2021-08-01 08:10:16 +02:00
hexdump.cpp Userland: Replace most printf-style APIs with AK::Format APIs :^) 2021-06-01 21:30:16 +01:00
host.cpp Userland: Replace most printf-style APIs with AK::Format APIs :^) 2021-06-01 21:30:16 +01:00
hostname.cpp hostname: Handle 'sethostname' errors 2021-06-04 19:11:27 +02:00
id.cpp Userland: Fix id(1) printing the user's primary group for extra gids 2021-07-31 17:56:53 +02:00
ifconfig.cpp ifconfig: Use shorter argument names 2021-06-05 23:51:08 +04:30
ini.cpp Everywhere: Use Core::ConfigFile::AllowWriting::Yes to allow writing 2021-08-22 01:32:25 +02:00
jp.cpp Userland: Avoid a bunch of JsonObject copies 2021-05-31 17:59:02 +01:00
js.cpp js: Convert JavaScript REPL to ThrowCompletionOr 2021-10-31 07:50:30 +02:00
kcov-example.cpp Kernel: Add option to build with coverage instrumentation and KCOV 2021-07-26 17:40:28 +02:00
keymap.cpp Everywhere: Use Core::ConfigFile::AllowWriting::Yes to allow writing 2021-08-22 01:32:25 +02:00
kill.cpp Userland: Replace most printf-style APIs with AK::Format APIs :^) 2021-06-01 21:30:16 +01:00
killall.cpp Everywhere: Improve CPU usage calculation 2021-07-18 22:08:26 +02:00
less.cpp Userland: Handle terminal window resizing in less(1) 2021-10-31 12:34:37 +01:00
ln.cpp Utilities: Add -f option to ln 2021-10-23 15:06:33 +02:00
logout.cpp TaskBar+Utilities: Add logout(1) command, and call it in ShutdownDialog 2021-10-17 22:18:48 +02:00
ls.cpp AK: Make Utf8View constructors inline and remove C string constructor 2021-09-18 19:54:24 +02:00
lsirq.cpp Userland: Replace most printf-style APIs with AK::Format APIs :^) 2021-06-01 21:30:16 +01:00
lsof.cpp Utilities: Remove unused header includes 2021-08-01 08:10:16 +02:00
lspci.cpp Kernel/PCI: Simplify the entire subsystem 2021-09-07 13:47:37 +02:00
lsusb.cpp Kernel/Userland: Expose usb device address and use it in lsusb 2021-08-31 16:38:49 +02:00
man.cpp AK: Replace the mutable String::replace API with an immutable version 2021-09-11 20:36:43 +03:00
markdown-check.cpp man.serenityos.org: Use pandoc for listings and landing page 2021-10-22 19:49:28 +03:00
matroska.cpp LibVideo: Migrate to east-const style & apply other minor fixes 2021-06-30 11:03:51 +02:00
md.cpp md: Improve document parsing error message 2021-06-01 21:30:16 +01:00
misbehaving-application.cpp Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
mkdir.cpp AK+Everywhere: Use mostly StringView in LexicalPath 2021-06-30 11:13:54 +02:00
mkfifo.cpp Everywhere: Use my cool new @serenityos.org email address 2021-09-01 11:37:25 +04:30
mknod.cpp Userland: Return 1 when help text is shown for insufficient args 2021-06-01 21:30:16 +01:00
mktemp.cpp Everywhere: Fix format-vulnerabilities 2021-09-11 15:16:26 +01:00
mount.cpp Userland: Replace most printf-style APIs with AK::Format APIs :^) 2021-06-01 21:30:16 +01:00
mv.cpp AK+Everywhere: Add and use static APIs for LexicalPath 2021-06-30 11:13:54 +02:00
nc.cpp Everywhere: Make ByteBuffer::{create_*,copy}() OOM-safe 2021-09-06 01:53:26 +02:00
netstat.cpp Utilities: Add program argument for netstat to display connection pid 2021-08-13 20:03:57 +04:30
nl.cpp Userland: Replace most printf-style APIs with AK::Format APIs :^) 2021-06-01 21:30:16 +01:00
notify.cpp Utilities: Remove unused header includes 2021-08-01 08:10:16 +02:00
nproc.cpp nproc: Avoid making StringView of temporary ByteBuffer 2021-09-11 13:22:51 +03:00
ntpquery.cpp Userland: Switch static_assert of type sizes to AK::AssertSize 2021-09-05 20:08:57 +02:00
open.cpp Utilities: Add support for relative paths in open command 2021-06-02 17:34:27 +04:30
pape.cpp Userland: Replace most printf-style APIs with AK::Format APIs :^) 2021-06-01 21:30:16 +01:00
passwd.cpp LibCore: Change Account::set_password to take a SecretString 2021-10-19 18:19:33 +02:00
paste.cpp Userland: Implement paste --watch mode 2021-05-10 19:09:53 +01:00
pathchk.cpp Everywhere: "file name" => "filename" 2021-04-29 22:16:18 +02:00
pgrep.cpp Everywhere: Improve CPU usage calculation 2021-07-18 22:08:26 +02:00
pidof.cpp Everywhere: Improve CPU usage calculation 2021-07-18 22:08:26 +02:00
ping.cpp Utilities: Fix -Wunreachable-code warnings from clang 2021-10-08 23:33:46 +02:00
pls.cpp LibCore: Make Account::authenticate take a SecretString 2021-09-12 16:36:52 +02:00
pmap.cpp Utilities: Make sure columns are properly aligned for pmap on x86_64 2021-07-22 08:57:01 +02:00
printf.cpp Utilities: Correct non-standard assert macros includes 2021-05-17 18:14:05 +01:00
pro.cpp Everywhere: Use OOM-safe ByteBuffer APIs where possible 2021-09-06 01:53:26 +02:00
profile.cpp profile: Always enable PERF_EVENT_SIGNPOST 2021-08-12 00:03:38 +02:00
ps.cpp Utilities: Show PGID and SID in ps -f 2021-10-17 22:18:48 +02:00
purge.cpp Userland: Replace most printf-style APIs with AK::Format APIs :^) 2021-06-01 21:30:16 +01:00
pwd.cpp Utilities: Implement pwd 2021-07-09 20:15:40 +02:00
readelf.cpp LibELF+Userland: Move a few functions to Elf::Image 2021-10-21 01:14:09 +02:00
readlink.cpp Userland: Replace most printf-style APIs with AK::Format APIs :^) 2021-06-01 21:30:16 +01:00
realpath.cpp Userland: Replace most printf-style APIs with AK::Format APIs :^) 2021-06-01 21:30:16 +01:00
reboot.cpp Kernel+Userland: Introduce a new way to reboot and poweroff the machine 2021-09-12 11:52:16 +02:00
rev.cpp rev: Unbreak reading from standard input 2021-10-17 12:07:09 -07:00
rm.cpp rm: Allow empty paths if -f is specified 2021-06-05 10:56:58 +02:00
rmdir.cpp Utilities: Remove unused header includes 2021-08-01 08:10:16 +02:00
run-tests.cpp Everywhere: Rename get in ConfigFile::get_for_{lib,app,system} to open 2021-08-22 01:32:25 +02:00
seq.cpp Userland: Replace most printf-style APIs with AK::Format APIs :^) 2021-06-01 21:30:16 +01:00
shot.cpp Everywhere: Rename left/right-click to primary/secondary 2021-10-27 22:05:58 +03:00
shuf.cpp shuf: Fix division by zero when no lines are read 2021-10-17 12:07:09 -07:00
shutdown.cpp Kernel+Userland: Introduce a new way to reboot and poweroff the machine 2021-09-12 11:52:16 +02:00
sleep.cpp LibC: Do not include errno.h inside unistd.h 2021-05-14 22:24:02 +02:00
sort.cpp Utilities: Modernize output and comparison in the sort utility 2021-09-05 00:15:26 +02:00
sql.cpp SQL Utility: Implement reading sql files 2021-10-05 02:22:19 +02:00
stat.cpp Kernel+LibC: Use 64 bit values for ino_t 2021-08-12 20:57:32 +02:00
strace.cpp Kernel + WindowServer: Re-define the interface to framebuffer devices 2021-10-27 07:57:44 +03:00
stty.cpp Utilities: Remove unused header includes 2021-08-01 08:10:16 +02:00
su.cpp LibCore: Make Account::authenticate take a SecretString 2021-09-12 16:36:52 +02:00
sync.cpp Utilities: Remove unused header includes 2021-08-01 08:10:16 +02:00
syscall.cpp Kernel: Make a bunch of "char const* to_string()" return StringView 2021-08-06 00:37:47 +02:00
sysctl.cpp sysctl: Allow showing or setting multiple variables 2021-10-17 14:46:59 +02:00
tac.cpp tac: Unbreak reading from standard input 2021-10-17 12:07:09 -07:00
tail.cpp Userland: Replace most printf-style APIs with AK::Format APIs :^) 2021-06-01 21:30:16 +01:00
tar.cpp Everywhere: Use my cool new @serenityos.org email address 2021-09-01 11:37:25 +04:30
tee.cpp Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
telws.cpp AK+Everywhere: Make Base64 decoding fallible 2021-10-23 19:16:40 +01:00
test-bindtodevice.cpp Userland: Rename e1k0 to ep0s7 2021-05-22 15:42:54 +01:00
test-crypto.cpp LibTLS: Use a setter for on_tls_ready_to_write with some more smarts 2021-09-19 21:10:23 +04:30
test-fuzz.cpp LibCore+Everywhere: Move OpenMode out of IODevice 2021-05-12 11:00:45 +01:00
test-imap.cpp LibCore: Make get_password return SecretString instead of String 2021-09-12 16:36:52 +02:00
test-pthread.cpp test-pthread: Add a mutex test 2021-07-07 17:08:40 +02:00
test-unveil.cpp Utilities: Fix test-unveil INT_MAX include 2021-05-23 18:10:29 +02:00
test.cpp Utilities: Remove unused header includes 2021-08-01 08:10:16 +02:00
test_env.cpp Userland: Replace most printf-style APIs with AK::Format APIs :^) 2021-06-01 21:30:16 +01:00
top.cpp Utilities: Fix -Wunreachable-code warnings from clang 2021-10-08 23:33:46 +02:00
touch.cpp Utilities: Add ignored -f option to touch 2021-10-23 15:06:33 +02:00
tr.cpp AK: Move FormatParser definition from header to implementation file 2021-08-19 23:49:25 +02:00
traceroute.cpp Utilities: Fix incorrect error handling in traceroute 2021-09-12 16:36:52 +02:00
tree.cpp AK+Everywhere: Add and use static APIs for LexicalPath 2021-06-30 11:13:54 +02:00
true.cpp Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
truncate.cpp Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
tt.cpp Utilities: Fix -Wunreachable-code warnings from clang 2021-10-08 23:33:46 +02:00
tty.cpp Userland: Replace most printf-style APIs with AK::Format APIs :^) 2021-06-01 21:30:16 +01:00
umount.cpp Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
uname.cpp Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
uniq.cpp Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
unzip.cpp Utilites: Implement unzip -q 2021-06-13 17:05:48 +01:00
uptime.cpp Userland: Replace most printf-style APIs with AK::Format APIs :^) 2021-06-01 21:30:16 +01:00
useradd.cpp Utilities: Do not allow creating users with existing usernames 2021-06-09 09:00:31 +02:00
userdel.cpp Utilities: Validate user with Core::Account in userdel 2021-06-24 17:33:14 +04:30
usermod.cpp Utilities: Remove unused header includes 2021-08-01 08:10:16 +02:00
utmpupdate.cpp Utilities: Correct non-standard assert macros includes 2021-05-17 18:14:05 +01:00
w.cpp Utilities: Remove unused header includes 2021-08-01 08:10:16 +02:00
wasm.cpp wasm: Avoid making StringView of temporary ByteBuffer 2021-09-11 13:22:51 +03:00
watch.cpp watch: Add ability to run command on file change 2021-10-23 11:41:18 +02:00
wc.cpp wc: Count last line even if it doesn't end in newline 2021-10-29 22:37:34 +03:00
which.cpp which: Replace printf() with outln()/warnln() 2021-05-30 14:07:58 +01:00
whoami.cpp Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
wsctl.cpp WindowServer+wsctl: Add a simple utility for toggling "flash flush" 2021-07-07 22:56:46 +02:00
xargs.cpp Everywhere: Prefer using "..."sv over StringView { "..." } 2021-07-04 14:24:03 +02:00
yes.cpp Utilities: Fix -Wunreachable-code warnings from clang 2021-10-08 23:33:46 +02:00
zip.cpp LibCore+Everywhere: Move OpenMode out of IODevice 2021-05-12 11:00:45 +01:00