mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-14 22:31:29 +03:00
Colorize ls output.
This commit is contained in:
parent
52c19136f2
commit
e2dbdd14aa
Notes:
sideshowbarker
2024-07-19 18:37:19 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/e2dbdd14aab
@ -6,6 +6,8 @@
|
||||
|
||||
int main(int c, char** v)
|
||||
{
|
||||
bool colorize = true;
|
||||
|
||||
DIR* dirp = opendir(".");
|
||||
if (!dirp) {
|
||||
perror("opendir failed");
|
||||
@ -58,7 +60,26 @@ int main(int c, char** v)
|
||||
printf(" %4u %4u", st.st_uid, st.st_gid);
|
||||
|
||||
printf(" %10u ", st.st_size);
|
||||
printf("%s%c", de->d_name, S_ISDIR(st.st_mode) ? '/' : ' ');
|
||||
|
||||
const char* beginColor = "";
|
||||
const char* endColor = "";
|
||||
|
||||
if (colorize) {
|
||||
if (S_ISDIR(st.st_mode))
|
||||
beginColor = "\033[34;1m";
|
||||
else if (st.st_mode & 0111)
|
||||
beginColor = "\033[32;1m";
|
||||
else if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode))
|
||||
beginColor = "\033[33;1m";
|
||||
endColor = "\033[0m";
|
||||
}
|
||||
|
||||
printf("%s%s%s", beginColor, de->d_name, endColor);
|
||||
|
||||
if (S_ISDIR(st.st_mode))
|
||||
printf("/");
|
||||
else if (st.st_mode & 0111)
|
||||
printf("*");
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user