* [kbd] Feature Request: add the setvtrgb utility
@ 2011-03-28 20:29 ` Dustin Kirkland
2011-04-01 23:39 ` Alexey Gladkov
0 siblings, 1 reply; 6+ messages in thread
From: Dustin Kirkland @ 2011-03-28 20:29 UTC (permalink / raw)
To: kbd; +Cc: Michael Schutte
[-- Attachment #1: Type: text/plain, Size: 1956 bytes --]
Howdy!
We're carrying a new feature in Ubuntu's kbd package, provided by a
neat little utility called /sbin/setvtrgb.
I recently became aware of a nifty little ioctl, ioctl(fd, PIO_CMAP,
cmap), which is able to dynamically modify the console colors in all
virtual terminals.
Providing this utility gives distributions, as well as interested
system administrators, a really convenient way to make the console's
color scheme easier on the eyes, or higher contrast for the
vision-impaired.
See the included manpage for detailed operation.
As for values, we are using the following values selected by the
Ubuntu Design Team, which are within the current Ubuntu color scheme:
/etc/vtrgb:
1,222,57,255,0,118,44,204,128,255,0,255,0,255,0,255
1,56,181,199,111,38,181,204,128,0,255,255,0,0,255,255
1,43,74,6,184,113,233,204,128,0,0,0,255,255,255,255
Alternatively, the stock, default Linux kernel's VGA values are:
0,170,0,170,0,170,0,170,85,255,85,255,85,255,85,255
0,0,170,85,0,0,170,170,85,85,255,255,85,85,255,255
0,0,0,0,170,170,170,170,85,85,85,85,255,255,255,255
You can place these values, or a modified version of them in a file,
and then run "sudo setvtrgb [FILE]" to test this. The three lines of
configuration represent 16 red values, 16 green values, and 16 blue
values. The format matches those exported by the kernel in sysfs.
See:
$ cat /sys/module/vt/parameters/default_{red,grn,blu}
I'm attaching a patch. You may choose to put something like the
following in a changelog entry if you apply my patch:
[ Dustin Kirkland <kirkland@ubuntu.com> ]
* src/setvtrgb.c, man/man8/setvtrgb.8, COPYING, debian/rules,
debian/copyright: LP: #730672
- Add a 'setvtrgb' utility to configure vt/console colors
- add to udeb (so that this can improve installer usability)
- add to /sbin, run by root
- update copyright statement
--
:-Dustin
Dustin Kirkland
Ubuntu Core Developer
[-- Attachment #2: kbd-setvtrgb.patch --]
[-- Type: text/x-patch, Size: 7903 bytes --]
diff -u kbd-1.15/debian/copyright kbd-1.15/debian/copyright
--- kbd-1.15/debian/copyright
+++ kbd-1.15/debian/copyright
@@ -63,0 +64,6 @@
+
+Files: setvtrgb.c
+Copyright © 2011 Canonical Ltd.
+License: GPL-2+
+Authors: Seth Forshee <seth.forshee@canonical.com>
+ Dustin Kirkland <kirkland@canonical.com>
diff -u kbd-1.15/debian/rules kbd-1.15/debian/rules
--- kbd-1.15/debian/rules
+++ kbd-1.15/debian/rules
@@ -4,12 +4,12 @@
KBD = $(TOPDIR)/debian/kbd
KBD_UDEB = $(TOPDIR)/debian/kbd-udeb
-UDEB_BINARIES = loadkeys kbd_mode setfont
+UDEB_BINARIES = loadkeys kbd_mode setfont setvtrgb
EXTRA_BINARIES = screendump setlogcons setvesablank
CONTRIB_BINARIES = codepage splitfont vcstime
MOVE_TO_BIN = kbd_mode setfont fgconsole openvt chvt dumpkeys unicode_start loadkeys
-MOVE_TO_SBIN = kbdrate
+MOVE_TO_SBIN = kbdrate setvtrgb
MOVE_TO_USR_SBIN = vcstime setvesablank
configure: configure-stamp
only in patch2:
unchanged:
--- kbd-1.15.orig/COPYING
+++ kbd-1.15/COPYING
@@ -28,6 +28,12 @@
(and changes to earlier mentioned programs)
are Copyright (C) 1994-1999 Andries E. Brouwer.
+The file
+ setvtrgb.c
+is Copyright (C) 2011 Canonical Ltd.
+ Authors: Seth Forshee <seth.forshee@canonical.com>
+ Dustin Kirkland <kirkland@canonical.com>
+
All files in this package may be freely copied under the terms
of the GNU General Public License (GPL), version 2, or at your
option any later version - except possibly for the restrictions
only in patch2:
unchanged:
--- kbd-1.15.orig/man/man8/setvtrgb.8
+++ kbd-1.15/man/man8/setvtrgb.8
@@ -0,0 +1,21 @@
+.\" @(#)man/man8/setvtrgb.8 1.0 Mar 3 12:32:18 CST 2011
+.TH SETVTRGB 8 "3 Mar 2011" "Set Virtual Terminal RGB Colors"
+.SH NAME
+setvtrgb \- set the virtual terminal RGB colors
+.SH SYNOPSIS
+.B setvtrgb
+.I vga|[FILE]
+.SH DESCRIPTION
+The
+.I setvtrgb
+command takes a single argument, either the string "vga", or a path to a file containing the red, green, and blue colors to be used by the Linux virtual terminals.
+
+If you use the FILE parameter, FILE should be exactly 3 lines of 16 comma-separated decimal values for RED, GREEN, and BLUE.
+
+To seed a valid FILE:
+ cat /sys/module/vt/parameters/default_{red,grn,blu} > FILE
+
+And then edit the values in FILE.
+
+.SH AUTHOR
+This manpage and the utility were written by Dustin Kirkland <kirkland@canonical.com> for Ubuntu systems (but may be used by others). Permission is granted to copy, distribute and/or modify this document and the utility under the terms of the GNU General Public License, Version 2 or any later version published by the Free Software Foundation. The complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL-2 on Debian/Ubuntu systems, or on the web at http://www.gnu.org/licenses/gpl2.txt.
only in patch2:
unchanged:
--- kbd-1.15.orig/man/man8/Makefile.am
+++ kbd-1.15/man/man8/Makefile.am
@@ -1,6 +1,6 @@
gen_MANS = loadunimap.8 mapscrn.8 setfont.8
dist_man_MANS = getkeycodes.8 kbdrate.8 resizecons.8 setkeycodes.8 \
- showconsolefont.8 $(gen_MANS)
+ showconsolefont.8 setvtrgb.8 $(gen_MANS)
install-data-hook:
cd $(DESTDIR)$(mandir)/man8 && \
only in patch2:
unchanged:
--- kbd-1.15.orig/src/Makefile.am
+++ kbd-1.15/src/Makefile.am
@@ -4,7 +4,7 @@
PROGS = \
dumpkeys loadkeys showkey setfont showconsolefont \
setleds setmetamode kbd_mode chvt deallocvt \
- psfxtable kbdrate fgconsole openvt
+ psfxtable kbdrate fgconsole openvt setvtrgb
if KEYCODES_PROGS
PROGS += getkeycodes setkeycodes
@@ -54,6 +54,7 @@
screendump_SOURCES = $(ALL_S) screendump.c $(XMAL_S)
setfont_SOURCES = $(ALL_S) setfont.c $(FIND_S) $(XMAL_S) $(GETFD_S) mapscrn.c $(KDMA_S) $(PSF_S) $(UTF8_S) kdfontop.c kdfontop.h $(UNIM_S)
setkeycodes_SOURCES = $(ALL_S) setkeycodes.c $(GETFD_S)
+setvtrgb_SOURCES = $(ALL_S) setvtrgb.c $(GETFD_S)
setlogcons_SOURCES = $(ALL_S) setlogcons.c $(GETFD_S)
setpalette_SOURCES = $(ALL_S) setpalette.c $(GETFD_S)
setvesablank_SOURCES = $(ALL_S) setvesablank.c $(GETFD_S)
only in patch2:
unchanged:
--- kbd-1.15.orig/src/setvtrgb.c
+++ kbd-1.15/src/setvtrgb.c
@@ -0,0 +1,136 @@
+/*
+ * setvtrgb - set the virtual terminal RGB colors
+ * Copyright (C) 2011 Canonical Ltd.
+ *
+ * Authors: Seth Forshee <seth.forshee@canonical.com>
+ * Dustin Kirkland <kirkland@canonical.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <linux/kd.h>
+#include <errno.h>
+
+/* Standard VGA terminal colors, matching those hardcoded in the Linux kernel's
+ * drivers/tty/vt/vt.c
+ */
+unsigned char vga_colors[] = {
+ 0x00, 0x00, 0x00,
+ 0xaa, 0x00, 0x00,
+ 0x00, 0xaa, 0x00,
+ 0xaa, 0x55, 0x00,
+ 0x00, 0x00, 0xaa,
+ 0xaa, 0x00, 0xaa,
+ 0x00, 0xaa, 0xaa,
+ 0xaa, 0xaa, 0xaa,
+ 0x55, 0x55, 0x55,
+ 0xff, 0x55, 0x55,
+ 0x55, 0xff, 0x55,
+ 0xff, 0xff, 0x55,
+ 0x55, 0x55, 0xff,
+ 0xff, 0x55, 0xff,
+ 0x55, 0xff, 0xff,
+ 0xff, 0xff, 0xff,
+};
+
+/* Usage statement */
+void usage(void) {
+ fprintf(stderr,
+"\nUSAGE: setvtrgb vga|[FILE]\n"
+"\n"
+"If you use the FILE parameter, FILE should be exactly 3 lines of\n"
+"comma-separated decimal values for RED, GREEN, and BLUE.\n"
+"\n"
+"To seed a valid FILE:\n"
+" cat /sys/module/vt/parameters/default_{red,grn,blu} > FILE\n"
+"\n"
+"And then edit the values in FILE.\n\n"
+);
+ exit(EINVAL);
+}
+
+int main(int argc, const char *argv[]) {
+ int fd;
+ FILE *fp = NULL;
+ int i, j;
+ char *c;
+ unsigned char *cmap;
+ char s[1024];
+
+ /* Must have at least one argument */
+ if (argc != 2)
+ usage();
+
+ if (strcmp(argv[1], "vga") == 0)
+ /* Use the Standard VGA colors */
+ cmap = vga_colors;
+ else if (fp = fopen(argv[1], "r" )) {
+ /* Use a color palette specified in a file */
+ /* Allocate a 48 character array */
+ cmap = calloc(3*16, sizeof(unsigned char));
+ for (i=0; i<3; i++) {
+ j = 0;
+ /* Retrieve a line from file */
+ /* Tokenize the CSV string, convert to int, then to char */
+ if (fgets(s, sizeof(s), fp)) {
+ if ((c = strtok(s, ",")) != NULL)
+ cmap[i+j*3] = (unsigned char)atoi(c);
+ else {
+ fprintf(stderr, "ERROR: Error reading color value at line [%d], position [%d], file [%s]\n", i+1, 1, argv[1]);
+ usage();
+ }
+ for (j=1; j<16; j++) {
+ if ((c = strtok(NULL, ",")) != NULL)
+ cmap[i+j*3] = (unsigned char)atoi(c);
+ else {
+ fprintf(stderr, "ERROR: Error reading color value at line [%d], position [%d], file [%s]\n", i+1, j+1, argv[1]);
+ usage();
+ }
+ }
+ } else {
+ fprintf(stderr, "ERROR: Invalid file at [%s]\n", argv[1]);
+ usage();
+ }
+ }
+ fclose(fp);
+ } else {
+ perror(argv[1]);
+ usage();
+ }
+
+ /* Ensure that this user can open tty, before going further */
+ fd = open("/dev/tty0", O_RDONLY);
+ if (fd < 0) {
+ perror(argv[1]);
+ exit(errno);
+ }
+
+ /* Apply the color map to the tty via ioctl */
+ if (ioctl(fd, PIO_CMAP, cmap) < 0) {
+ perror("ioctl");
+ exit(errno);
+ }
+ close(fd);
+ return(0);
+}
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [kbd] Feature Request: add the setvtrgb utility
2011-03-28 20:29 ` [kbd] Feature Request: add the setvtrgb utility Dustin Kirkland
@ 2011-04-01 23:39 ` Alexey Gladkov
0 siblings, 1 reply; 6+ messages in thread
From: Alexey Gladkov @ 2011-04-01 23:39 UTC (permalink / raw)
To: Linux console tools development discussion
Cc: Dustin Kirkland, Michael Schutte
[-- Attachment #1: Type: text/plain, Size: 485 bytes --]
29.03.2011 00:29, Dustin Kirkland wrote:
> We're carrying a new feature in Ubuntu's kbd package, provided by a
> neat little utility called /sbin/setvtrgb.
Thanks, I like the idea. I'm not quite happy with your implementation,
though:
I'm not sure that "char s[1024];" buffer is necessary;
Error diagnostics is difficult to understand;
Memory allocated by calloc() is never freed.
I wrote a different implementation (see attachment).
What do you think about it?
--
Rgrds, legion
[-- Attachment #2: setvtrgb.c --]
[-- Type: text/plain, Size: 3088 bytes --]
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <sys/ioctl.h>
#include <linux/kd.h>
#include <errno.h>
#include <error.h>
#include "getfd.h"
#include "nls.h"
#include "version.h"
static unsigned char *cmap;
/* Standard VGA terminal colors, matching those hardcoded in the Linux kernel's
* drivers/char/vt.c
*/
unsigned char vga_colors[] = {
0x00, 0x00, 0x00,
0xaa, 0x00, 0x00,
0x00, 0xaa, 0x00,
0xaa, 0x55, 0x00,
0x00, 0x00, 0xaa,
0xaa, 0x00, 0xaa,
0x00, 0xaa, 0xaa,
0xaa, 0xaa, 0xaa,
0x55, 0x55, 0x55,
0xff, 0x55, 0x55,
0x55, 0xff, 0x55,
0xff, 0xff, 0x55,
0x55, 0x55, 0xff,
0xff, 0x55, 0xff,
0x55, 0xff, 0xff,
0xff, 0xff, 0xff,
};
static void attr_noreturn
usage(int code)
{
fprintf(stderr,
_("Usage: %s vga|FILE|-\n"
"\n"
"If you use the FILE parameter, FILE should be exactly 3 lines of\n"
"comma-separated decimal values for RED, GREEN, and BLUE.\n"
"\n"
"To seed a valid FILE:\n"
" cat /sys/module/vt/parameters/default_{red,grn,blu} > FILE\n"
"\n"
"and then edit the values in FILE.\n"
"\n"),
progname);
exit(code);
}
static void
set_colormap(unsigned char *colormap)
{
int fd = getfd(NULL);
/* Apply the color map to the tty via ioctl */
if (ioctl(fd, PIO_CMAP, colormap) == -1)
error(EXIT_FAILURE, errno, "ioctl");
close(fd);
}
static void
parse_file(FILE *fd, const char *filename)
{
int c;
unsigned int rows, cols, val;
if ((cmap = calloc(3 * 16, sizeof(unsigned char))) == NULL)
error(EXIT_FAILURE, errno, "calloc");
for (rows = 0; rows < 3; rows++) {
cols = 0;
while (cols < 16) {
if ((c = fscanf(fd, "%u", &val)) != 1) {
if (c == EOF)
error(EXIT_FAILURE, errno, "fscanf");
error(EXIT_FAILURE, 0, _("Error: %s: Invalid value in field %u in line %u."),
filename, rows + 1, cols + 1);
}
cmap[rows + cols * 3] = (unsigned char) val;
if (cols < 15 && fgetc(fd) != ',')
error(EXIT_FAILURE, 0, _("Error: %s: Insufficient number of fields in line %u."),
filename, rows + 1);
cols++;
}
if ((c = fgetc(fd)) == EOF)
error(EXIT_FAILURE, 0, _("Error: %s: Line %u has ended unexpectedly.\n"),
filename, rows + 1);
if (c != '\n')
error(EXIT_FAILURE, 0, _("Error: %s: Line %u is too long.\n"),
filename, rows + 1);
}
}
int
main(int argc, char **argv) {
int c;
const char *file;
FILE *fd;
set_progname(argv[0]);
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE_NAME, LOCALEDIR);
textdomain(PACKAGE_NAME);
while ((c = getopt(argc, argv, "hV")) != EOF) {
switch (c) {
case 'V':
print_version_and_exit();
break;
case 'h':
usage(EXIT_SUCCESS);
break;
}
}
if (optind == argc)
usage(EXIT_FAILURE);
file = argv[optind];
if (!strcmp(file, "vga")) {
set_colormap(vga_colors);
return EXIT_SUCCESS;
} else if (!strcmp(file, "-")) {
parse_file(stdin, "stdin");
} else {
if ((fd = fopen(file, "r")) == NULL)
error(EXIT_FAILURE, errno, "fopen");
parse_file(fd, file);
fclose(fd);
}
set_colormap(cmap);
free(cmap);
return EXIT_SUCCESS;
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [kbd] Feature Request: add the setvtrgb utility
@ 2011-04-04 14:12 ` Alexey Gladkov
0 siblings, 1 reply; 6+ messages in thread
From: Alexey Gladkov @ 2011-04-04 14:12 UTC (permalink / raw)
To: Dustin Kirkland
Cc: Michael Schutte, Linux console tools development discussion
04.04.2011 17:42, Dustin Kirkland wrote:
> -static void attr_noreturn
> +static void
> usage(int code)
> {
> fprintf(stderr,
Yep. In this version forgotten kbd.h.
Look at this commit:
http://git.altlinux.org/people/legion/packages/kbd.git?p=kbd.git;a=commitdiff;h=74221133a1810895623d903a00c60b3de4294655
> Would you mind listing Seth Forshee <seth.forshee@canonical.com> and
> Dustin Kirkland <kirkland@canonical.com>, perhaps somewhere in the
> headers or contributor to this program?
Historically, all authors are listed in the COPYING. Of course, I have
listed you among the authors. Look at my commit.
Is it ok for you ?
--
Rgrds, legion
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [kbd] Feature Request: add the setvtrgb utility
@ 2011-04-04 14:49 ` Alexey Gladkov
2011-04-04 15:02 ` Dustin Kirkland
2011-04-04 16:38 ` Michael Schutte
1 sibling, 1 reply; 6+ messages in thread
From: Alexey Gladkov @ 2011-04-04 14:49 UTC (permalink / raw)
To: Dustin Kirkland
Cc: Seth Forshee, Michael Schutte,
Linux console tools development discussion
04.04.2011 18:24, Dustin Kirkland wrote:
>> Historically, all authors are listed in the COPYING. Of course, I have
>> listed you among the authors. Look at my commit.
>>
>> Is it ok for you ?
>
> Looks good! Thanks so much for being a great upstream, reviewing,
> rewriting, and accepting this upstream in such a timely manner ;-)
>
> Do you have any roadmap or schedule for the next kbd release that
> would include this utility?
I'd really like to solve the problem of duplication of names of files
in directories (it's the goal for 1.6). I am currently working on
optimizing loadkeys. If you need this utility I can do an 1.15.3
release. But I need help to test the refs/heads/loadkeys branch.
--
Rgrds, legion
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [kbd] Feature Request: add the setvtrgb utility
2011-04-04 14:49 ` Alexey Gladkov
@ 2011-04-04 15:02 ` Dustin Kirkland
0 siblings, 0 replies; 6+ messages in thread
From: Dustin Kirkland @ 2011-04-04 15:02 UTC (permalink / raw)
To: Alexey Gladkov
Cc: Seth Forshee, Michael Schutte,
Linux console tools development discussion
On Mon, Apr 4, 2011 at 9:49 AM, Alexey Gladkov <gladkov.alexey@gmail.com> wrote:
> 04.04.2011 18:24, Dustin Kirkland wrote:
>>> Historically, all authors are listed in the COPYING. Of course, I have
>>> listed you among the authors. Look at my commit.
>>>
>>> Is it ok for you ?
>>
>> Looks good! Thanks so much for being a great upstream, reviewing,
>> rewriting, and accepting this upstream in such a timely manner ;-)
>>
>> Do you have any roadmap or schedule for the next kbd release that
>> would include this utility?
>
> I'd really like to solve the problem of duplication of names of files
> in directories (it's the goal for 1.6). I am currently working on
> optimizing loadkeys. If you need this utility I can do an 1.15.3
> release. But I need help to test the refs/heads/loadkeys branch.
It's not urgent, per se. We're carrying the diff we need in Ubuntu
for now. Ideally, we'll re-sync Ubuntu with Debian in ~3 months or
so. Hopefully by that time, a) you've released 1.6 or a 1.15.3, and
b) the Debian maintainer (Michael Schutte on CC) has merged your new
release into Debian's unstable.
--
:-Dustin
Dustin Kirkland
Ubuntu Core Developer
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [kbd] Feature Request: add the setvtrgb utility
2011-04-04 14:49 ` Alexey Gladkov
@ 2011-04-04 16:38 ` Michael Schutte
1 sibling, 0 replies; 6+ messages in thread
From: Michael Schutte @ 2011-04-04 16:38 UTC (permalink / raw)
To: Linux console tools development discussion; +Cc: Dustin Kirkland
[-- Attachment #1: Type: text/plain, Size: 545 bytes --]
Alexey,
On Mon, Apr 04, 2011 at 09:24:01AM -0500, Dustin Kirkland wrote:
> Looks good! Thanks so much for being a great upstream, reviewing,
> rewriting, and accepting this upstream in such a timely manner ;-)
Same from me, thanks a lot for being so responsive! We really
appreciate that in the downstream department :-)
Cheers,
--
Michael Schutte | michi@{uiae.at,debian.org}
Innsbruck, Austria | happily accepting encrypted mail
OpenPGP: 0x16fb 517b a866 c3f6 8f11 1485 f3e4 122f 1D8C 261A
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 490 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-04-04 16:38 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-28 20:29 ` [kbd] Feature Request: add the setvtrgb utility Dustin Kirkland
2011-04-01 23:39 ` Alexey Gladkov
2011-04-04 14:12 ` Alexey Gladkov
2011-04-04 14:49 ` Alexey Gladkov
2011-04-04 15:02 ` Dustin Kirkland
2011-04-04 16:38 ` Michael Schutte
Linux console tools development discussion
This inbox may be cloned and mirrored by anyone:
git clone --mirror http://lore.altlinux.org/kbd/0 kbd/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 kbd kbd/ http://lore.altlinux.org/kbd \
kbd@lists.altlinux.org kbd@lists.altlinux.ru kbd@lists.altlinux.com
public-inbox-index kbd
Example config snippet for mirrors.
Newsgroup available over NNTP:
nntp://lore.altlinux.org/org.altlinux.lists.kbd
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git