summaryrefslogtreecommitdiff
path: root/console
diff options
context:
space:
mode:
authorMarcus Brinkmann <marcus@gnu.org>2002-08-29 23:57:44 +0000
committerMarcus Brinkmann <marcus@gnu.org>2002-08-29 23:57:44 +0000
commitf713724dc9049b3b7bb8bcc3d112747619c3fa13 (patch)
treeac6579c635ad3ffa7a4908d4bf48d34763d68dc4 /console
parentc19963fb7ad44ac4c5f908f3587e551c727c5be1 (diff)
2002-08-30 Marcus Brinkmann <marcus@gnu.org>
* display.c (display_create): Likewise. Set DISPLAY->attr.attr_def instead the color versions. (struct attr): Remove fgcol_def, bgcol_def, and add attr_def. (handle_esc_bracket_m): Set all attributes to their defaults for case 0. Set default color using default attribute for case 49 and case 39. (display_output_one): Likewise. * console.c (options): Add --attribute option. (parse_opt): Parse --attribute option. Bail out with argp_error on error. (netfs_append_args): ... (struct cons): Replace foreground and background with new attribute member. (vcons_lookup): Pass CONS->attribute to display_create instead CONS->foreground and CONS->background. (main): Set default colors and attributes. (parse_attributes): New function.
Diffstat (limited to 'console')
-rw-r--r--console/ChangeLog20
-rw-r--r--console/console.c178
-rw-r--r--console/display.c23
-rw-r--r--console/display.h2
4 files changed, 191 insertions, 32 deletions
diff --git a/console/ChangeLog b/console/ChangeLog
index 69830796..b5726620 100644
--- a/console/ChangeLog
+++ b/console/ChangeLog
@@ -1,3 +1,23 @@
+2002-08-30 Marcus Brinkmann <marcus@gnu.org>
+
+ * display.c (display_create): Likewise. Set
+ DISPLAY->attr.attr_def instead the color versions.
+ (struct attr): Remove fgcol_def, bgcol_def, and add attr_def.
+ (handle_esc_bracket_m): Set all attributes to their defaults for
+ case 0. Set default color using default attribute for case 49 and
+ case 39.
+ (display_output_one): Likewise.
+ * console.c (options): Add --attribute option.
+ (parse_opt): Parse --attribute option. Bail out with argp_error
+ on error.
+ (netfs_append_args): ...
+ (struct cons): Replace foreground and background with new
+ attribute member.
+ (vcons_lookup): Pass CONS->attribute to display_create instead
+ CONS->foreground and CONS->background.
+ (main): Set default colors and attributes.
+ (parse_attributes): New function.
+
2002-08-28 Marcus Brinkmann <marcus@gnu.org>
* display.c (screen_fill): Take CUR_LINES modulo LINES.
diff --git a/console/console.c b/console/console.c
index 204937f6..0e2ebbc9 100644
--- a/console/console.c
+++ b/console/console.c
@@ -55,6 +55,13 @@ int netfs_maxsymlinks = 16; /* Arbitrary. */
volatile struct mapped_time_value *console_maptime;
#define DEFAULT_ENCODING "ISO-8859-1"
+#define DEFAULT_INTENSITY CONS_ATTR_INTENSITY_NORMAL
+#define DEFAULT_UNDERLINED 0
+#define DEFAULT_BLINKING 0
+#define DEFAULT_REVERSED 0
+#define DEFAULT_CONCEALED 0
+/* For the help output. */
+#define DEFAULT_ATTRIBUTE_NAME "normal"
#define DEFAULT_FOREGROUND CONS_COLOR_WHITE
/* For the help output. */
#define DEFAULT_FOREGROUND_NAME "white"
@@ -109,10 +116,9 @@ struct cons
vcons_t vcons_list;
/* The encoding. */
char *encoding;
- /* Default foreground and background colors. */
- int foreground;
- int background;
-
+ /* Default attributes. */
+ conchar_attr_t attribute;
+
/* Requester of directory modification notifications. */
struct modreq *dirmod_reqs;
unsigned int dirmod_tick;
@@ -215,7 +221,7 @@ vcons_lookup (cons_t cons, int id, int create, vcons_t *r_vcons)
mutex_init (&vcons->lock);
err = display_create (&vcons->display, cons->encoding ?: DEFAULT_ENCODING,
- cons->foreground, cons->background);
+ cons->attribute);
if (err)
{
free (vcons->name);
@@ -1294,10 +1300,12 @@ static const char *color_names[CONS_COLOR_MAX + 1] =
static const struct argp_option options[] =
{
- { "foreground",'f', "COLOR", 0, "Set foreground color to"
+ { "foreground", 'f', "COLOR", 0, "Set foreground color to"
" COLOR (default `" DEFAULT_FOREGROUND_NAME "')" },
- { "background",'b', "COLOR", 0, "Set background color to"
+ { "background", 'b', "COLOR", 0, "Set background color to"
" COLOR (default `" DEFAULT_BACKGROUND_NAME "')" },
+ { "attribute", 'a', "ATTR[,...]", 0, "Set further default attributes"
+ " (default `" DEFAULT_ATTRIBUTE_NAME "')" },
{ "encoding", 'e', "NAME", 0, "Set encoding of virtual consoles to"
" NAME (default `" DEFAULT_ENCODING "')" },
{0}
@@ -1333,9 +1341,71 @@ parse_color (const char *name, int *number)
}
static error_t
+parse_attributes (const char *name, conchar_attr_t *attr)
+{
+ while (*name)
+ {
+ int value = 1;
+
+ if (!strncmp (name, "not-", 4))
+ {
+ value = 0;
+ name += 4;
+ }
+
+ if (!strncmp (name, "normal", 6))
+ {
+ name += 6;
+ if (value != 1)
+ return EINVAL;
+ attr->intensity = CONS_ATTR_INTENSITY_NORMAL;
+ }
+ else if (!strncmp (name, "bold", 4))
+ {
+ name += 4;
+ if (value != 1)
+ return EINVAL;
+ attr->intensity = CONS_ATTR_INTENSITY_BOLD;
+ }
+ else if (!strncmp (name, "dim", 3))
+ {
+ name += 3;
+ if (value != 1)
+ return EINVAL;
+ attr->intensity = CONS_ATTR_INTENSITY_DIM;
+ }
+ else if (!strncmp (name, "underlined", 10))
+ {
+ name += 10;
+ attr->underlined = value;
+ }
+ else if (!strncmp (name, "blinking", 8))
+ {
+ name += 8;
+ attr->blinking = value;
+ }
+ else if (!strncmp (name, "concealed", 9))
+ {
+ name += 9;
+ attr->concealed = value;
+ }
+ else
+ return EINVAL;
+
+ if (name[0] == ',')
+ name++;
+ else if (name[0] != '\0')
+ return EINVAL;
+ }
+ return 0;
+}
+
+static error_t
parse_opt (int opt, char *arg, struct argp_state *state)
{
cons_t cons = state->input;
+ error_t err;
+ int color = 0;
switch (opt)
{
@@ -1354,9 +1424,24 @@ parse_opt (int opt, char *arg, struct argp_state *state)
break;
case 'f':
- return parse_color (arg, &cons->foreground);
+ err = parse_color (arg, &color);
+ cons->attribute.fgcol = color;
+ if (err)
+ argp_error (state, "Invalid color name: %s", arg);
+ break;
+
case 'b':
- return parse_color (arg, &cons->background);
+ err = parse_color (arg, &color);
+ cons->attribute.bgcol = color;
+ if (err)
+ argp_error (state, "Invalid color name: %s", arg);
+ break;
+
+ case 'a':
+ err = parse_attributes (arg, &cons->attribute);
+ if (err)
+ argp_error (state, "Invalid attribute specifier: %s", arg);
+ break;
case 'e':
/* XXX Check validity of encoding. Can we perform all necessary
@@ -1382,6 +1467,11 @@ netfs_append_args (char **argz, size_t *argz_len)
{
error_t err = 0;
cons_t cons = netfs_root_node->nn->cons;
+ /* The longest possible is 61 characters long:
+ "normal,not-underlined,not-blinking,not-reversed,not-concealed". */
+ char attr_str[80] = "--attribute=";
+ char *attr = &attr_str[12];
+ char *attrp = attr;
if (cons->encoding && strcmp (cons->encoding, DEFAULT_ENCODING))
{
@@ -1392,24 +1482,75 @@ netfs_append_args (char **argz, size_t *argz_len)
else
err = errno;
}
- if (cons->foreground != DEFAULT_FOREGROUND)
+ if (!err && cons->attribute.fgcol != DEFAULT_FOREGROUND)
{
char *buf;
- asprintf (&buf, "--foreground=%s", color_names[cons->foreground]);
+ asprintf (&buf, "--foreground=%s", color_names[cons->attribute.fgcol]);
if (buf)
err = argz_add (argz, argz_len, buf);
else
err = errno;
}
- if (cons->background != DEFAULT_BACKGROUND)
+ if (!err && cons->attribute.bgcol != DEFAULT_BACKGROUND)
{
char *buf;
- asprintf (&buf, "--background=%s", color_names[cons->background]);
+ asprintf (&buf, "--background=%s", color_names[cons->attribute.bgcol]);
if (buf)
err = argz_add (argz, argz_len, buf);
else
err = errno;
- }
+ }
+ if (!err && cons->attribute.intensity != DEFAULT_INTENSITY)
+ {
+ if (attrp != attr)
+ *(attrp++) = ',';
+ switch (cons->attribute.intensity)
+ {
+ case CONS_ATTR_INTENSITY_NORMAL:
+ attrp = stpcpy (attrp, "normal");
+ break;
+ case CONS_ATTR_INTENSITY_BOLD:
+ attrp = stpcpy (attrp, "bold");
+ break;
+ case CONS_ATTR_INTENSITY_DIM:
+ attrp = stpcpy (attrp, "dim");
+ break;
+ }
+ }
+ if (!err && cons->attribute.underlined != DEFAULT_UNDERLINED)
+ {
+ if (attrp != attr)
+ *(attrp++) = ',';
+ if (!cons->attribute.underlined)
+ attrp = stpcpy (attrp, "not-");
+ attrp = stpcpy (attrp, "underlined");
+ }
+ if (!err && cons->attribute.blinking != DEFAULT_BLINKING)
+ {
+ if (attrp != attr)
+ *(attrp++) = ',';
+ if (!cons->attribute.blinking)
+ attrp = stpcpy (attrp, "not-");
+ attrp = stpcpy (attrp, "blinking");
+ }
+ if (!err && cons->attribute.reversed != DEFAULT_REVERSED)
+ {
+ if (attrp != attr)
+ *(attrp++) = ',';
+ if (!cons->attribute.reversed)
+ attrp = stpcpy (attrp, "not-");
+ attrp = stpcpy (attrp, "reversed");
+ }
+ if (!err && cons->attribute.concealed != DEFAULT_CONCEALED)
+ {
+ if (attrp != attr)
+ *(attrp++) = ',';
+ if (!cons->attribute.concealed)
+ attrp = stpcpy (attrp, "not-");
+ attrp = stpcpy (attrp, "concealed");
+ }
+ if (!err && attrp != attr)
+ err = argz_add (argz, argz_len, attr_str);
return err;
}
@@ -1750,8 +1891,13 @@ 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->attribute.intensity = DEFAULT_INTENSITY;
+ cons->attribute.underlined = DEFAULT_UNDERLINED;
+ cons->attribute.blinking = DEFAULT_BLINKING;
+ cons->attribute.reversed = DEFAULT_REVERSED;
+ cons->attribute.concealed = DEFAULT_CONCEALED;
+ cons->attribute.fgcol = DEFAULT_FOREGROUND;
+ cons->attribute.bgcol = DEFAULT_BACKGROUND;
cons->vcons_list = NULL;
cons->dirmod_reqs = NULL;
cons->dirmod_tick = 0;
diff --git a/console/display.c b/console/display.c
index 908a1d06..43e01e29 100644
--- a/console/display.c
+++ b/console/display.c
@@ -125,8 +125,7 @@ typedef struct output *output_t;
struct attr
{
- unsigned int bgcol_def;
- unsigned int fgcol_def;
+ conchar_attr_t attr_def;
conchar_attr_t current;
/* True if in alternate character set (ASCII graphic) mode. */
unsigned int altchar;
@@ -978,9 +977,7 @@ handle_esc_bracket_m (attr_t attr, int code)
{
case 0:
/* All attributes off: <sgr0>. */
- memset (&attr->current, 0, sizeof (conchar_attr_t));
- attr->current.fgcol = attr->fgcol_def;
- attr->current.bgcol = attr->bgcol_def;
+ attr->current = attr->attr_def;
attr->altchar = 0;
break;
case 1:
@@ -1041,7 +1038,7 @@ handle_esc_bracket_m (attr_t attr, int code)
break;
case 39:
/* Default foreground color; ANSI?. */
- attr->current.fgcol = attr->fgcol_def;
+ attr->current.fgcol = attr->attr_def.fgcol;
break;
case 40 ... 47:
/* Set background color: <setab>. */
@@ -1049,7 +1046,7 @@ handle_esc_bracket_m (attr_t attr, int code)
break;
case 49:
/* Default background color; ANSI?. */
- attr->current.bgcol = attr->bgcol_def;
+ attr->current.bgcol = attr->attr_def.bgcol;
break;
}
}
@@ -1519,9 +1516,7 @@ display_output_one (display_t display, wchar_t chr)
break;
case L'M': /* ECMA-48 <RIS>. */
/* Reset: <rs2>. */
- * (uint32_t *) &display->attr.current = 0;
- display->attr.current.bgcol = display->attr.bgcol_def;
- display->attr.current.fgcol = display->attr.fgcol_def;
+ display->attr.current = display->attr.attr_def;
display->attr.altchar = 0;
user->cursor.status = CONS_CURSOR_NORMAL;
/* Fall through. */
@@ -1681,7 +1676,7 @@ display_init (void)
being ENCODING. */
error_t
display_create (display_t *r_display, const char *encoding,
- int foreground, int background)
+ conchar_attr_t def_attr)
{
error_t err = 0;
display_t display;
@@ -1704,10 +1699,8 @@ display_create (display_t *r_display, const char *encoding,
display->notify_port->display = display;
mutex_init (&display->lock);
- display->attr.bgcol_def = background;
- display->attr.fgcol_def = foreground;
- display->attr.current.bgcol = display->attr.bgcol_def;
- display->attr.current.fgcol = display->attr.fgcol_def;
+ display->attr.attr_def = def_attr;
+ display->attr.current = display->attr.attr_def;
err = user_create (display, width, height, lines, L' ',
display->attr.current);
if (err)
diff --git a/console/display.h b/console/display.h
index 26430cd3..1fe6f6c0 100644
--- a/console/display.h
+++ b/console/display.h
@@ -31,7 +31,7 @@ void display_init (void);
/* Create a new virtual console display, with the system encoding
being ENCODING and the default colors being FOREGROUND and BACKGROUND. */
error_t display_create (display_t *r_display, const char *encoding,
- int foreground, int background);
+ conchar_attr_t attr);
/* Destroy the display DISPLAY. */
void display_destroy (display_t display);