diff --git a/common/Kconfig b/common/Kconfig index a21f3e5..25de248 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -751,6 +751,14 @@ 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 d051458..0202345 100644 --- a/common/console_common.c +++ b/common/console_common.c @@ -145,15 +145,28 @@ 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 7af3c7d..6f3a34d 100644 --- a/defaultenv/defaultenv-2-base/bin/init +++ b/defaultenv/defaultenv-2-base/bin/init @@ -6,7 +6,6 @@ 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 @@ [ -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 6365329..c61cae2 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 02d7b4b..bbb5443 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 724168e..a8b2663 100644 --- a/include/console.h +++ b/include/console.h @@ -94,4 +94,6 @@ static inline void pbl_set_putc(void (*putcf)(void *ctx, int c), void *ctx) {} #endif +bool console_allow_color(void); + #endif