Commit 2f09c95e authored by Kevin Wolf's avatar Kevin Wolf

shell: Ein bisschen mehr Farbe

* shell: Wenn stdin ein Terminal ist, aktiviert ls die Farben jetzt per
  Default. Außer dem Dateinamen wird jetzt auch der Typ eingefärbt.
  Abgesehen davon macht ps die Überschriften auf Terminals weiß und der
  Prompt ist jetzt ebenfalls weiß statt hellgrau.
Signed-off-by: Kevin Wolf's avatarKevin Wolf <kevin@tyndur.org>
parent 20d46f0d
...@@ -41,10 +41,12 @@ ...@@ -41,10 +41,12 @@
#include <lost/config.h> #include <lost/config.h>
#include <getopt.h> #include <getopt.h>
#include <collections.h> #include <collections.h>
#include <lostio.h>
#include <tms.h> #include <tms.h>
#define LS_COLOR_RESET_DEFAULT "00" #define LS_COLOR_RESET_DEFAULT "00"
#define LS_COLOR_TYPE "32"
#define LS_COLOR_FILE_DEFAULT "00" #define LS_COLOR_FILE_DEFAULT "00"
#define LS_COLOR_DIR_DEFAULT "01;34" #define LS_COLOR_DIR_DEFAULT "01;34"
#define LS_COLOR_LINK_DEFAULT "01;36" #define LS_COLOR_LINK_DEFAULT "01;36"
...@@ -52,6 +54,10 @@ ...@@ -52,6 +54,10 @@
void ls_display_usage(void); void ls_display_usage(void);
char* format_size(size_t size, bool human_readable); char* format_size(size_t size, bool human_readable);
enum {
OPT_NO_COLOR = 256,
};
#ifdef CONFIG_SHELL_BUILTIN_ONLY #ifdef CONFIG_SHELL_BUILTIN_ONLY
int shell_command_ls(int argc, char* argv[]) int shell_command_ls(int argc, char* argv[])
#else #else
...@@ -73,11 +79,16 @@ char* format_size(size_t size, bool human_readable); ...@@ -73,11 +79,16 @@ char* format_size(size_t size, bool human_readable);
{ "help", no_argument, 0, 1 }, { "help", no_argument, 0, 1 },
{ "human-readable", no_argument, 0, 'h' }, { "human-readable", no_argument, 0, 'h' },
{ "color", no_argument, 0, 'C' }, { "color", no_argument, 0, 'C' },
{ "no-color", no_argument, 0, OPT_NO_COLOR },
{ 0, 0, 0, 0 } { 0, 0, 0, 0 }
}; };
optind = 0; optind = 0;
if (file_is_terminal(stdout)) {
colorize = true;
}
while (optind < argc) { while (optind < argc) {
int result = getopt_long(argc, argv, "ahC", long_options, NULL); int result = getopt_long(argc, argv, "ahC", long_options, NULL);
if (result == -1) { if (result == -1) {
...@@ -93,6 +104,9 @@ char* format_size(size_t size, bool human_readable); ...@@ -93,6 +104,9 @@ char* format_size(size_t size, bool human_readable);
case 'C': case 'C':
colorize = true; colorize = true;
break; break;
case OPT_NO_COLOR:
colorize = false;
break;
case 1: case 1:
ls_display_usage(); ls_display_usage();
return EXIT_SUCCESS; return EXIT_SUCCESS;
...@@ -143,8 +157,10 @@ char* format_size(size_t size, bool human_readable); ...@@ -143,8 +157,10 @@ char* format_size(size_t size, bool human_readable);
} }
if (colorize) { if (colorize) {
printf(" [%s] %s \e[%sm%s\e[%sm\n", flags, formatted_size, printf(" [\e[%sm%s\e[%sm] %s \e[%sm%s\e[%sm\n",
color, direntry->name, LS_COLOR_RESET_DEFAULT); LS_COLOR_TYPE, flags, LS_COLOR_RESET_DEFAULT,
formatted_size,
color, direntry->name, LS_COLOR_RESET_DEFAULT);
} else { } else {
printf(" [%s] %s %s\n", flags, formatted_size, printf(" [%s] %s %s\n", flags, formatted_size,
direntry->name); direntry->name);
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include "syscall.h" #include "syscall.h"
#include "unistd.h" #include "unistd.h"
#include <lost/config.h> #include <lost/config.h>
#include <lostio.h>
#include <tms.h> #include <tms.h>
void ps_display_usage(void); void ps_display_usage(void);
...@@ -54,6 +55,7 @@ void ps_display_usage(void); ...@@ -54,6 +55,7 @@ void ps_display_usage(void);
char* temp; char* temp;
char* process; char* process;
char copied_cmdline[255]; char copied_cmdline[255];
bool color = file_is_terminal(stdout);
if (argc > 2) { if (argc > 2) {
ps_display_usage(); ps_display_usage();
...@@ -73,12 +75,18 @@ void ps_display_usage(void); ...@@ -73,12 +75,18 @@ void ps_display_usage(void);
task_info_t* task_info = enumerate_tasks(); task_info_t* task_info = enumerate_tasks();
uint32_t i; uint32_t i;
if (color) {
printf("\033[1m");
}
if (with_eip) { if (with_eip) {
printf(TMS(ps_with_eip, printf(TMS(ps_with_eip,
" PID PPID Status EIP Speicher CMD\n")); " PID PPID Status EIP Speicher CMD\n"));
} else { } else {
printf(TMS(ps_without_eip, " PID PPID Status Speicher CMD\n")); printf(TMS(ps_without_eip, " PID PPID Status Speicher CMD\n"));
} }
if (color) {
printf("\033[0m");
}
for (i = 0; i < task_info->task_count; i++) { for (i = 0; i < task_info->task_count; i++) {
strncpy(copied_cmdline, task_info->tasks[i].cmdline, 255); strncpy(copied_cmdline, task_info->tasks[i].cmdline, 255);
......
...@@ -156,7 +156,7 @@ void shell_read_command(void) ...@@ -156,7 +156,7 @@ void shell_read_command(void)
char* input; char* input;
int i; int i;
asprintf(&prompt, "%s # ", cwd); asprintf(&prompt, "\033[1m%s #\033[0m ", cwd);
input = readline(prompt); input = readline(prompt);
if (input) { if (input) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment