]> CyberLeo.Net >> Repos - CDN/shlib.git/blob - lib/sh/ansi.sh
Add explicit copyright to all library files
[CDN/shlib.git] / lib / sh / ansi.sh
1 # Include me for neat color defines!
2 : <<"END_OF_COPYRIGHT"
3
4 Copyright (c) 2000-2012, CyberLeo
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9
10     * Redistributions of the source code must retain the above copyright
11       notice, this list of conditions, and the following disclaimer.
12     * Redistributions in binary form must reproduce the above copyright
13       notice, this list of conditions, and the following disclaimer in the
14       documentation and/or other materials provided with the distribution.
15     * Neither the name of the organization nor the names of its contributors
16       may be used to endorse or promote products derived from this software
17       without specific prior written permission.
18
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
25 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 HOWEVER CAUSED AND ON ANY THEORY OF LIABILTY, WHETHER IN CONTRACT, STRICT
27 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
28 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 END_OF_COPYRIGHT
31
32 if [ -z "${__ansi_sh_loaded}" ]
33 then
34   __ansi_sh_loaded=yes
35
36   # ANSI formats
37   e="$(printf "\033")"
38
39   # ANSI styles
40   a_bright="$e[1m"
41   a_dim="$e[2m"
42   a_italic="$e[3m"    # Probably won't work
43   a_underline="$e[4m" # Probably won't work
44   a_blink="$e[5m"     # Annoying; probably won't work
45   a_flash="$e[6m"     # Probably won't work
46   a_inverse="$e[7m"
47   a_conceal="$e[8m"   # Probably won't work
48   a_strike="$e[9m"    # Probably won't work
49
50   # ANSI colors
51   a_red="$e[1;31m"
52   a_green="$e[1;32m"
53   a_yellow="$e[1;33m"
54   a_blue="$e[1;34m"
55   a_purple="$e[1;35m"
56   a_cyan="$e[1;36m"
57   a_white="$e[1;37m"
58   a_gloom="$e[1;30m"
59
60   a_crimson="$e[0;31m"
61   a_forest="$e[0;32m"
62   a_brown="$e[0;33m"
63   a_navy="$e[0;34m"
64   a_violet="$e[0;35m"
65   a_aqua="$e[0;36m"
66   a_gray="$e[0;37m"
67   a_black="$e[0;30m"
68
69   a_bred="$e[41m"
70   a_bgreen="$e[42m"
71   a_bbrown="$e[43m"
72   a_bblue="$e[44m"
73   a_bpurple="$e[45m"
74   a_bcyan="$e[46m"
75   a_bgray="$e[47m"
76   a_bblack="$e[40m"
77
78   # Normal is at the bottom, otherwise debugging via 'sh -x' is difficult
79   a_normal="$e[0m"
80
81   a() {
82     while [ "${1}" ]
83     do
84       eval "echo \${a_$1}"
85       shift
86     done
87   }
88 fi