public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Rob Clark <robdclark@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v1 08/12] efi_loader: console support for color attributes
Date: Sun, 10 Sep 2017 09:22:29 -0400	[thread overview]
Message-ID: <20170910132236.14318-9-robdclark@gmail.com> (raw)
In-Reply-To: <20170910132236.14318-1-robdclark@gmail.com>

Shell.efi uses this, and supporting color attributes makes things look
nicer.  Map the EFI fg/bg color attributes to ANSI escape sequences.
Not all colors have a perfect match, but spec just says "Devices
supporting a different number of text colors are required to emulate the
above colors to the best of the device’s capabilities".

Signed-off-by: Rob Clark <robdclark@gmail.com>
---
 include/efi_api.h            | 29 +++++++++++++++++++++++++++++
 lib/efi_loader/efi_console.c | 30 ++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+)

diff --git a/include/efi_api.h b/include/efi_api.h
index 87c8ffe68e..3cc1dbac2e 100644
--- a/include/efi_api.h
+++ b/include/efi_api.h
@@ -426,6 +426,35 @@ struct simple_text_output_mode {
 	EFI_GUID(0x387477c2, 0x69c7, 0x11d2, \
 		 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
 
+#define EFI_BLACK                0x00
+#define EFI_BLUE                 0x01
+#define EFI_GREEN                0x02
+#define EFI_CYAN                 0x03
+#define EFI_RED                  0x04
+#define EFI_MAGENTA              0x05
+#define EFI_BROWN                0x06
+#define EFI_LIGHTGRAY            0x07
+#define EFI_BRIGHT               0x08
+#define EFI_DARKGRAY             0x08
+#define EFI_LIGHTBLUE            0x09
+#define EFI_LIGHTGREEN           0x0a
+#define EFI_LIGHTCYAN            0x0b
+#define EFI_LIGHTRED             0x0c
+#define EFI_LIGHTMAGENTA         0x0d
+#define EFI_YELLOW               0x0e
+#define EFI_WHITE                0x0f
+#define EFI_BACKGROUND_BLACK     0x00
+#define EFI_BACKGROUND_BLUE      0x10
+#define EFI_BACKGROUND_GREEN     0x20
+#define EFI_BACKGROUND_CYAN      0x30
+#define EFI_BACKGROUND_RED       0x40
+#define EFI_BACKGROUND_MAGENTA   0x50
+#define EFI_BACKGROUND_BROWN     0x60
+#define EFI_BACKGROUND_LIGHTGRAY 0x70
+
+#define EFI_ATTR_FG(attr)        ((attr) & 0x0f)
+#define EFI_ATTR_BG(attr)        (((attr) >> 4) & 0x7)
+
 struct efi_simple_text_output_protocol {
 	void *reset;
 	efi_status_t (EFIAPI *output_string)(
diff --git a/lib/efi_loader/efi_console.c b/lib/efi_loader/efi_console.c
index 2e13fdc096..fcd65ca488 100644
--- a/lib/efi_loader/efi_console.c
+++ b/lib/efi_loader/efi_console.c
@@ -316,12 +316,42 @@ static efi_status_t EFIAPI efi_cout_set_mode(
 	return EFI_EXIT(EFI_SUCCESS);
 }
 
+static const struct {
+	unsigned fg;
+	unsigned bg;
+} color[] = {
+	{ 30, 40 },     /* 0: black */
+	{ 34, 44 },     /* 1: blue */
+	{ 32, 42 },     /* 2: green */
+	{ 36, 46 },     /* 3: cyan */
+	{ 31, 41 },     /* 4: red */
+	{ 35, 45 },     /* 5: magenta */
+	{ 30, 40 },     /* 6: brown, map to black */
+	{ 37, 47 },     /* 7: light grey, map to white */
+	{ 37, 47 },     /* 8: bright, map to white */
+	{ 34, 44 },     /* 9: light blue, map to blue */
+	{ 32, 42 },     /* A: light green, map to green */
+	{ 36, 46 },     /* B: light cyan, map to cyan */
+	{ 31, 41 },     /* C: light red, map to red */
+	{ 35, 45 },     /* D: light magenta, map to magenta */
+	{ 33, 43 },     /* E: yellow */
+	{ 37, 47 },     /* F: white */
+};
+
 static efi_status_t EFIAPI efi_cout_set_attribute(
 			struct efi_simple_text_output_protocol *this,
 			unsigned long attribute)
 {
+	unsigned fg = EFI_ATTR_FG(attribute);
+	unsigned bg = EFI_ATTR_BG(attribute);
+
 	EFI_ENTRY("%p, %lx", this, attribute);
 
+	if (attribute)
+		printf(ESC"[%u;%um", color[fg].fg, color[bg].bg);
+	else
+		printf(ESC"[37;40m");
+
 	/* Just ignore attributes (colors) for now */
 	return EFI_EXIT(EFI_UNSUPPORTED);
 }
-- 
2.13.5

  parent reply	other threads:[~2017-09-10 13:22 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-10 13:22 [U-Boot] [PATCH v1 00/12] efi_loader+video: support for Shell.efi Rob Clark
2017-09-10 13:22 ` [U-Boot] [PATCH v1 01/12] efi_loader: add stub EFI_DEVICE_PATH_UTILITIES_PROTOCOL Rob Clark
2017-10-04 17:13   ` Heinrich Schuchardt
2017-10-04 17:29     ` Heinrich Schuchardt
2017-10-04 18:00     ` Heinrich Schuchardt
2017-09-10 13:22 ` [U-Boot] [PATCH v1 02/12] efi_loader: add stub HII protocols Rob Clark
2017-10-04 17:45   ` Heinrich Schuchardt
2017-10-04 17:59     ` Heinrich Schuchardt
2017-09-10 13:22 ` [U-Boot] [PATCH v1 03/12] efi_loader: add EFI_UNICODE_COLLATION_PROTOCOL stub Rob Clark
2017-10-04 17:57   ` Heinrich Schuchardt
2017-10-04 18:35     ` Rob Clark
2017-10-04 18:57       ` Heinrich Schuchardt
2017-10-04 19:02         ` Heinrich Schuchardt
2017-10-04 19:01       ` Peter Jones
2017-09-10 13:22 ` [U-Boot] [PATCH v1 04/12] efi_loader: start fleshing out HII Rob Clark
2017-09-10 13:22 ` [U-Boot] [PATCH v1 05/12] efi_loader: flesh out unicode protocol Rob Clark
2017-09-10 13:22 ` [U-Boot] [PATCH v1 06/12] efi_loader: start fleshing out efi_device_path_utilities Rob Clark
2017-09-10 13:22 ` [U-Boot] [PATCH v1 07/12] efi_loader: SIMPLE_TEXT_INPUT_EX plus wire up objects properly Rob Clark
2017-09-10 13:22 ` Rob Clark [this message]
2017-10-04 18:53   ` [U-Boot] [PATCH v1 08/12] efi_loader: console support for color attributes Heinrich Schuchardt
2017-10-04 20:54     ` Rob Clark
2017-10-04 22:01       ` Heinrich Schuchardt
2017-10-04 23:19         ` Rob Clark
2017-10-04 23:53           ` Heinrich Schuchardt
2017-10-05  0:00             ` Rob Clark
2017-10-05  0:12               ` Rob Clark
2017-10-05  0:33                 ` Heinrich Schuchardt
2017-09-10 13:22 ` [U-Boot] [PATCH v1 09/12] dm: video: Fix cache flushes Rob Clark
2017-10-04 19:29   ` Heinrich Schuchardt
2017-09-10 13:22 ` [U-Boot] [PATCH v1 10/12] dm: video: Add basic ANSI escape sequence support Rob Clark
2017-09-12 12:30   ` Simon Glass
2017-09-12 13:06     ` Rob Clark
2017-09-10 13:22 ` [U-Boot] [PATCH v1 11/12] dm: video: Add color " Rob Clark
2017-09-10 13:22 ` [U-Boot] [PATCH v1 12/12] HACK: efi_loader: hacks for SCT Rob Clark

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170910132236.14318-9-robdclark@gmail.com \
    --to=robdclark@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox