parent
0d4912826b
commit
cebd3f740b
Notes:
sideshowbarker
2024-07-18 19:29:18 +09:00
Author: https://github.com/danielledeleo Commit: https://github.com/SerenityOS/serenity/commit/cebd3f740b6 Pull-request: https://github.com/SerenityOS/serenity/pull/6430 Issue: https://github.com/SerenityOS/serenity/issues/5671 Reviewed-by: https://github.com/awesomekling
1 changed files with 9 additions and 3 deletions
|
@ -75,6 +75,8 @@ static bool output_is_terminal = false;
|
||||||
static HashMap<uid_t, String> users;
|
static HashMap<uid_t, String> users;
|
||||||
static HashMap<gid_t, String> groups;
|
static HashMap<gid_t, String> groups;
|
||||||
|
|
||||||
|
static bool is_a_tty = false;
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
if (pledge("stdio rpath tty", nullptr) < 0) {
|
if (pledge("stdio rpath tty", nullptr) < 0) {
|
||||||
|
@ -89,7 +91,9 @@ int main(int argc, char** argv)
|
||||||
terminal_columns = ws.ws_col;
|
terminal_columns = ws.ws_col;
|
||||||
output_is_terminal = true;
|
output_is_terminal = true;
|
||||||
}
|
}
|
||||||
if (!isatty(STDOUT_FILENO)) {
|
|
||||||
|
is_a_tty = isatty(STDOUT_FILENO);
|
||||||
|
if (!is_a_tty) {
|
||||||
flag_disable_hyperlinks = true;
|
flag_disable_hyperlinks = true;
|
||||||
} else {
|
} else {
|
||||||
flag_colorize = true;
|
flag_colorize = true;
|
||||||
|
@ -483,8 +487,10 @@ static bool print_names(const char* path, size_t longest_name, const Vector<Stri
|
||||||
size_t column_width = longest_name + max(offset, 2);
|
size_t column_width = longest_name + max(offset, 2);
|
||||||
printed_on_row += column_width;
|
printed_on_row += column_width;
|
||||||
|
|
||||||
|
if (is_a_tty) {
|
||||||
for (size_t j = nprinted; i != (names.size() - 1) && j < column_width; ++j)
|
for (size_t j = nprinted; i != (names.size() - 1) && j < column_width; ++j)
|
||||||
printf(" ");
|
printf(" ");
|
||||||
|
}
|
||||||
if ((printed_on_row + column_width) >= terminal_columns) {
|
if ((printed_on_row + column_width) >= terminal_columns) {
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printed_on_row = 0;
|
printed_on_row = 0;
|
||||||
|
|
Loading…
Add table
Reference in a new issue