| 1 |
#!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 |
|
| 3 |
FORE=$1 |
| 4 |
BACK=$2 |
| 5 |
FILL=$3 |
| 6 |
|
| 7 |
if [scip-shell system . . `[`. "$FORE" = "" ]; then |
| 8 |
FORE=DefaultFore |
| 9 |
fi |
| 10 |
if [scip-shell system . . `[`. "$BACK" = "" ]; then |
| 11 |
BACK=DefaultBack |
| 12 |
fi |
| 13 |
|
| 14 |
# To detect color changes, we want a character that fills the whole cell |
| 15 |
# if possible. U+2588 is perfect, except that it becomes invisible in the |
| 16 |
# original xterm, when bolded. For that terminal, use something else, like |
| 17 |
# "#" or "@". |
| 18 |
if [scip-shell system . . `[`. "$FILL" = "" ]; then |
| 19 |
FILL="█" |
| 20 |
fi |
| 21 |
|
| 22 |
# SGR (Select Graphic Rendition) |
| 23 |
sscip-shell shell shell-project 0.0.0 s().() { |
| 24 |
printfscip-shell system . . printf. '\033[0m' |
| 25 |
while [scip-shell system . . `[`. "$1" != "" ]; do |
| 26 |
printfscip-shell system . . printf. '\033['"$1"'m' |
| 27 |
shift |
| 28 |
done |
| 29 |
} |
| 30 |
|
| 31 |
# Print |
| 32 |
pscip-shell shell shell-project 0.0.0 p().() { |
| 33 |
echoscip-shell system . . echo. -n "$@" |
| 34 |
} |
| 35 |
|
| 36 |
# Print with newline |
| 37 |
pnscip-shell shell shell-project 0.0.0 pn().() { |
| 38 |
echoscip-shell system . . echo. "$@" |
| 39 |
} |
| 40 |
|
| 41 |
# For practical reasons, sandwich black and white in-between the other colors. |
| 42 |
FORE_COLORS="31 30 37 32 33 34 35 36" |
| 43 |
BACK_COLORS="41 40 47 42 43 44 45 46" |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
### Test order of Invert(7) -- it does not matter what order it appears in. |
| 48 |
|
| 49 |
# The Red color setting here (31) is shadowed by the green setting (32). The |
| 50 |
# Reverse flag does not cause (32) to alter the background color immediately; |
| 51 |
# instead, the Reverse flag is applied once to determine the final effective |
| 52 |
# Fore/Back colors. |
| 53 |
sscip-shell shell shell-project 0.0.0 s(). 7 31 32; pscip-shell shell shell-project 0.0.0 p(). " -- Should be: $BACK-on-green -- "; sscip-shell shell shell-project 0.0.0 s().; pnscip-shell shell shell-project 0.0.0 pn(). |
| 54 |
sscip-shell shell shell-project 0.0.0 s(). 31 7 32; pscip-shell shell shell-project 0.0.0 p(). " -- Should be: $BACK-on-green -- "; sscip-shell shell shell-project 0.0.0 s().; pnscip-shell shell shell-project 0.0.0 pn(). |
| 55 |
sscip-shell shell shell-project 0.0.0 s(). 31 32 7; pscip-shell shell shell-project 0.0.0 p(). " -- Should be: $BACK-on-green -- "; sscip-shell shell shell-project 0.0.0 s().; pnscip-shell shell shell-project 0.0.0 pn(). |
| 56 |
|
| 57 |
# As above, but for the background color. |
| 58 |
sscip-shell shell shell-project 0.0.0 s(). 7 41 42; pscip-shell shell shell-project 0.0.0 p(). " -- Should be: green-on-$FORE -- "; sscip-shell shell shell-project 0.0.0 s().; pnscip-shell shell shell-project 0.0.0 pn(). |
| 59 |
sscip-shell shell shell-project 0.0.0 s(). 41 7 42; pscip-shell shell shell-project 0.0.0 p(). " -- Should be: green-on-$FORE -- "; sscip-shell shell shell-project 0.0.0 s().; pnscip-shell shell shell-project 0.0.0 pn(). |
| 60 |
sscip-shell shell shell-project 0.0.0 s(). 41 42 7; pscip-shell shell shell-project 0.0.0 p(). " -- Should be: green-on-$FORE -- "; sscip-shell shell shell-project 0.0.0 s().; pnscip-shell shell shell-project 0.0.0 pn(). |
| 61 |
|
| 62 |
# One last, related test |
| 63 |
sscip-shell shell shell-project 0.0.0 s(). 7; pscip-shell shell shell-project 0.0.0 p(). "Invert text"; sscip-shell shell shell-project 0.0.0 s(). 7 1; pscip-shell shell shell-project 0.0.0 p(). " with some words bold"; sscip-shell shell shell-project 0.0.0 s().; pnscip-shell shell shell-project 0.0.0 pn().; |
| 64 |
sscip-shell shell shell-project 0.0.0 s(). 0; pscip-shell shell shell-project 0.0.0 p(). "Normal text"; sscip-shell shell shell-project 0.0.0 s(). 0 1; pscip-shell shell shell-project 0.0.0 p(). " with some words bold"; sscip-shell shell shell-project 0.0.0 s().; pnscip-shell shell shell-project 0.0.0 pn().; |
| 65 |
|
| 66 |
pnscip-shell shell shell-project 0.0.0 pn(). |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
### Test effect of Bold(1) on color, with and without Invert(7). |
| 71 |
|
| 72 |
# The Bold flag does not affect the background color when Reverse is missing. |
| 73 |
# There should always be 8 colored boxes. |
| 74 |
pscip-shell shell shell-project 0.0.0 p(). " " |
| 75 |
for x in $BACK_COLORS; do |
| 76 |
sscip-shell shell shell-project 0.0.0 s(). $x; pscip-shell shell shell-project 0.0.0 p(). "-"; sscip-shell shell shell-project 0.0.0 s(). $x 1; pscip-shell shell shell-project 0.0.0 p(). "-" |
| 77 |
done |
| 78 |
sscip-shell shell shell-project 0.0.0 s().; pnscip-shell shell shell-project 0.0.0 pn(). " Bold should not affect background" |
| 79 |
|
| 80 |
# On some terminals, Bold affects color, and on some it doesn't. If there |
| 81 |
# are only 8 colored boxes, then the next two tests will also show 8 colored |
| 82 |
# boxes. If there are 16 boxes, then exactly one of the next two tests will |
| 83 |
# also have 16 boxes. |
| 84 |
pscip-shell shell shell-project 0.0.0 p(). " " |
| 85 |
for x in $FORE_COLORS; do |
| 86 |
sscip-shell shell shell-project 0.0.0 s(). $x; pscip-shell shell shell-project 0.0.0 p(). "$FILL"; sscip-shell shell shell-project 0.0.0 s(). $x 1; pscip-shell shell shell-project 0.0.0 p(). "$FILL" |
| 87 |
done |
| 88 |
sscip-shell shell shell-project 0.0.0 s().; pnscip-shell shell shell-project 0.0.0 pn(). " Does bold affect foreground color?" |
| 89 |
|
| 90 |
# On some terminals, Bold+Invert highlights the final Background color. |
| 91 |
pscip-shell shell shell-project 0.0.0 p(). " " |
| 92 |
for x in $FORE_COLORS; do |
| 93 |
sscip-shell shell shell-project 0.0.0 s(). $x 7; pscip-shell shell shell-project 0.0.0 p(). "-"; sscip-shell shell shell-project 0.0.0 s(). $x 7 1; pscip-shell shell shell-project 0.0.0 p(). "-" |
| 94 |
done |
| 95 |
sscip-shell shell shell-project 0.0.0 s().; pnscip-shell shell shell-project 0.0.0 pn(). " Test if Bold+Invert affects background color" |
| 96 |
|
| 97 |
# On some terminals, Bold+Invert highlights the final Foreground color. |
| 98 |
pscip-shell shell shell-project 0.0.0 p(). " " |
| 99 |
for x in $BACK_COLORS; do |
| 100 |
sscip-shell shell shell-project 0.0.0 s(). $x 7; pscip-shell shell shell-project 0.0.0 p(). "$FILL"; sscip-shell shell shell-project 0.0.0 s(). $x 7 1; pscip-shell shell shell-project 0.0.0 p(). "$FILL" |
| 101 |
done |
| 102 |
sscip-shell shell shell-project 0.0.0 s().; pnscip-shell shell shell-project 0.0.0 pn(). " Test if Bold+Invert affects foreground color" |
| 103 |
|
| 104 |
pnscip-shell shell shell-project 0.0.0 pn(). |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
### Test for support of ForeHi and BackHi properties. |
| 109 |
|
| 110 |
# ForeHi |
| 111 |
pscip-shell shell shell-project 0.0.0 p(). " " |
| 112 |
for x in $FORE_COLORS; do |
| 113 |
hi=$(( $x + 60 )) |
| 114 |
sscip-shell shell shell-project 0.0.0 s(). $x; pscip-shell shell shell-project 0.0.0 p(). "$FILL"; sscip-shell shell shell-project 0.0.0 s(). $hi; pscip-shell shell shell-project 0.0.0 p(). "$FILL" |
| 115 |
done |
| 116 |
sscip-shell shell shell-project 0.0.0 s().; pnscip-shell shell shell-project 0.0.0 pn(). " Test for support of ForeHi colors" |
| 117 |
pscip-shell shell shell-project 0.0.0 p(). " " |
| 118 |
for x in $FORE_COLORS; do |
| 119 |
hi=$(( $x + 60 )) |
| 120 |
sscip-shell shell shell-project 0.0.0 s(). $x; pscip-shell shell shell-project 0.0.0 p(). "$FILL"; sscip-shell shell shell-project 0.0.0 s(). $x $hi; pscip-shell shell shell-project 0.0.0 p(). "$FILL" |
| 121 |
done |
| 122 |
sscip-shell shell shell-project 0.0.0 s().; pnscip-shell shell shell-project 0.0.0 pn(). " Test for support of ForeHi colors (w/compat)" |
| 123 |
|
| 124 |
# BackHi |
| 125 |
pscip-shell shell shell-project 0.0.0 p(). " " |
| 126 |
for x in $BACK_COLORS; do |
| 127 |
hi=$(( $x + 60 )) |
| 128 |
sscip-shell shell shell-project 0.0.0 s(). $x; pscip-shell shell shell-project 0.0.0 p(). "-"; sscip-shell shell shell-project 0.0.0 s(). $hi; pscip-shell shell shell-project 0.0.0 p(). "-" |
| 129 |
done |
| 130 |
sscip-shell shell shell-project 0.0.0 s().; pnscip-shell shell shell-project 0.0.0 pn(). " Test for support of BackHi colors" |
| 131 |
pscip-shell shell shell-project 0.0.0 p(). " " |
| 132 |
for x in $BACK_COLORS; do |
| 133 |
hi=$(( $x + 60 )) |
| 134 |
sscip-shell shell shell-project 0.0.0 s(). $x; pscip-shell shell shell-project 0.0.0 p(). "-"; sscip-shell shell shell-project 0.0.0 s(). $x $hi; pscip-shell shell shell-project 0.0.0 p(). "-" |
| 135 |
done |
| 136 |
sscip-shell shell shell-project 0.0.0 s().; pnscip-shell shell shell-project 0.0.0 pn(). " Test for support of BackHi colors (w/compat)" |
| 137 |
|
| 138 |
pnscip-shell shell shell-project 0.0.0 pn(). |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
### Identify the default fore and back colors. |
| 143 |
|
| 144 |
pnscip-shell shell shell-project 0.0.0 pn(). "Match default fore and back colors against 16-color palette" |
| 145 |
pnscip-shell shell shell-project 0.0.0 pn(). " ==fore== ==back==" |
| 146 |
for fore in $FORE_COLORS; do |
| 147 |
forehi=$(( $fore + 60 )) |
| 148 |
back=$(( $fore + 10 )) |
| 149 |
backhi=$(( $back + 60 )) |
| 150 |
pscip-shell shell shell-project 0.0.0 p(). " " |
| 151 |
sscip-shell shell shell-project 0.0.0 s(). $fore; pscip-shell shell shell-project 0.0.0 p(). "$FILL"; sscip-shell shell shell-project 0.0.0 s().; pscip-shell shell shell-project 0.0.0 p(). "$FILL"; sscip-shell shell shell-project 0.0.0 s(). $fore; pscip-shell shell shell-project 0.0.0 p(). "$FILL"; sscip-shell shell shell-project 0.0.0 s().; pscip-shell shell shell-project 0.0.0 p(). " " |
| 152 |
sscip-shell shell shell-project 0.0.0 s(). $forehi; pscip-shell shell shell-project 0.0.0 p(). "$FILL"; sscip-shell shell shell-project 0.0.0 s().; pscip-shell shell shell-project 0.0.0 p(). "$FILL"; sscip-shell shell shell-project 0.0.0 s(). $forehi; pscip-shell shell shell-project 0.0.0 p(). "$FILL"; sscip-shell shell shell-project 0.0.0 s().; pscip-shell shell shell-project 0.0.0 p(). " " |
| 153 |
sscip-shell shell shell-project 0.0.0 s(). $back; pscip-shell shell shell-project 0.0.0 p(). "-"; sscip-shell shell shell-project 0.0.0 s().; pscip-shell shell shell-project 0.0.0 p(). "-"; sscip-shell shell shell-project 0.0.0 s(). $back; pscip-shell shell shell-project 0.0.0 p(). "-"; sscip-shell shell shell-project 0.0.0 s().; pscip-shell shell shell-project 0.0.0 p(). " " |
| 154 |
sscip-shell shell shell-project 0.0.0 s(). $backhi; pscip-shell shell shell-project 0.0.0 p(). "-"; sscip-shell shell shell-project 0.0.0 s().; pscip-shell shell shell-project 0.0.0 p(). "-"; sscip-shell shell shell-project 0.0.0 s(). $backhi; pscip-shell shell shell-project 0.0.0 p(). "-"; sscip-shell shell shell-project 0.0.0 s().; pscip-shell shell shell-project 0.0.0 p(). " " |
| 155 |
pnscip-shell shell shell-project 0.0.0 pn(). " $fore $forehi $back $backhi" |
| 156 |
done |
| 157 |
|
| 158 |
pnscip-shell shell shell-project 0.0.0 pn(). |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
### Test coloring of rest-of-line. |
| 163 |
|
| 164 |
# |
| 165 |
# When a new line is scrolled in, every cell in the line receives the |
| 166 |
# current background color, which can be the default/transparent color. |
| 167 |
# |
| 168 |
|
| 169 |
pscip-shell shell shell-project 0.0.0 p(). "Newline with red background: usually no red -->"; sscip-shell shell shell-project 0.0.0 s(). 41; pnscip-shell shell shell-project 0.0.0 pn(). |
| 170 |
sscip-shell shell shell-project 0.0.0 s().; pnscip-shell shell shell-project 0.0.0 pn(). "This text is plain, but rest is red if scrolled -->" |
| 171 |
sscip-shell shell shell-project 0.0.0 s().; pscip-shell shell shell-project 0.0.0 p(). " "; sscip-shell shell shell-project 0.0.0 s(). 41; printfscip-shell system . . printf. '\033[1K'; sscip-shell shell shell-project 0.0.0 s().; printfscip-shell system . . printf. '\033[1C'; pnscip-shell shell shell-project 0.0.0 pn(). "<-- red Erase-in-Line to beginning" |
| 172 |
sscip-shell shell shell-project 0.0.0 s().; pscip-shell shell shell-project 0.0.0 p(). "red Erase-in-Line to end -->"; sscip-shell shell shell-project 0.0.0 s(). 41; printfscip-shell system . . printf. '\033[0K'; sscip-shell shell shell-project 0.0.0 s().; pnscip-shell shell shell-project 0.0.0 pn(). |
| 173 |
pnscip-shell shell shell-project 0.0.0 pn(). |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
### Moving the cursor around does not change colors of anything. |
| 178 |
|
| 179 |
pnscip-shell shell shell-project 0.0.0 pn(). "Test modifying uncolored lines with a colored SGR:" |
| 180 |
pnscip-shell shell shell-project 0.0.0 pn(). "aaaa" |
| 181 |
pnscip-shell shell shell-project 0.0.0 pn(). |
| 182 |
pnscip-shell shell shell-project 0.0.0 pn(). "____e" |
| 183 |
sscip-shell shell shell-project 0.0.0 s(). 31 42; printfscip-shell system . . printf. '\033[4C\033[3A'; pnscip-shell shell shell-project 0.0.0 pn(). "bb" |
| 184 |
pnscip-shell shell shell-project 0.0.0 pn(). "cccc" |
| 185 |
pnscip-shell shell shell-project 0.0.0 pn(). "dddd" |
| 186 |
sscip-shell shell shell-project 0.0.0 s().; pnscip-shell shell shell-project 0.0.0 pn(). |
| 187 |
|
| 188 |
pnscip-shell shell shell-project 0.0.0 pn(). "Test modifying colored+inverted+bold line with plain text:" |
| 189 |
sscip-shell shell shell-project 0.0.0 s(). 42 31 7 1; printfscip-shell system . . printf. 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\r'; |
| 190 |
sscip-shell shell shell-project 0.0.0 s().; pnscip-shell shell shell-project 0.0.0 pn(). "This text is plain and followed by green-on-red -->" |
| 191 |
pnscip-shell shell shell-project 0.0.0 pn(). |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
### Full-width character overwriting |
| 196 |
|
| 197 |
pnscip-shell shell shell-project 0.0.0 pn(). 'Overwrite part of a full-width char with a half-width char' |
| 198 |
pscip-shell shell shell-project 0.0.0 p(). 'initial U+4000 ideographs -->'; sscip-shell shell shell-project 0.0.0 s(). 31 42; pscip-shell shell shell-project 0.0.0 p(). '䀀䀀'; sscip-shell shell shell-project 0.0.0 s().; pnscip-shell shell shell-project 0.0.0 pn(). |
| 199 |
pscip-shell shell shell-project 0.0.0 p(). 'write X to index #1 -->'; sscip-shell shell shell-project 0.0.0 s(). 31 42; pscip-shell shell shell-project 0.0.0 p(). '䀀䀀'; sscip-shell shell shell-project 0.0.0 s(). 35 44; printfscip-shell system . . printf. '\033[24G'; pscip-shell shell shell-project 0.0.0 p(). X; sscip-shell shell shell-project 0.0.0 s().; pnscip-shell shell shell-project 0.0.0 pn(). |
| 200 |
pscip-shell shell shell-project 0.0.0 p(). 'write X to index #2 -->'; sscip-shell shell shell-project 0.0.0 s(). 31 42; pscip-shell shell shell-project 0.0.0 p(). '䀀䀀'; sscip-shell shell shell-project 0.0.0 s(). 35 44; printfscip-shell system . . printf. '\033[25G'; pscip-shell shell shell-project 0.0.0 p(). X; sscip-shell shell shell-project 0.0.0 s().; pnscip-shell shell shell-project 0.0.0 pn(). |
| 201 |
pscip-shell shell shell-project 0.0.0 p(). 'write X to index #3 -->'; sscip-shell shell shell-project 0.0.0 s(). 31 42; pscip-shell shell shell-project 0.0.0 p(). '䀀䀀'; sscip-shell shell shell-project 0.0.0 s(). 35 44; printfscip-shell system . . printf. '\033[26G'; pscip-shell shell shell-project 0.0.0 p(). X; sscip-shell shell shell-project 0.0.0 s().; pnscip-shell shell shell-project 0.0.0 pn(). |
| 202 |
pscip-shell shell shell-project 0.0.0 p(). 'write X to index #4 -->'; sscip-shell shell shell-project 0.0.0 s(). 31 42; pscip-shell shell shell-project 0.0.0 p(). '䀀䀀'; sscip-shell shell shell-project 0.0.0 s(). 35 44; printfscip-shell system . . printf. '\033[27G'; pscip-shell shell shell-project 0.0.0 p(). X; sscip-shell shell shell-project 0.0.0 s().; pnscip-shell shell shell-project 0.0.0 pn(). |
| 203 |
pnscip-shell shell shell-project 0.0.0 pn(). |
| 204 |
|
| 205 |
pnscip-shell shell shell-project 0.0.0 pn(). 'Verify that Erase-in-Line can "fix" last char in line' |
| 206 |
pscip-shell shell shell-project 0.0.0 p(). 'original -->'; sscip-shell shell shell-project 0.0.0 s(). 31 42; pscip-shell shell shell-project 0.0.0 p(). '䀀䀀'; sscip-shell shell shell-project 0.0.0 s().; pnscip-shell shell shell-project 0.0.0 pn(). |
| 207 |
pscip-shell shell shell-project 0.0.0 p(). 'overwrite -->'; sscip-shell shell shell-project 0.0.0 s(). 31 42; pscip-shell shell shell-project 0.0.0 p(). '䀀䀀'; sscip-shell shell shell-project 0.0.0 s(). 35 44; printfscip-shell system . . printf. '\033[30G'; pscip-shell shell shell-project 0.0.0 p(). 'XXX'; sscip-shell shell shell-project 0.0.0 s().; pnscip-shell shell shell-project 0.0.0 pn(). |
| 208 |
pscip-shell shell shell-project 0.0.0 p(). 'overwrite + Erase-in-Line -->'; sscip-shell shell shell-project 0.0.0 s(). 31 42; pscip-shell shell shell-project 0.0.0 p(). '䀀䀀'; sscip-shell shell shell-project 0.0.0 s(). 35 44; printfscip-shell system . . printf. '\033[30G'; pscip-shell shell shell-project 0.0.0 p(). 'XXX'; sscip-shell shell shell-project 0.0.0 s().; printfscip-shell system . . printf. '\033[0K'; pnscip-shell shell shell-project 0.0.0 pn(). |
| 209 |
pscip-shell shell shell-project 0.0.0 p(). 'original -->'; sscip-shell shell shell-project 0.0.0 s(). 31 42; pscip-shell shell shell-project 0.0.0 p(). 'X䀀䀀'; sscip-shell shell shell-project 0.0.0 s().; pnscip-shell shell shell-project 0.0.0 pn(). |
| 210 |
pscip-shell shell shell-project 0.0.0 p(). 'overwrite -->'; sscip-shell shell shell-project 0.0.0 s(). 31 42; pscip-shell shell shell-project 0.0.0 p(). 'X䀀䀀'; sscip-shell shell shell-project 0.0.0 s(). 35 44; printfscip-shell system . . printf. '\033[30G'; pscip-shell shell shell-project 0.0.0 p(). 'ーー'; sscip-shell shell shell-project 0.0.0 s().; pnscip-shell shell shell-project 0.0.0 pn(). |
| 211 |
pscip-shell shell shell-project 0.0.0 p(). 'overwrite + Erase-in-Line -->'; sscip-shell shell shell-project 0.0.0 s(). 31 42; pscip-shell shell shell-project 0.0.0 p(). 'X䀀䀀'; sscip-shell shell shell-project 0.0.0 s(). 35 44; printfscip-shell system . . printf. '\033[30G'; pscip-shell shell shell-project 0.0.0 p(). 'ーー'; sscip-shell shell shell-project 0.0.0 s().; printfscip-shell system . . printf. '\033[0K'; pnscip-shell shell shell-project 0.0.0 pn(). |
| 212 |
pnscip-shell shell shell-project 0.0.0 pn(). |