colours 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. #!/bin/sh
  2. # http://misc.flogisoft.com/bash/tip_colors_and_formatting
  3. # http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/the-elegant-useless-clock-prompt.html
  4. # http://www.thegeekstuff.com/2011/01/tput-command-examples/
  5. print_range() {
  6. prefix=$1
  7. range_low=$2
  8. range_high=$3
  9. suffix=$4
  10. count=$range_low
  11. while [ $count -le $range_high ]; do
  12. printf '%s%sm[%3s]%s\t' $prefix "$count" "$count" $suffix
  13. count=$(( $count + 1 ))
  14. done
  15. printf '\n'
  16. }
  17. print_cont() {
  18. print_range '[' '0' '7' ''
  19. printf '\n'
  20. }
  21. print_ansi() {
  22. print_range '[' '30' '37' ''
  23. print_range '[' '90' '97' ''
  24. print_range '[' '40' '47' ''
  25. print_range '[' '100' '107' ''
  26. printf '\n'
  27. }
  28. print_num() {
  29. step=6
  30. low=16
  31. max=231
  32. case "$1" in
  33. '0')
  34. step=8
  35. low=0
  36. max=15
  37. ;;
  38. [:1-6:])
  39. low=$(( 16 + ( ( $1 - 1 ) * ( $step * $step ) ) ))
  40. max=$(( 16 + ( $1 * ( $step * $step ) ) - 1 ))
  41. ;;
  42. '7')
  43. low=232
  44. max=255
  45. ;;
  46. esac
  47. printf '\nColors %s-%s\n\n' $low $max
  48. high=$(( $low + $step - 1 ))
  49. while [ $high -le $max ]; do
  50. print_range '[48;5;' "$low" "$high" ''
  51. low=$(( $low + $step ))
  52. high=$(( $high + $step ))
  53. done
  54. printf '\n'
  55. }
  56. print_hex() {
  57. step=6
  58. low=16
  59. case "$1" in
  60. [:1-6:])
  61. block=$(( $1 - 1 ))
  62. low=$(( 16 + ( $block * $step ) ))
  63. inc=$(( $step * $step ))
  64. high=$(( $low + $step - 1 ))
  65. max=$(( $low + ( $step * $inc ) ))
  66. printf '\nColors %s-%s\n\n' $low $max
  67. while [ $high -le $max ]; do
  68. print_range '[48;5;' "$low" "$high" ''
  69. low=$(( $low + $inc ))
  70. high=$(( $high + $inc ))
  71. done
  72. ;;
  73. *)
  74. max=231
  75. high=$(( $low + $step - 1 ))
  76. block=0
  77. base=$low
  78. inc=$(( $step * $step ))
  79. printf '\nColors %s-%s\n\n' $low $max
  80. while [ $block -lt 6 ]; do
  81. while [ $high -le $max ]; do
  82. print_range '[48;5;' "$low" "$high" ''
  83. low=$(( $low + $inc ))
  84. high=$(( $high + $inc ))
  85. done
  86. block=$(( $block + 1 ))
  87. base=$(( $base + $step ))
  88. low=$base
  89. high=$(( $low + $step - 1 ))
  90. done
  91. ;;
  92. esac
  93. printf '\n'
  94. }
  95. clear_scr() {
  96. clear
  97. cat << END
  98. . .
  99. :,,, . . ,,,:
  100. Y888888bo. : : .od888888Y
  101. 8888888888b. : : .d8888888888
  102. 88888Y Y8b. . . .d8Y Y88888
  103. j88888 .db. Yb. . . .dY .db. 88888k
  104. 888 Y88Y b ( ) d Y88Y 888
  105. 888b ,., d888
  106. j888888bd8gf .:. ?g8bd888888k
  107. Y .8 d: :b 8. Y
  108. : .8 db d : : b db 8. :
  109. d88 8 : : 8 88b
  110. d888b .g8 . 8g. d888b
  111. :888888888Y Y888888888:
  112. ______ : 8888888 _______ 8888888 : ______
  113. 8Y Y Y Y8
  114. Y Terminal Y
  115. : Colors :
  116. END
  117. }
  118. while true
  119. do
  120. clear_scr
  121. printf '\t1) control chars\n'
  122. printf '\t2) colours 30-37\n'
  123. printf '\t3) colours 0-15\n'
  124. printf '\t4) colours 0-87\n'
  125. printf '\t5) 16-231 pallet 1\n'
  126. printf '\t6) 16-231 pallet 2\n'
  127. printf '\t7) 232-255 grayscale\n'
  128. printf '\n\tq) quit\n'
  129. printf ' _________________________________________ \n\n'
  130. echo '[1-6q] '
  131. read com
  132. # printf '[1-6q] '
  133. # trap 'stty -raw' EXIT
  134. # stty raw
  135. # com=$(dd count=1 bs=1 2>/dev/null)
  136. # stty -raw
  137. case "$com" in
  138. '')
  139. read -n 2 inp
  140. echo "$inp"
  141. [[ "$inp" = '' ]] && echo yep
  142. [[ "$@" = '' ]] && read inp
  143. echo 'press any key '
  144. read inp
  145. ;;
  146. '1')
  147. clear_scr
  148. print_cont
  149. echo 'press any key '
  150. read inp
  151. ;;
  152. '2')
  153. clear_scr
  154. print_ansi
  155. echo 'press any key '
  156. read inp
  157. ;;
  158. '3')
  159. clear_scr
  160. print_num 0
  161. echo 'press any key '
  162. read inp
  163. ;;
  164. '4')
  165. clear_scr
  166. print_num 0
  167. print_num 1
  168. print_num 2
  169. echo 'press any key '
  170. read inp
  171. ;;
  172. '5')
  173. while true
  174. do
  175. clear_scr
  176. print_num "$inp"
  177. echo '[0-7q] '
  178. read inp
  179. if [ "$inp" = 'q' ];
  180. then
  181. clear_scr
  182. break
  183. fi
  184. done
  185. ;;
  186. '6')
  187. while true
  188. do
  189. clear_scr
  190. print_hex "$inp"
  191. echo '[1-6q] '
  192. read inp
  193. if [ "$inp" = 'q' ];
  194. then
  195. clear_scr
  196. break
  197. fi
  198. done
  199. ;;
  200. '7')
  201. clear_scr
  202. print_num 7
  203. echo 'press any key '
  204. read inp
  205. ;;
  206. 'q')
  207. clear_scr
  208. exit
  209. ;;
  210. esac
  211. done