summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/Kconfig8
-rw-r--r--common/console_common.c17
-rw-r--r--defaultenv/defaultenv-2-base/bin/init3
-rw-r--r--defaultenv/defaultenv-2-base/data/ansi-colors2
-rw-r--r--defaultenv/defaultenv-2-base/init/ps12
-rw-r--r--include/console.h2
6 files changed, 27 insertions, 7 deletions
diff --git a/common/Kconfig b/common/Kconfig
index a21f3e51b2..25de2485cd 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -751,6 +751,14 @@ config CONSOLE_ACTIVATE_NONE
endchoice
+config CONSOLE_ALLOW_COLOR
+ prompt "Allow colored console output during boot"
+ bool
+ help
+ If enabled, colored output is allowed during boot. This is the
+ compile time default for colored console output. After boot it
+ can be controlled using global.allow_color.
+
config PBL_CONSOLE
depends on PBL_IMAGE
depends on !CONSOLE_NONE
diff --git a/common/console_common.c b/common/console_common.c
index d051458de4..0202345a62 100644
--- a/common/console_common.c
+++ b/common/console_common.c
@@ -145,15 +145,28 @@ int dev_printf(int level, const struct device_d *dev, const char *format, ...)
return ret;
}
-static int loglevel_init(void)
+#ifdef CONFIG_CONSOLE_ALLOW_COLOR
+static unsigned int __console_allow_color = 1;
+#else
+static unsigned int __console_allow_color = 0;
+#endif
+
+bool console_allow_color(void)
+{
+ return __console_allow_color;
+}
+
+static int console_common_init(void)
{
if (IS_ENABLED(CONFIG_LOGBUF))
globalvar_add_simple_int("log_max_messages",
&barebox_log_max_messages, "%d");
+ globalvar_add_simple_bool("allow_color", &__console_allow_color);
+
return globalvar_add_simple_int("loglevel", &barebox_loglevel, "%d");
}
-device_initcall(loglevel_init);
+device_initcall(console_common_init);
void log_print(unsigned flags)
{
diff --git a/defaultenv/defaultenv-2-base/bin/init b/defaultenv/defaultenv-2-base/bin/init
index 7af3c7d95c..6f3a34dbac 100644
--- a/defaultenv/defaultenv-2-base/bin/init
+++ b/defaultenv/defaultenv-2-base/bin/init
@@ -6,7 +6,6 @@ global hostname
global user
global autoboot_timeout
global boot.default
-global allow_color
global linux.bootargs.base
global linux.bootargs.console
#linux.bootargs.dyn.* will be cleared at the beginning of boot
@@ -20,8 +19,6 @@ magicvar -a global.user "username (used in network filenames)"
[ -z "${global.autoboot_timeout}" ] && global.autoboot_timeout=3
magicvar -a global.autoboot_timeout "timeout in seconds before automatic booting"
[ -z "${global.boot.default}" ] && global.boot.default=net
-[ -z "${global.allow_color}" ] && global.allow_color=true
-magicvar -a global.allow_color "Allow color on the console (boolean)"
[ -z "${global.editcmd}" ] && global.editcmd=sedit
[ -e /env/config-board ] && /env/config-board
diff --git a/defaultenv/defaultenv-2-base/data/ansi-colors b/defaultenv/defaultenv-2-base/data/ansi-colors
index 636532979a..c61cae24e8 100644
--- a/defaultenv/defaultenv-2-base/data/ansi-colors
+++ b/defaultenv/defaultenv-2-base/data/ansi-colors
@@ -1,6 +1,6 @@
#!/bin/sh
-if [ ${global.allow_color} != "true" ]; then
+if [ ${global.allow_color} != "1" ]; then
exit
fi
diff --git a/defaultenv/defaultenv-2-base/init/ps1 b/defaultenv/defaultenv-2-base/init/ps1
index 02d7b4b780..bbb544338c 100644
--- a/defaultenv/defaultenv-2-base/init/ps1
+++ b/defaultenv/defaultenv-2-base/init/ps1
@@ -1,6 +1,6 @@
#!/bin/sh
-if [ ${global.allow_color} = "true" ]; then
+if [ ${global.allow_color} = "1" ]; then
export PS1="\e[1;32mbarebox@\e[1;36m\h:\w\e[0m "
else
export PS1="barebox@\h:\w "
diff --git a/include/console.h b/include/console.h
index 724168e07c..a8b2663a4c 100644
--- a/include/console.h
+++ b/include/console.h
@@ -94,4 +94,6 @@ void pbl_set_putc(void (*putcf)(void *ctx, int c), void *ctx);
static inline void pbl_set_putc(void (*putcf)(void *ctx, int c), void *ctx) {}
#endif
+bool console_allow_color(void);
+
#endif