Browse Source

Add 'forcecolor' module

Same as 'color' but does not turn off the colors on non-terminal tty.
Alois Mahdal 4 years ago
parent
commit
db7e27520b

+ 1
- 0
packaging/debian/shellfu-bash-pretty.install View File

@@ -1,4 +1,5 @@
1 1
 /usr/share/shellfu/include-bash/_pretty_color.sh
2
+/usr/share/shellfu/include-bash/_pretty_forcecolor.sh
2 3
 /usr/share/shellfu/include-bash/_pretty_html.sh
3 4
 /usr/share/shellfu/include-bash/_pretty_journald.sh
4 5
 /usr/share/shellfu/include-bash/_pretty_notify.sh

+ 1
- 0
packaging/template.spec View File

@@ -175,6 +175,7 @@ make test \
175 175
 
176 176
 %files bash-pretty
177 177
 %{_datadir}/%{name}/include-bash/_pretty_color.sh
178
+%{_datadir}/%{name}/include-bash/_pretty_forcecolor.sh
178 179
 %{_datadir}/%{name}/include-bash/_pretty_html.sh
179 180
 %{_datadir}/%{name}/include-bash/_pretty_journald.sh
180 181
 %{_datadir}/%{name}/include-bash/_pretty_notify.sh

+ 62
- 0
src/include-bash/_pretty_forcecolor.sh View File

@@ -0,0 +1,62 @@
1
+#!/bin/bash
2
+
3
+shellfu import termcolors
4
+
5
+
6
+_PRETTY_FORCECOLOR_DEBUG="${TERMCOLORS_LBLUE}"
7
+_PRETTY_FORCECOLOR_DIE="${TERMCOLORS_LRED}"
8
+_PRETTY_FORCECOLOR_USAGE_IS="${TERMCOLORS_YELLOW}"
9
+_PRETTY_FORCECOLOR_THINK="${TERMCOLORS_LBLACK}"
10
+_PRETTY_FORCECOLOR_WARN="${TERMCOLORS_LRED}"
11
+_PRETTY_FORCECOLOR_OFF="${TERMCOLORS_NONE}"
12
+
13
+
14
+_pretty__debug() {
15
+    local decor="()"
16
+    local caller_is_main=${caller_is_main:-false}
17
+    local caller=${caller:-UNKNOWN}
18
+    $caller_is_main && decor=
19
+    while IFS= read -r line;
20
+    do echo -ne "${_PRETTY_FORCECOLOR_DEBUG}debug:$caller$decor:$_PRETTY_FORCECOLOR_OFF"
21
+       echo "$line"; done
22
+}
23
+
24
+
25
+_pretty__die() {
26
+    echo -ne "$_PRETTY_FORCECOLOR_DIE"
27
+    while IFS= read -r line;
28
+    do echo "$line"; done
29
+    echo -ne "$_PRETTY_FORCECOLOR_OFF"
30
+}
31
+
32
+
33
+_pretty__mkhelp() {
34
+    echo -ne "$_PRETTY_FORCECOLOR_USAGE_IS"
35
+    while IFS= read -r line;
36
+    do echo -e "$line"; done
37
+    echo -ne "$_PRETTY_FORCECOLOR_OFF"
38
+}
39
+
40
+
41
+_pretty__mkusage() {
42
+    echo -ne "$_PRETTY_FORCECOLOR_USAGE_IS"
43
+    while IFS= read -r line;
44
+    do echo -e "$line"; done
45
+    echo -ne "$_PRETTY_FORCECOLOR_OFF"
46
+}
47
+
48
+
49
+_pretty__think() {
50
+    echo -ne "$_PRETTY_FORCECOLOR_THINK"
51
+    while IFS= read -r line;
52
+    do echo "$line"; done
53
+    echo -ne "$_PRETTY_FORCECOLOR_OFF"
54
+}
55
+
56
+
57
+_pretty__warn() {
58
+    echo -ne "$_PRETTY_FORCECOLOR_WARN"
59
+    while IFS= read -r line;
60
+    do echo "$line"; done
61
+    echo -ne "$_PRETTY_FORCECOLOR_OFF"
62
+}

+ 1
- 0
tests/shellfu_api/TF_RUN View File

@@ -12,6 +12,7 @@ flt_ours() {
12 12
         -e _pretty_journald \
13 13
         -e _pretty_html \
14 14
         -e sync \
15
+        -e _pretty_forcecolor \
15 16
         -e _pretty_color \
16 17
         -e inigrep \
17 18
         -e _pretty_notify \

+ 6
- 0
tests/shellfu_api/oracle/functions.stdout View File

@@ -5,6 +5,12 @@ _pretty_color:_pretty__mkhelp
5 5
 _pretty_color:_pretty__mkusage
6 6
 _pretty_color:_pretty__think
7 7
 _pretty_color:_pretty__warn
8
+_pretty_forcecolor:_pretty__debug
9
+_pretty_forcecolor:_pretty__die
10
+_pretty_forcecolor:_pretty__mkhelp
11
+_pretty_forcecolor:_pretty__mkusage
12
+_pretty_forcecolor:_pretty__think
13
+_pretty_forcecolor:_pretty__warn
8 14
 _pretty_html:_pretty__debug
9 15
 _pretty_html:_pretty__die
10 16
 _pretty_html:_pretty__mkhelp

+ 1
- 0
tests/shellfu_api/oracle/modules.stdout View File

@@ -1,4 +1,5 @@
1 1
 _pretty_color
2
+_pretty_forcecolor
2 3
 _pretty_html
3 4
 _pretty_journald
4 5
 _pretty_notify

+ 6
- 0
tests/shellfu_api/oracle/variables.stdout View File

@@ -4,6 +4,12 @@ _pretty_color:_PRETTY_COLOR_OFF
4 4
 _pretty_color:_PRETTY_COLOR_THINK
5 5
 _pretty_color:_PRETTY_COLOR_USAGE_IS
6 6
 _pretty_color:_PRETTY_COLOR_WARN
7
+_pretty_forcecolor:_PRETTY_FORCECOLOR_DEBUG
8
+_pretty_forcecolor:_PRETTY_FORCECOLOR_DIE
9
+_pretty_forcecolor:_PRETTY_FORCECOLOR_OFF
10
+_pretty_forcecolor:_PRETTY_FORCECOLOR_THINK
11
+_pretty_forcecolor:_PRETTY_FORCECOLOR_USAGE_IS
12
+_pretty_forcecolor:_PRETTY_FORCECOLOR_WARN
7 13
 charmenu:CHARMENU_FILE
8 14
 exit:EXIT_ERROR
9 15
 exit:EXIT_NO