mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:07:36 +00:00
Userland: Bring back improved "LOGIN@" column in "w"
This actually looks a lot nicer if we slim down the datetime format. Also remove the "FROM" column which was the one I actually didn't want.
This commit is contained in:
parent
c995166c56
commit
6dc5cda50d
1 changed files with 6 additions and 3 deletions
|
@ -1,5 +1,6 @@
|
||||||
#include <AK/JsonObject.h>
|
#include <AK/JsonObject.h>
|
||||||
#include <AK/JsonValue.h>
|
#include <AK/JsonValue.h>
|
||||||
|
#include <LibCore/DateTime.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
#include <LibCore/ProcessStatisticsReader.h>
|
#include <LibCore/ProcessStatisticsReader.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
|
@ -53,13 +54,15 @@ int main()
|
||||||
auto now = time(nullptr);
|
auto now = time(nullptr);
|
||||||
|
|
||||||
printf("\033[1m%-10s %-12s %-16s %-6s %s\033[0m\n",
|
printf("\033[1m%-10s %-12s %-16s %-6s %s\033[0m\n",
|
||||||
"USER", "TTY", "FROM", "IDLE", "WHAT");
|
"USER", "TTY", "LOGIN@", "IDLE", "WHAT");
|
||||||
json.value().as_object().for_each_member([&](auto& tty, auto& value) {
|
json.value().as_object().for_each_member([&](auto& tty, auto& value) {
|
||||||
const JsonObject& entry = value.as_object();
|
const JsonObject& entry = value.as_object();
|
||||||
auto uid = entry.get("uid").to_u32();
|
auto uid = entry.get("uid").to_u32();
|
||||||
auto pid = entry.get("pid").to_i32();
|
auto pid = entry.get("pid").to_i32();
|
||||||
(void)pid;
|
(void)pid;
|
||||||
auto from = entry.get("from").to_string();
|
|
||||||
|
auto login_time = Core::DateTime::from_timestamp(entry.get("login_at").to_number<time_t>());
|
||||||
|
auto login_at = login_time.to_string("%b%d %H:%M:%S");
|
||||||
|
|
||||||
auto* pw = getpwuid(uid);
|
auto* pw = getpwuid(uid);
|
||||||
String username;
|
String username;
|
||||||
|
@ -89,7 +92,7 @@ int main()
|
||||||
printf("%-10s %-12s %-16s %-6s %s\n",
|
printf("%-10s %-12s %-16s %-6s %s\n",
|
||||||
username.characters(),
|
username.characters(),
|
||||||
tty.characters(),
|
tty.characters(),
|
||||||
from.characters(),
|
login_at.characters(),
|
||||||
idle_string.characters(),
|
idle_string.characters(),
|
||||||
what.characters());
|
what.characters());
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue