public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Cute feature: colored printk output
@ 2007-10-05 19:13 Jan Engelhardt
  2007-10-05 19:19 ` Lennart Sorensen
                   ` (5 more replies)
  0 siblings, 6 replies; 22+ messages in thread
From: Jan Engelhardt @ 2007-10-05 19:13 UTC (permalink / raw)
  To: Linux Kernel Mailing List; +Cc: Andrew Morton


Colored kernel message output

Let's work more on Linux's cuteness! [http://lkml.org/lkml/2007/10/4/431]
The following patch makes it possible to give kernel messages a
selectable color which helps to distinguish it from other noise,
such as boot messages. NetBSD has it, OpenBSD has it, FreeBSD to some
extent, so I think Linux should too.

Inspired by cko (http://freshmeat.net/p/cko/), but independently
written, later contributed forth and back.

Already posted at: http://lkml.org/lkml/2007/4/1/162

Signed-off-by: Jan Engelhardt <jengelh@gmx.de>

---
 drivers/char/Kconfig |   29 +++++++++++++++++++++++++++++
 drivers/char/vt.c    |   14 ++++++++++++++
 2 files changed, 43 insertions(+)

Index: linux-2.6.23/drivers/char/Kconfig
===================================================================
--- linux-2.6.23.orig/drivers/char/Kconfig
+++ linux-2.6.23/drivers/char/Kconfig
@@ -58,6 +58,35 @@ config VT_CONSOLE
 
 	  If unsure, say Y.
 
+config VT_PRINTK_COLOR
+	hex "Colored kernel message output"
+	range 0x00 0xFF
+	depends on VT_CONSOLE
+	default 0x17
+	---help---
+	This option will give you ability to change the color of
+	kernel messages printed to the console.
+
+	The value you need to enter here is the ASCII color value
+	composed (OR'ed) by one foreground color, one background
+	color and any number of attributes as follows:
+
+	Foreground:
+	0x00=black, 0x01=blue, 0x02=green, 0x03=green,
+	0x04=red, 0x05=magenta, 0x06=brown, 0x07=gray
+
+	Background:
+	0x00=black, 0x10=blue, 0x20=green, 0x30=green,
+	0x40=red, 0x50=magenta, 0x60=brown, 0x70=gray
+
+	Attributes:
+	0x08=highlight foreground
+
+	Thus, 0x17 will yield gray-on-blue like in OpenBSD and
+	0x02 green-on-black like in NetBSD.
+	Using "highlight foreground" is said not work when you use
+	VGA Console (Framebuffer not affected) with a 512-glyph font.
+
 config HW_CONSOLE
 	bool
 	depends on VT && !S390 && !UML
Index: linux-2.6.23/drivers/char/vt.c
===================================================================
--- linux-2.6.23.orig/drivers/char/vt.c
+++ linux-2.6.23/drivers/char/vt.c
@@ -73,6 +73,7 @@
  */
 
 #include <linux/module.h>
+#include <linux/moduleparam.h>
 #include <linux/types.h>
 #include <linux/sched.h>
 #include <linux/tty.h>
@@ -2348,6 +2349,9 @@ struct tty_driver *console_driver;
 
 #ifdef CONFIG_VT_CONSOLE
 
+static unsigned int printk_color = CONFIG_VT_PRINTK_COLOR;
+module_param(printk_color, uint, S_IRUGO | S_IWUSR);
+
 /*
  *	Console on virtual terminal
  *
@@ -2388,12 +2392,16 @@ static void vt_console_print(struct cons
 		hide_cursor(vc);
 
 	start = (ushort *)vc->vc_pos;
+	vc->vc_color = printk_color;
+	update_attr(vc);
 
 	/* Contrived structure to try to emulate original need_wrap behaviour
 	 * Problems caused when we have need_wrap set on '\n' character */
 	while (count--) {
 		c = *b++;
 		if (c == 10 || c == 13 || c == 8 || vc->vc_need_wrap) {
+			vc->vc_color = vc->vc_def_color;
+			update_attr(vc);
 			if (cnt > 0) {
 				if (CON_IS_VISIBLE(vc))
 					vc->vc_sw->con_putcs(vc, start, cnt, vc->vc_y, vc->vc_x);
@@ -2406,6 +2414,8 @@ static void vt_console_print(struct cons
 				bs(vc);
 				start = (ushort *)vc->vc_pos;
 				myx = vc->vc_x;
+				vc->vc_color = printk_color;
+				update_attr(vc);
 				continue;
 			}
 			if (c != 13)
@@ -2413,6 +2423,8 @@ static void vt_console_print(struct cons
 			cr(vc);
 			start = (ushort *)vc->vc_pos;
 			myx = vc->vc_x;
+			vc->vc_color = printk_color;
+			update_attr(vc);
 			if (c == 10 || c == 13)
 				continue;
 		}
@@ -2434,6 +2446,8 @@ static void vt_console_print(struct cons
 			vc->vc_need_wrap = 1;
 		}
 	}
+	vc->vc_color = vc->vc_def_color;
+	update_attr(vc);
 	set_cursor(vc);
 
 quit:

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2007-10-07  8:43 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-05 19:13 [PATCH] Cute feature: colored printk output Jan Engelhardt
2007-10-05 19:19 ` Lennart Sorensen
2007-10-05 19:21   ` Jan Engelhardt
2007-10-05 19:24     ` Lennart Sorensen
2007-10-05 19:32       ` Jan Engelhardt
2007-10-05 19:43         ` Lennart Sorensen
2007-10-05 19:55           ` Jan Engelhardt
2007-10-05 20:23 ` Medve Emilian-EMMEDVE1
2007-10-05 23:22 ` Krzysztof Halasa
2007-10-05 23:47   ` Jan Engelhardt
2007-10-06  0:10     ` Krzysztof Halasa
2007-10-06  0:23       ` Jan Engelhardt
2007-10-06  0:26         ` Jan Engelhardt
2007-10-06 11:58           ` Krzysztof Halasa
2007-10-06 11:08 ` Ingo Molnar
2007-10-06 17:16   ` Dave Jones
2007-10-06 18:09   ` Oleg Verych
2007-10-06 19:53 ` Bill Davidsen
2007-10-06 20:01   ` Jan Engelhardt
2007-10-07  0:50     ` Bill Davidsen
2007-10-07  8:42       ` Jan Engelhardt
2007-10-06 21:19 ` Miguel Botón

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox