From 72e1e38fb8077f591210f5af8510beb49ef84edd Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Tue, 23 May 2023 22:10:24 +0100 Subject: Utilities/w: Add `-h` option to optionally hide the header --- Userland/Utilities/w.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'Userland/Utilities') diff --git a/Userland/Utilities/w.cpp b/Userland/Utilities/w.cpp index 260b4a9bfc..bab3681a3a 100644 --- a/Userland/Utilities/w.cpp +++ b/Userland/Utilities/w.cpp @@ -45,9 +45,11 @@ ErrorOr serenity_main(Main::Arguments args) TRY(Core::System::unveil("/sys/kernel/processes", "r")); TRY(Core::System::unveil(nullptr, nullptr)); + bool hide_header = false; StringView username_to_filter_by; Core::ArgsParser args_parser; + args_parser.add_option(hide_header, "Don't show the header", "no-header", 'h'); args_parser.add_positional_argument(username_to_filter_by, "Only show information about the specified user", "user", Core::ArgsParser::Required::No); args_parser.parse(args); @@ -63,7 +65,9 @@ ErrorOr serenity_main(Main::Arguments args) auto now = Time::now_realtime().to_seconds(); - outln("\033[1m{:10} {:12} {:16} {:6} {}\033[0m", "USER", "TTY", "LOGIN@", "IDLE", "WHAT"); + if (!hide_header) + outln("\033[1m{:10} {:12} {:16} {:6} {}\033[0m", "USER", "TTY", "LOGIN@", "IDLE", "WHAT"); + TRY(json.as_object().try_for_each_member([&](auto& tty, auto& value) -> ErrorOr { const JsonObject& entry = value.as_object(); auto uid = entry.get_u32("uid"sv).value_or(0); -- cgit v1.2.3