Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 17 Aug 2017 18:08:45 +0000 (UTC)
From:      Bruce Evans <bde@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r322626 - head/usr.sbin/vidcontrol
Message-ID:  <201708171808.v7HI8jeR061291@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: bde
Date: Thu Aug 17 18:08:45 2017
New Revision: 322626
URL: https://svnweb.freebsd.org/changeset/base/322626

Log:
  Update vidcontrol -c to support all cursor appearance setting
  capabilities.
  
  Most of the capabilities (all of the arcane ones) were in FreeBSD-2.0.5,
  but were harder to use then, and vidcontrol didn't try.  FreeBSD-4.1.0
  added per-vty support, fixed the destructivness of the "destructive"
  cursor, and improved APIs.  Start using the new APIs, support all of
  their capabilities, and document all of the capabilities and some of
  the historical mistakes.
  
  vt doesn't support any of this before or after the change.
  
  Fix minor unrelated bitrot in the usage message for the syscons case.

Modified:
  head/usr.sbin/vidcontrol/vidcontrol.1
  head/usr.sbin/vidcontrol/vidcontrol.c

Modified: head/usr.sbin/vidcontrol/vidcontrol.1
==============================================================================
--- head/usr.sbin/vidcontrol/vidcontrol.1	Thu Aug 17 17:17:28 2017	(r322625)
+++ head/usr.sbin/vidcontrol/vidcontrol.1	Thu Aug 17 18:08:45 2017	(r322626)
@@ -125,15 +125,123 @@ Set border color to
 This option may not be always supported by the video driver.
 .It Fl C
 Clear the history buffer.
-.It Fl c Cm normal | blink | destructive
+.It Fl c Ar setting Ns Op , Ns Ar setting ...
 Change the cursor appearance.
-The cursor is either an inverting block
-.Pq Cm normal
-that can optionally
-.Cm blink ,
-or it can be like the old hardware cursor
-.Pq Cm destructive .
-The latter is actually a simulation.
+The change is specified by a non-empty comma-separated list of
+.Cm setting Ns s .
+Each
+.Cm setting
+overrides or modifies previous ones in left to right order.
+.Pp
+The following override
+.Cm setting Ns s
+are available:
+.Bl -tag -width indent
+.It Cm block
+Set to a block covering 1 character cell,
+with a configuration-dependent coloring
+that should be at worst inverse video.
+.It Cm blinkingblock
+Set to a blinking
+.Cm block .
+.It Cm underline
+Set to
+.Cm height
+scanlines starting at
+.Cm base .
+This only gives an underline in normal configurations.
+.It Cm blinkingunderline
+Set to a blinking
+.Cm underline .
+.It Cm base Ns = Ns Ar value, Cm height Ns = Ns Ar value
+Set the specified scanline parameters.
+These parameters are only active in so-called
+.Cm char ( underline )
+mode.
+.Cm value
+is an integer in any base supported by
+.Xr strtol 3 .
+Setting
+.Cm height
+to 0 turns off the cursor in
+.Cm char
+mode.
+Negative
+.Ar value Ns s
+are silently ignored.
+Positive
+.Ar value Ns s
+are clamped to fit in the character cell when the cursor is drawn.
+.El
+.Pp
+The following override
+.Cm setting Ns s
+are provided for backwards compatibility:
+.Bl -tag -width indent
+.It Cm normal
+Old name for
+.Cm block .
+.It Cm blink
+Old name for
+.Cm blinkingblock .
+.It Cm destructive
+Bad old name for
+.Cm blinkingunderline .
+The so-called
+.Cm destructive
+cursor was only destructive due to a bug that was fixed in
+.Fx 4.1.0 .
+The destruction in the non-blinking case was so large that
+this case was not supported by
+.Nm ,
+so no backwards compatible name is needed for this case.
+.El
+.Pp
+The following modifier
+.Cm setting Ns s
+are available:
+.Bl -tag -width indent
+.It Cm blinking , noblinking
+Set or clear the blinking attribute.
+.It Cm char , nochar
+Set or clear the so-called
+.Cm char
+attribute.
+Names in this section follow the bad old names of
+flags in the implementation.
+.Cm char
+now means
+.Do
+activate the scanline parameters,
+and implement them using the best available method
+(at worst, actually use the old
+.Cm char
+method with its destruction fixed if it is configured,
+else silently ignore this flag).
+.Dc
+.It Cm hidden , nohidden
+Set or clear the hidden attribute.
+.It Cm local
+Apply the changes (except for the
+.Cm local
+and
+.Cm reset
+control flags)
+to the current vty.
+The default is to apply them to all vtys.
+.It Cm reset
+Reset everything.
+The default is to not reset.
+When the
+.Cm local
+parameter is specified, the resetting is for the 
+current local settings to the current global settings.
+Otherwise, the resetting is for the current global
+settings to defaults configured a boot time.
+Beware that the scanline parameters and not automatically
+scaled by the font size and resetting tends to undo manual
+fixups for this.
+.El
 .It Fl d
 Print out current output screen map.
 .It Xo

Modified: head/usr.sbin/vidcontrol/vidcontrol.c
==============================================================================
--- head/usr.sbin/vidcontrol/vidcontrol.c	Thu Aug 17 17:17:28 2017	(r322625)
+++ head/usr.sbin/vidcontrol/vidcontrol.c	Thu Aug 17 18:08:45 2017	(r322626)
@@ -200,12 +200,13 @@ usage(void)
 "                  [-S on | off] [-s number] [-T xterm | cons25] [-t N | off]",
 "                  [mode] [foreground [background]] [show]");
 	else
-		fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n",
+		fprintf(stderr, "%s\n%s\n%s\n%s\n%s%s\n\n",
 "usage: vidcontrol [-CdHLPpx] [-b color] [-c appearance] [-f [size] file]",
-"                  [-g geometry] [-h size] [-i adapter | mode] [-l screen_map]",
-"                  [-M char] [-m on | off] [-r foreground background]",
-"                  [-S on | off] [-s number] [-T xterm | cons25] [-t N | off]",
-"                  [mode] [foreground [background]] [show]");
+"                  [-g geometry] [-h size] [-i active | adapter | mode]",
+"                  [-l screen_map] [-M char] [-m on | off]",
+"                  [-r foreground background] [-S on | off] [-s number]",
+"                  [-T xterm | cons25] [-t N | off] [mode]",
+"                  [foreground [background]] [show]");
 	exit(1);
 }
 
@@ -619,30 +620,85 @@ set_screensaver_timeout(char *arg)
 	}
 }
 
+static void
+parse_cursor_params(char *param, struct cshape *shape)
+{
+	char *dupparam, *word;
+	int type;
 
+	param = dupparam = strdup(param);
+	type = shape->shape[0];
+	while ((word = strsep(&param, ",")) != NULL) {
+		if (strcmp(word, "block") == 0)
+			type = 0;
+		else if (strcmp(word, "underline") == 0)
+			type = CONS_CHAR_CURSOR;
+		else if (strcmp(word, "blinkingblock") == 0)
+			type = CONS_BLINK_CURSOR;
+		else if (strcmp(word, "blinkingunderline") == 0)
+			type = CONS_BLINK_CURSOR | CONS_CHAR_CURSOR;
+		else if (strncmp(word, "base=", 5) == 0)
+			shape->shape[1] = strtol(word + 5, NULL, 0);
+		else if (strncmp(word, "height=", 7) == 0)
+			shape->shape[2] = strtol(word + 7, NULL, 0);
+		else if (strcmp(word, "blinking") == 0)
+			type |= CONS_BLINK_CURSOR;
+		else if (strcmp(word, "normal") == 0)
+			type = 0;
+		else if (strcmp(word, "blink") == 0)
+			type = CONS_BLINK_CURSOR;
+		else if (strcmp(word, "destructive") == 0)
+			type = CONS_BLINK_CURSOR | CONS_CHAR_CURSOR;
+		else if (strcmp(word, "noblinking") == 0)
+			type &= ~CONS_BLINK_CURSOR;
+		else if (strcmp(word, "char") == 0)
+			type |= CONS_CHAR_CURSOR;
+		else if (strcmp(word, "nochar") == 0)
+			type &= ~CONS_CHAR_CURSOR;
+		else if (strcmp(word, "hidden") == 0)
+			type |= CONS_HIDDEN_CURSOR;
+		else if (strcmp(word, "nohidden") == 0)
+			type &= ~CONS_HIDDEN_CURSOR;
+		else if (strcmp(word, "local") == 0)
+			type |= CONS_LOCAL_CURSOR;
+		else if (strcmp(word, "reset") == 0)
+			type |= CONS_RESET_CURSOR;
+		else {
+			revert();
+			errx(1,
+			    "invalid parameters for -c starting at '%s%s%s'",
+			    word, param != NULL ? "," : "",
+			    param != NULL ? param : "");
+		}
+	}
+	free(dupparam);
+	shape->shape[0] = type;
+}
+
+
 /*
  * Set the cursor's shape/type.
  */
 
 static void
-set_cursor_type(char *appearance)
+set_cursor_type(char *param)
 {
-	int type;
+	struct cshape shape;
 
-	if (!strcmp(appearance, "normal"))
-		type = 0;
-	else if (!strcmp(appearance, "blink"))
-		type = 1;
-	else if (!strcmp(appearance, "destructive"))
-		type = 3;
-	else {
+	/* Determine if the new setting is local (default to non-local). */
+	shape.shape[0] = 0;
+	parse_cursor_params(param, &shape);
+
+	/* Get the relevant shape (the local flag is the only input arg). */
+	if (ioctl(0, CONS_GETCURSORSHAPE, &shape) != 0) {
 		revert();
-		errx(1, "argument to -c must be normal, blink or destructive");
+		err(1, "ioctl(CONS_GETCURSORSHAPE)");
 	}
 
-	if (ioctl(0, CONS_CURSORTYPE, &type) == -1) {
+	parse_cursor_params(param, &shape);
+	if (ioctl(0, CONS_SETCURSORSHAPE, &shape) != 0) {
 		revert();
-		err(1, "setting cursor type");
+		err(1, "ioctl(CONS_SETCURSORSHAPE)");
 	}
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201708171808.v7HI8jeR061291>