1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 05:28:11 +00:00

ls: Use indicator for sockets and pipes

= indicator for sockets, | for pipes.
Pipes are now colored yellow like other special files
This commit is contained in:
LevitatingBusinessMan (Rein Fernhout) 2023-10-31 17:36:47 +01:00 committed by Daniel Bertalan
parent 4a5136fc8c
commit edd38358c2

View file

@ -54,7 +54,9 @@ enum class IndicatorStyle {
Directory = 1 << 0, Directory = 1 << 0,
Executable = 1 << 1, Executable = 1 << 1,
SymbolicLink = 1 << 2, SymbolicLink = 1 << 2,
Classify = Directory | Executable | SymbolicLink Pipe = 1 << 3,
Socket = 1 << 4,
Classify = Directory | Executable | SymbolicLink | Pipe | Socket
}; };
AK_ENUM_BITWISE_OPERATORS(IndicatorStyle) AK_ENUM_BITWISE_OPERATORS(IndicatorStyle)
@ -292,12 +294,13 @@ static size_t print_name(const struct stat& st, DeprecatedString const& name, Op
begin_color = "\033[32;1m"; begin_color = "\033[32;1m";
else if (S_ISSOCK(st.st_mode)) else if (S_ISSOCK(st.st_mode))
begin_color = "\033[35;1m"; begin_color = "\033[35;1m";
else if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) else if (S_ISFIFO(st.st_mode) || S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode))
begin_color = "\033[33;1m"; begin_color = "\033[33;1m";
printf("%s", begin_color); printf("%s", begin_color);
nprinted = print_escaped(name); nprinted = print_escaped(name);
printf("%s", end_color); printf("%s", end_color);
} }
if (S_ISLNK(st.st_mode)) { if (S_ISLNK(st.st_mode)) {
if (path_for_link_resolution.has_value()) { if (path_for_link_resolution.has_value()) {
auto link_destination_or_error = FileSystem::read_link(path_for_link_resolution.value()); auto link_destination_or_error = FileSystem::read_link(path_for_link_resolution.value());
@ -316,6 +319,12 @@ static size_t print_name(const struct stat& st, DeprecatedString const& name, Op
} else if (st.st_mode & 0111) { } else if (st.st_mode & 0111) {
if (has_flag(flag_indicator_style, IndicatorStyle::Executable)) if (has_flag(flag_indicator_style, IndicatorStyle::Executable))
nprinted += printf("*"); nprinted += printf("*");
} else if (S_ISFIFO(st.st_mode)) {
if (has_flag(flag_indicator_style, IndicatorStyle::Pipe))
nprinted += printf("|");
} else if (S_ISSOCK(st.st_mode)) {
if (has_flag(flag_indicator_style, IndicatorStyle::Socket))
nprinted += printf("=");
} }
if (!flag_disable_hyperlinks) { if (!flag_disable_hyperlinks) {