[PATCH] Cute feature: colored printk output

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Jan Engelhardt
Date: Friday, October 5, 2007 - 12:13 pm

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:
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] Cute feature: colored printk output, Jan Engelhardt, (Fri Oct 5, 12:13 pm)
Re: [PATCH] Cute feature: colored printk output, Lennart Sorensen, (Fri Oct 5, 12:19 pm)
Re: [PATCH] Cute feature: colored printk output, Jan Engelhardt, (Fri Oct 5, 12:21 pm)
Re: [PATCH] Cute feature: colored printk output, Lennart Sorensen, (Fri Oct 5, 12:24 pm)
Re: [PATCH] Cute feature: colored printk output, Jan Engelhardt, (Fri Oct 5, 12:32 pm)
Re: [PATCH] Cute feature: colored printk output, Lennart Sorensen, (Fri Oct 5, 12:43 pm)
Re: [PATCH] Cute feature: colored printk output, Jan Engelhardt, (Fri Oct 5, 12:55 pm)
RE: [PATCH] Cute feature: colored printk output, Medve Emilian-EMMEDVE1, (Fri Oct 5, 1:23 pm)
Re: [PATCH] Cute feature: colored printk output, Krzysztof Halasa, (Fri Oct 5, 4:22 pm)
Re: [PATCH] Cute feature: colored printk output, Jan Engelhardt, (Fri Oct 5, 4:47 pm)
Re: [PATCH] Cute feature: colored printk output, Krzysztof Halasa, (Fri Oct 5, 5:10 pm)
Re: [PATCH] Cute feature: colored printk output, Jan Engelhardt, (Fri Oct 5, 5:23 pm)
Re: [PATCH] Cute feature: colored printk output, Jan Engelhardt, (Fri Oct 5, 5:26 pm)
Re: [PATCH] Cute feature: colored printk output, Ingo Molnar, (Sat Oct 6, 4:08 am)
Re: [PATCH] Cute feature: colored printk output, Krzysztof Halasa, (Sat Oct 6, 4:58 am)
Re: [PATCH] Cute feature: colored printk output, Dave Jones, (Sat Oct 6, 10:16 am)
Re: [PATCH] Cute feature: colored printk output, Oleg Verych, (Sat Oct 6, 11:09 am)
Re: [PATCH] Cute feature: colored printk output, Bill Davidsen, (Sat Oct 6, 12:53 pm)
Re: [PATCH] Cute feature: colored printk output, Jan Engelhardt, (Sat Oct 6, 1:01 pm)
Re: [PATCH] Cute feature: colored printk output, Miguel Botón, (Sat Oct 6, 2:19 pm)
Re: [PATCH] Cute feature: colored printk output, Bill Davidsen, (Sat Oct 6, 5:50 pm)
Re: [PATCH] Cute feature: colored printk output, Jan Engelhardt, (Sun Oct 7, 1:42 am)