module 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. #!/bin/bash
  2. # interfas de colores
  3. msg(){
  4. COLOR[0]='\033[1;37m' #BRAN='\033[1;37m'
  5. COLOR[1]='\e[31m' #VERMELHO='\e[31m'
  6. COLOR[2]='\e[32m' #VERDE='\e[32m'
  7. COLOR[3]='\e[33m' #AMARELO='\e[33m'
  8. COLOR[4]='\e[34m' #AZUL='\e[34m'
  9. COLOR[5]='\e[91m' #MAGENTA='\e[35m'
  10. COLOR[6]='\033[1;97m' #MAG='\033[1;36m'
  11. COLOR[7]='\e[36m' #teal='\e[36m'
  12. COLOR[8]='\e[30m' #negro='\e[30m'
  13. COLOR[9]='\033[34m' #blue='\033[1;34m'
  14. NEGRITO='\e[1m'
  15. SEMCOR='\e[0m'
  16. case $1 in
  17. -ne) cor="${COLOR[1]}${NEGRITO}" && echo -ne "${cor}${2}${SEMCOR}";;
  18. -nazu) cor="${COLOR[6]}${NEGRITO}" && echo -ne "${cor}${2}${SEMCOR}";;
  19. -nverd)cor="${COLOR[2]}${NEGRITO}" && echo -ne "${cor}${2}${SEMCOR}";;
  20. -nama) cor="${COLOR[3]}${NEGRITO}" && echo -ne "${cor}${2}${SEMCOR}";;
  21. -ama) cor="${COLOR[3]}${NEGRITO}" && echo -e "${cor}${2}${SEMCOR}";;
  22. -verm) cor="${COLOR[3]}${NEGRITO}[!] ${COLOR[1]}" && echo -e "${cor}${2}${SEMCOR}";;
  23. -verm2)cor="${COLOR[1]}${NEGRITO}" && echo -e "${cor}${2}${SEMCOR}";;
  24. -verm3)cor="${COLOR[1]}" && echo -e "${cor}${2}${SEMCOR}";;
  25. -teal) cor="${COLOR[7]}${NEGRITO}" && echo -e "${cor}${2}${SEMCOR}";;
  26. -teal2)cor="${COLOR[7]}" && echo -e "${cor}${2}${SEMCOR}";;
  27. -blak) cor="${COLOR[8]}${NEGRITO}" && echo -e "${cor}${2}${SEMCOR}";;
  28. -blak2)cor="${COLOR[8]}" && echo -e "${cor}${2}${SEMCOR}";;
  29. -azu) cor="${COLOR[6]}${NEGRITO}" && echo -e "${cor}${2}${SEMCOR}";;
  30. -blu) cor="${COLOR[9]}${NEGRITO}" && echo -e "${cor}${2}${SEMCOR}";;
  31. -blu1) cor="${COLOR[9]}" && echo -e "${cor}${2}${SEMCOR}";;
  32. -verd) cor="${COLOR[2]}${NEGRITO}" && echo -e "${cor}${2}${SEMCOR}";;
  33. -bra) cor="${COLOR[0]}${NEGRITO}" && echo -e "${cor}${2}${SEMCOR}";;
  34. -bar) cor="${COLOR[1]}=====================================================" && echo -e "${SEMCOR}${cor}${SEMCOR}";;
  35. -bar2) cor="${COLOR[7]}=====================================================" && echo -e "${SEMCOR}${cor}${SEMCOR}";;
  36. -bar3) cor="${COLOR[1]}-----------------------------------------------------" && echo -e "${SEMCOR}${cor}${SEMCOR}";;
  37. -bar4) cor="${COLOR[7]}-----------------------------------------------------" && echo -e "${SEMCOR}${cor}${SEMCOR}";;
  38. esac
  39. }
  40. # centrado de texto
  41. print_center(){
  42. if [[ -z $2 ]]; then
  43. text="$1"
  44. else
  45. col="$1"
  46. text="$2"
  47. fi
  48. while read line; do
  49. unset space
  50. x=$(( ( 54 - ${#line}) / 2))
  51. for (( i = 0; i < $x; i++ )); do
  52. space+=' '
  53. done
  54. space+="$line"
  55. if [[ -z $2 ]]; then
  56. msg -azu "$space"
  57. else
  58. msg "$col" "$space"
  59. fi
  60. done <<< $(echo -e "$text")
  61. }
  62. #print_center2(){
  63. # local x
  64. # local y
  65. # #text="$*"
  66. # text="$2"
  67. # #x=$(( ($(tput cols) - ${#text}) / 2))
  68. # x=$(( ( 54 - ${#text}) / 2))
  69. # echo -ne "\E[6n";read -sdR y; y=$(echo -ne "${y#*[}" | cut -d';' -f1)
  70. # #echo -e "\033[${y};${x}f$*"
  71. # msg "$1" "\033[${y};${x}f$2"
  72. #}
  73. # titulos y encabesados
  74. title(){
  75. clear
  76. msg -bar
  77. if [[ -z $2 ]]; then
  78. print_center -azu "$1"
  79. else
  80. print_center "$1" "$2"
  81. fi
  82. msg -bar
  83. }
  84. # finalizacion de tareas
  85. enter(){
  86. msg -bar
  87. text="►► Presione enter para continuar ◄◄"
  88. if [[ -z $1 ]]; then
  89. print_center -ama "$text"
  90. else
  91. print_center "$1" "$text"
  92. fi
  93. read
  94. }
  95. # opcion, regresar volver/atras
  96. back(){
  97. msg -bar
  98. echo -ne "$(msg -verd " [0]") $(msg -verm2 ">") " && msg -bra "\033[1;41mVOLVER"
  99. msg -bar
  100. }
  101. # menu maker (opciones 1, 2, 3,.....)
  102. menu_func(){
  103. local options=${#@}
  104. local array
  105. for((num=1; num<=$options; num++)); do
  106. echo -ne "$(msg -verd " [$num]") $(msg -verm2 ">") "
  107. array=(${!num})
  108. case ${array[0]} in
  109. "-vd")echo -e "\033[1;33m[!]\033[1;32m ${array[@]:1}";;
  110. "-vm")echo -e "\033[1;33m[!]\033[1;31m ${array[@]:1}";;
  111. "-fi")echo -e "${array[@]:2} ${array[1]}";;
  112. -bar|-bar2|-bar3|-bar4)echo -e "\033[1;37m${array[@]:1}\n$(msg ${array[0]})";;
  113. *)echo -e "\033[1;37m${array[@]}";;
  114. esac
  115. done
  116. }
  117. # opcion de seleccion numerica
  118. selection_fun(){
  119. local selection="null"
  120. local range
  121. if [[ -z $2 ]]; then
  122. opcion=$1
  123. col="-nazu"
  124. else
  125. opcion=$2
  126. col=$1
  127. fi
  128. for((i=0; i<=$opcion; i++)); do range[$i]="$i "; done
  129. while [[ ! $(echo ${range[*]}|grep -w "$selection") ]]; do
  130. msg "$col" " Selecione una Opcion: " >&2
  131. read selection
  132. tput cuu1 >&2 && tput dl1 >&2
  133. done
  134. echo $selection
  135. }
  136. in_opcion(){
  137. unset opcion
  138. if [[ -z $2 ]]; then
  139. msg -nazu " $1: " >&2
  140. else
  141. msg $1 " $2: " >&2
  142. fi
  143. read opcion
  144. echo "$opcion"
  145. }
  146. in_opcion_down(){
  147. dat=$1
  148. length=${#dat}
  149. cal=$(( 22 - $length / 2 ))
  150. line=''
  151. for (( i = 0; i < $cal; i++ )); do
  152. line+='╼'
  153. done
  154. echo -e " $(msg -verm3 "╭$line╼[")$(msg -azu "$dat")$(msg -verm3 "]")"
  155. echo -ne " $(msg -verm3 "╰╼")\033[37;1m> " && read opcion
  156. }
  157. export -f msg
  158. export -f selection_fun
  159. export -f menu_func
  160. export -f print_center
  161. export -f title
  162. export -f back
  163. export -f enter
  164. export -f in_opcion
  165. export -f in_opcion_down