1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-23 18:45:07 +00:00

ps: Use Optional for column indices, instead of -1 meaning "not present"

This commit is contained in:
Sam Atkins 2023-05-14 13:20:40 +01:00 committed by Andreas Kling
parent e6f7b828c3
commit 02ee93d6c9

View file

@ -65,14 +65,14 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
Vector<Column> columns; Vector<Column> columns;
int uid_column = -1; Optional<size_t> uid_column;
int pid_column = -1; Optional<size_t> pid_column;
int ppid_column = -1; Optional<size_t> ppid_column;
int pgid_column = -1; Optional<size_t> pgid_column;
int sid_column = -1; Optional<size_t> sid_column;
int state_column = -1; Optional<size_t> state_column;
int tty_column = -1; Optional<size_t> tty_column;
int cmd_column = -1; Optional<size_t> cmd_column;
auto add_column = [&](auto title, auto alignment) { auto add_column = [&](auto title, auto alignment) {
columns.unchecked_append({ title, alignment, 0, {} }); columns.unchecked_append({ title, alignment, 0, {} });
@ -148,24 +148,24 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
if (tty == "") if (tty == "")
tty = "n/a"_short_string; tty = "n/a"_short_string;
if (uid_column != -1) if (uid_column.has_value())
row[uid_column] = TRY(String::from_deprecated_string(process.username)); row[*uid_column] = TRY(String::from_deprecated_string(process.username));
if (pid_column != -1) if (pid_column.has_value())
row[pid_column] = TRY(String::number(process.pid)); row[*pid_column] = TRY(String::number(process.pid));
if (ppid_column != -1) if (ppid_column.has_value())
row[ppid_column] = TRY(String::number(process.ppid)); row[*ppid_column] = TRY(String::number(process.ppid));
if (pgid_column != -1) if (pgid_column.has_value())
row[pgid_column] = TRY(String::number(process.pgid)); row[*pgid_column] = TRY(String::number(process.pgid));
if (sid_column != -1) if (sid_column.has_value())
row[sid_column] = TRY(String::number(process.sid)); row[*sid_column] = TRY(String::number(process.sid));
if (tty_column != -1) if (tty_column.has_value())
row[tty_column] = tty; row[*tty_column] = tty;
if (state_column != -1) if (state_column.has_value())
row[state_column] = process.threads.is_empty() row[*state_column] = process.threads.is_empty()
? "Zombie"_short_string ? "Zombie"_short_string
: TRY(String::from_deprecated_string(process.threads.first().state)); : TRY(String::from_deprecated_string(process.threads.first().state));
if (cmd_column != -1) if (cmd_column.has_value())
row[cmd_column] = TRY(String::from_deprecated_string(process.name)); row[*cmd_column] = TRY(String::from_deprecated_string(process.name));
rows.unchecked_append(move(row)); rows.unchecked_append(move(row));
} }