Skip to content

Commit 66792bc

Browse files
author
Vasiliy Polyakov
committed
save
1 parent 7a45ad9 commit 66792bc

File tree

2 files changed

+55
-18
lines changed

2 files changed

+55
-18
lines changed

lib/colors.sh

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,61 @@
22
## @brief Color terminal support.
33
## @author Vasiliy Polyakov
44
## @date 2019
5-
## @pre lib.bash (Bash scripting library).
6-
## @pre ncurses (tput).
5+
## @pre lib.bash (Bash scripting library).
6+
## @pre ncurses (tput).
77

88
import_once || return $?
99

10-
declare -gi COLORS="$(tput colors)"
10+
declare -gi COLORS
1111
declare -ga FG BG
12-
declare -gr SGR0=$'\e[m'
12+
declare -gA SGR
1313

14-
local -i c
15-
for (( c = 0; c < 8 && COLORS >= 8; c++ )); do
16-
FG[c]=$'\e'"[$((30+c))m"
17-
BG[c]=$'\e'"[$((40+c))m"
18-
done
19-
for (( c = 8; c < 16 && COLORS >= 16; c++ )); do
20-
FG[c]=$'\e'"[$((82+c))m"
21-
BG[c]=$'\e'"[$((92+c))m"
22-
done
23-
for (( c = 16; c < 256 && COLORS >= 256; c++ )); do
24-
FG[c]=$'\e'"[38;5;${c}m"
25-
BG[c]=$'\e'"[48;5;${c}m"
26-
done
14+
local -i terminfo=0 c
15+
case $1 in
16+
0) declare -r COLORS FG BG SGR; return 0 ;;
17+
terminfo) terminfo=1 ;;
18+
esac
19+
20+
COLORS="$(tput colors)"
21+
22+
if (( terminfo )); then
23+
for (( c = 0; c < COLORS; c++ )); do
24+
FG[c]="$(tput setaf "$c")"
25+
BG[c]="$(tput setab "$c")"
26+
done
27+
SGR[bold]="$(tput bold)"
28+
SGR[dim]="$(tput dim)"
29+
SGR[italics]="$(tput sitm)"
30+
SGR[uline]="$(tput smul)"
31+
SGR[blink]="$(tput blink)"
32+
SGR[reverse]="$(tput rev)"
33+
SGR[reset]="$(tput sgr0)"
34+
else
35+
local CSI=$'\e['
36+
for (( c = 0; c < 8 && COLORS >= 8; c++ )); do
37+
FG[c]="${CSI}$((30+c))m"
38+
BG[c]="${CSI}$((40+c))m"
39+
done
40+
for (( c = 8; c < 16 && COLORS >= 16; c++ )); do
41+
FG[c]="${CSI}$((82+c))m"
42+
BG[c]="${CSI}$((92+c))m"
43+
done
44+
for (( c = 16; c < 256 && COLORS >= 256; c++ )); do
45+
FG[c]="${CSI}38;5;${c}m"
46+
BG[c]="${CSI}48;5;${c}m"
47+
done
48+
SGR[bold]="${CSI}1m"
49+
SGR[dim]="${CSI}2m"
50+
SGR[italics]="${CSI}3m"
51+
SGR[uline]="${CSI}4m"
52+
SGR[blink]="${CSI}5m"
53+
SGR[reverse]="${CSI}7m"
54+
SGR[reset]="${CSI}m"
55+
unset CSI
56+
fi; unset terminfo c
57+
# TODO: add one-letter and digit aliases for SGR
58+
SGR[rev]="${SGR[reverse]}"
59+
SGR[exit]="${SGR[reset]}"
60+
SGR[0]="${SGR[reset]}"
61+
62+
declare -r COLORS FG BG SGR

lib/prompt.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
## @see https://gitweb.gentoo.org/repo/gentoo.git/tree/app-shells/bash/files/bashrc
1010

1111
import_once || return $?
12-
import color
12+
import colors
1313
import git
1414

1515
declare -gA PROMPT_COLOR PROMPT_CHAR
@@ -83,6 +83,7 @@ prompt::ssh_color() {
8383

8484
prompt::cmd() {
8585
local x
86+
history -a
8687
[[ -z $MC_SID ]] && echo -en '\e[6n' && read -sdR x && (( ${x##*;} > 1 )) && echo
8788
}
8889

0 commit comments

Comments
 (0)