Move into an external dir
[zsh.git] / .zsh / 01_Terminfo.zsh
1 # -*- sh -*-
2
3 # Update terminfo
4 __() {
5 local terminfo
6 local termpath
7 if is-callable tic >/dev/null; then
8 for terminfo in $ZSH/terminfo/*.terminfo(.N); do
9 # We assume that the file is named appropriately for this to work
10 termpath=~/.terminfo/${(@)${terminfo##*/}[1]}/${${terminfo##*/}%%.terminfo}
11 if [[ ! -e $termpath ]] || [[ $terminfo -nt $termpath ]]; then
12 TERMINFO=~/.terminfo tic $terminfo
13 fi
14 done
15 fi
16 } && __
17
18 # Update TERM if we have LC__ORIGINALTERM variable
19 # Also, try a sensible term where we have terminfo stuff
20 autoload -U colors zsh/terminfo zsh/termcap
21 __ () {
22 local term
23 local colors
24 # If the terminal identifies itself as dumb, then we don't try
25 # to mess with it. As our system sure may find a definition
26 # that it thinks might work (just export the right TERM variable
27 # and $terminfo will succeed), yet the dumb terminal won't be able
28 # to handle it.
29 # Easy verified - remove the if here and use M-x shell in emacs.
30 # Have fun.
31 if [[ $TERM != "dumb" ]]; then
32 for term in $LC__ORIGINALTERM $TERM ${TERM/-256color} xterm; do
33 TERM=$term 2> /dev/null
34 if (( ${terminfo[colors]:-0} >= 8 )) || \
35 (zmodload zsh/termcap 2> /dev/null) && \
36 (( ${termcap[Co]:-0} >= 8)); then
37 colors
38 break
39 fi
40 done
41 unset LC__ORIGINALTERM
42 export TERM
43 alias xsudo="TERM=xterm command sudo"
44 fi
45 } && __
46
47
48 docolors()
49 {
50 if autoload -Uz colors && colors 2>/dev/null ; then
51 for COLOR in RED GREEN YELLOW BLUE MAGENTA CYAN BLACK WHITE GREY; do
52 eval $COLOR='%{$fg_no_bold[${(L)COLOR}]%}'
53 eval BOLD_$COLOR='%{$fg_bold[${(L)COLOR}]%}'
54 done
55 eval NO_COLOR='%{$reset_color%}'
56 else
57 BLUE=$'%{\e[1;34m%}'
58 RED=$'%{\e[1;31m%}'
59 GREEN=$'%{\e[1;32m%}'
60 CYAN=$'%{\e[1;36m%}'
61 WHITE=$'%{\e[1;37m%}'
62 MAGENTA=$'%{\e[1;35m%}'
63 YELLOW=$'%{\e[1;33m%}'
64 NO_COLOR=$'%{\e[0m%}'
65 fi
66 }
67
68 # And while setting up terminal related information, lets decide on some
69 # more features the terminal may or may not support.
70 __ () {
71 # Start out with default values
72 LINEDRAW=false
73 COLORS=false
74
75 # Do we support colors?
76 local colcount=$(tput colors)
77 if [[ ${colcount} -gt 0 ]]; then
78 COLORS="true"
79 # Colors supported, lets setup the variables so later on they can
80 # be used without again having to ensure it is done.
81 docolors
82 fi
83
84 # Is linedrawing supported?
85 if tput acsc >/dev/null || isutf8 || isconsole; then
86 LINEDRAW="true"
87 fi
88
89 setvar COLORS ${COLORS}
90 setvar LINEDRAW ${LINEDRAW}
91 } && __