From 05f1f41c9b02b916a5f03c5658bec3270ac3684d Mon Sep 17 00:00:00 2001 From: Robert Estelle Date: Mon, 25 Oct 2021 22:32:36 +0000 Subject: color: support "default" to restore fg/bg color The name "default" can now be used in foreground or background colors, and means to use the terminal's default color, discarding any explicitly-set color without affecting the other attributes. On many modern terminals, this is *not* the same as specifying "white" or "black". Although attributes could previously be cleared like "no-bold", there had not been a similar mechanism available for colors, other than a full "reset", which cannot currently be combined with other settings. Note that this is *not* the same as the existing name "normal", which is a no-op placeholder to permit setting the background without changing the foreground. (i.e. what is currently called "normal" might have been more descriptively named "inherit", "none", "pass" or similar). Signed-off-by: Robert Estelle Signed-off-by: Junio C Hamano --- t/t4026-color.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 't') diff --git a/t/t4026-color.sh b/t/t4026-color.sh index cc73161b46..d6907a66c3 100755 --- a/t/t4026-color.sh +++ b/t/t4026-color.sh @@ -96,6 +96,18 @@ test_expect_success '24-bit colors' ' color "#ff00ff black" "[38;2;255;0;255;40m" ' +test_expect_success '"default" foreground' ' + color "default" "[39m" +' + +test_expect_success '"normal default" to clear background' ' + color "normal default" "[49m" +' + +test_expect_success '"default" can be combined with attributes' ' + color "default default no-reverse bold" "[1;27;39;49m" +' + test_expect_success '"normal" yields no color at all"' ' color "normal black" "[40m" ' -- cgit v1.2.3 From de658515ae1166577441da09fe7624769e263a3e Mon Sep 17 00:00:00 2001 From: Robert Estelle Date: Tue, 26 Oct 2021 01:03:47 +0000 Subject: color: allow colors to be prefixed with "reset" "reset" was previously treated as a standalone special color name representing `\e[m`. Now, it can apply to other color properties, allowing exact specifications without implicit attribute inheritance. For example, "reset green" now renders `\e[;32m`, which is interpreted as "reset everything; then set foreground to green". This means the background and other attributes are also reset to their defaults. Previously, this was impossible to represent in a single color: "reset" could be specified alone, or a color with attributes, but some thing like clearing a background color were impossible. There is a separate change that introduces the "default" color name to assist with that, but even then, the above could only to be represented by explicitly disabling each of the attributes: green default no-bold no-dim no-italic no-ul no-blink no-reverse no-strike Signed-off-by: Robert Estelle Signed-off-by: Junio C Hamano --- t/t4026-color.sh | 4 ++++ 1 file changed, 4 insertions(+) (limited to 't') diff --git a/t/t4026-color.sh b/t/t4026-color.sh index d6907a66c3..cc3f60d468 100755 --- a/t/t4026-color.sh +++ b/t/t4026-color.sh @@ -60,6 +60,10 @@ test_expect_success 'fg bg attr...' ' color "blue bold dim ul blink reverse" "[1;2;4;5;7;34m" ' +test_expect_success 'reset fg bg attr...' ' + color "reset blue bold dim ul blink reverse" "[;1;2;4;5;7;34m" +' + # note that nobold and nodim are the same code (22) test_expect_success 'attr negation' ' color "nobold nodim noul noblink noreverse" "[22;24;25;27m" -- cgit v1.2.3