summaryrefslogtreecommitdiff
path: root/console/console.c
diff options
context:
space:
mode:
authorMarcus Brinkmann <marcus@gnu.org>2002-06-24 01:05:27 +0000
committerMarcus Brinkmann <marcus@gnu.org>2002-06-24 01:05:27 +0000
commit52be5cefb4852e6c2921fd1b19c4d0b4952860ea (patch)
treec2c5d6d53248df64e218b6148a95c26825a5b5bf /console/console.c
parent98f81ca345424f0e3af7bd4c4eb492481b7f3573 (diff)
2002-06-24 Marcus Brinkmann <marcus@gnu.org>
* console.h (cons_color_t): New enum type replacing color macros. (CONS_COLOR_MAX): New macro. (cons_change_t): New type. (struct cons_display): New member CHANGES. * console.c: Include "console.h". (DEFAULT_FOREGROUND, DEFAULT_FOREGROUND_NAME, DEFAULT_BACKGROUND, DEFAULT_BACKGROUND_NAME): New macros. (struct cons): New members foreground and background. (vcons_lookup): Pass colors to display_create invocation. (new_node): Fix st_size for display node. (color_names): New array. (options): Add options to set default foreground and background color. (parse_color): New function. (parse_opt): Implement new options. (netfs_append_args): Add new options to output. (main): Set default colors. * Makefile (DIST_FILES): Remove target. (MIGSTUBS): Remove ourfs_notifyUser.o and add notifyServer.o. * display.c: Do not include "ourfs_notify_U.h". (struct modreq): New member PENDING. (struct notify): New structure. (struct display): New members FILEMOD_REQS_PENDING and NOTIFY_PORT. (pager_read_page): Hand out previously returned pages. (pager_unlock_page): Assert that this is not called. (notify_class, notify_bucket): New port class and bucket global variables. (nowait_file_changed): New function, modified from mig output. (do_mach_notify_port_deleted): New stub function. (do_mach_notify_port_destroyed): New stub function. (do_mach_notify_no_senders): New stub function. (do_mach_notify_dead_name): New stub function. (do_mach_notify_send_once): New stub function. (do_mach_notify_msg_accepted): New function. (service_notifications): New function. (display_notice_changes): Call nowait_file_changed with new argument. Initialize REQ->pending. (display_notice_filechange): Remove arguments except DISPLAY. Set PENDING flags in pending filemod requests. Call nowait_file_changed with new notify argument. If notification will be sent, move modreq structure to pending list. (display_flush_filechange): Rewritten to use ring buffer to store changes. (user_create): Initialize new members of struct cons_display. (display_init): Initialize notify_class and notify_bucket. (display_create): Accept new arguments for default colors. Initialize new members of struct display. (display_destroy): Remove pending filemod requests and destroy the notification port. Do not free the display structure memory. (display_destroy_complete): New function. * display.h: Add new arguments to prototype of display_create.
Diffstat (limited to 'console/console.c')
-rw-r--r--console/console.c90
1 files changed, 86 insertions, 4 deletions
diff --git a/console/console.c b/console/console.c
index 8500c84c..43f18e6e 100644
--- a/console/console.c
+++ b/console/console.c
@@ -39,6 +39,8 @@
#include "display.h"
#include "input.h"
+/* We include console.h for the color numbers. */
+#include "console.h"
const char *argp_program_version = STANDARD_HURD_VERSION (console);
@@ -50,6 +52,12 @@ int netfs_maxsymlinks = 16; /* Arbitrary. */
volatile struct mapped_time_value *console_maptime;
#define DEFAULT_ENCODING "ISO-8859-1"
+#define DEFAULT_FOREGROUND CONS_COLOR_WHITE
+/* For the help output. */
+#define DEFAULT_FOREGROUND_NAME "white"
+#define DEFAULT_BACKGROUND CONS_COLOR_BLACK
+/* For the help output. */
+#define DEFAULT_BACKGROUND_NAME "black"
/* A handle for a console device. */
@@ -91,6 +99,9 @@ struct cons
vcons_t vcons_list;
/* The encoding. */
char *encoding;
+ /* Default foreground and background colors. */
+ int foreground;
+ int background;
struct node *node;
mach_port_t underlying;
@@ -163,7 +174,8 @@ vcons_lookup (cons_t cons, int id, int create, vcons_t *r_vcons)
/* XXX Error checking. */
mutex_init (&vcons->lock);
- err = display_create (&vcons->display, cons->encoding ?: DEFAULT_ENCODING);
+ err = display_create (&vcons->display, cons->encoding ?: DEFAULT_ENCODING,
+ cons->foreground, cons->background);
if (err)
{
free (vcons->name);
@@ -302,7 +314,7 @@ new_node (struct node **np, vcons_t vcons, vcons_node_type type)
(*np)->nn_stat.st_mode |= S_IFREG;
(*np)->nn_stat.st_mode &= ~(S_IXUSR | S_IXGRP | S_IXOTH);
(*np)->nn_stat.st_size = 80*50 * (sizeof (wchar_t) + 4)
- + 11 * 4; /* XXX */
+ + 14 * 4 + 512 * 8; /* XXX */
break;
case VCONS_NODE_INPUT:
(*np)->nn_stat.st_ino = (vcons->id << 2) + 3;
@@ -1190,14 +1202,59 @@ netfs_S_file_notice_changes (struct protid *cred, mach_port_t notify)
}
+static const char *color_names[CONS_COLOR_MAX + 1] =
+ {
+ [CONS_COLOR_BLACK] = "black",
+ [CONS_COLOR_RED] = "red",
+ [CONS_COLOR_GREEN] = "green",
+ [CONS_COLOR_YELLOW] = "yellow",
+ [CONS_COLOR_BLUE] = "blue",
+ [CONS_COLOR_MAGENTA] = "magenta",
+ [CONS_COLOR_CYAN] = "cyan",
+ [CONS_COLOR_WHITE] = "white"
+ };
+
static const struct argp_option options[] =
{
- {"encoding", 'e', "NAME", 0, "Set encoding of virtual consoles to"
- " NAME (default `" DEFAULT_ENCODING "')" },
+ { "foreground",'f', "COLOR", 0, "Set foreground color to"
+ " COLOR (default `" DEFAULT_FOREGROUND_NAME "')" },
+ { "background",'b', "COLOR", 0, "Set background color to"
+ " COLOR (default `" DEFAULT_BACKGROUND_NAME "')" },
+ { "encoding", 'e', "NAME", 0, "Set encoding of virtual consoles to"
+ " NAME (default `" DEFAULT_ENCODING "')" },
{0}
};
static error_t
+parse_color (const char *name, int *number)
+{
+ if (isdigit (*name))
+ {
+ long int nr;
+ char *tail;
+
+ errno = 0;
+
+ nr = strtol (name, &tail, 0);
+ if (errno || &tail || nr < 0 || nr > CONS_COLOR_MAX)
+ return EINVAL;
+ *number = nr;
+ return 0;
+ }
+ else
+ {
+ int i;
+ for (i = 0; i <= CONS_COLOR_MAX; i++)
+ if (!strcmp (color_names[i], name))
+ {
+ *number = i;
+ return 0;
+ }
+ return EINVAL;
+ }
+}
+
+static error_t
parse_opt (int opt, char *arg, struct argp_state *state)
{
cons_t cons = state->input;
@@ -1218,6 +1275,11 @@ parse_opt (int opt, char *arg, struct argp_state *state)
mutex_unlock (&cons->lock);
break;
+ case 'f':
+ return parse_color (arg, &cons->foreground);
+ case 'b':
+ return parse_color (arg, &cons->background);
+
case 'e':
/* XXX Check validity of encoding. Can we perform all necessary
conversions? */
@@ -1252,6 +1314,24 @@ netfs_append_args (char **argz, size_t *argz_len)
else
err = errno;
}
+ if (cons->foreground != DEFAULT_FOREGROUND)
+ {
+ char *buf;
+ asprintf (&buf, "--foreground=%s", color_names[cons->foreground]);
+ if (buf)
+ err = argz_add (argz, argz_len, buf);
+ else
+ err = errno;
+ }
+ if (cons->background != DEFAULT_BACKGROUND)
+ {
+ char *buf;
+ asprintf (&buf, "--background=%s", color_names[cons->background]);
+ if (buf)
+ err = argz_add (argz, argz_len, buf);
+ else
+ err = errno;
+ }
return err;
}
@@ -1272,6 +1352,8 @@ main (int argc, char **argv)
error (1, ENOMEM, "Cannot create console structure");
mutex_init (&cons->lock);
cons->encoding = NULL;
+ cons->foreground = DEFAULT_FOREGROUND;
+ cons->background = DEFAULT_BACKGROUND;
cons->vcons_list = NULL;
root_nn.cons = cons;