1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:04:59 +00:00

Utilities/w: Display the TTY pseudo name in the "TTY" column

This matches the format used by `ps`.

If we cannot determine the TTY
pseudo name we fall back to the full device name, as shown previously.
This commit is contained in:
Tim Ledbetter 2023-05-23 22:10:15 +01:00 committed by Andreas Kling
parent 2dbc7e4fff
commit d2ec82d4f9

View file

@ -75,6 +75,7 @@ ErrorOr<int> serenity_main(Main::Arguments)
StringBuilder builder;
String idle_string = "n/a"_short_string;
String what = "n/a"_short_string;
StringView tty_display_name = tty;
auto maybe_stat = Core::System::stat(tty);
if (!maybe_stat.is_error()) {
auto stat = maybe_stat.release_value();
@ -85,6 +86,7 @@ ErrorOr<int> serenity_main(Main::Arguments)
}
auto tty_pseudo_name = TRY(tty_stat_to_pseudo_name(stat));
tty_display_name = tty_pseudo_name;
for (auto& process : process_statistics.processes) {
if (tty_pseudo_name == process.tty.view() && process.pid == process.pgid) {
what = TRY(String::from_deprecated_string(process.name));
@ -93,7 +95,7 @@ ErrorOr<int> serenity_main(Main::Arguments)
}
}
outln("{:10} {:12} {:16} {:6} {}", username, tty, login_at, idle_string, what);
outln("{:10} {:12} {:16} {:6} {}", username, tty_display_name, login_at, idle_string, what);
return {};
}));
return 0;