sistema_progs

Programas para customizar o meu entorno de traballo nos meus equipos persoais
Log | Files | Refs

sample.RandomColor2.bash (1361B)


      1 # ble/contrib/layer/sample.RandomColor2.bash (C) 2015, akinomyoga
      2 #
      3 # This is a sample implementation of a highlighting layer.  This defines a
      4 # random-color layer named `RandomColor2'.  To use the layer, the layer name can
      5 # be inserted in the array `_ble_highlight_layer_list`:
      6 #
      7 # ```bash
      8 # ble-import layer/sample.RandomColor2
      9 # ble/array#insert-before _ble_highlight_layer_list syntax RandomColor2
     10 # ```
     11 #
     12 # Note: This code was first introduced in commit ec3f3661b@akinomyoga/ble.sh
     13 # (2015-02-23) but later moved to contrib in refactoring on 2023-09-19.
     14 
     15 _ble_highlight_layer_RandomColor2_buff=()
     16 
     17 function ble/highlight/layer:RandomColor2/update {
     18   local text=$1 ret i x
     19   ble/highlight/layer/update/shift _ble_highlight_layer_RandomColor2_buff
     20   for ((i=DMIN;i<DMAX;i++)); do
     21     ble/color/gspec2sgr "fg=$((16+(x=RANDOM%27)*4-x%9*2-x%3))"
     22     _ble_highlight_layer_RandomColor2_buff[i]=$ret${_ble_highlight_layer_plain_buff[i]}
     23   done
     24   PREV_BUFF=_ble_highlight_layer_RandomColor2_buff
     25   ((PREV_UMIN=0,PREV_UMAX=${#text}))
     26 }
     27 
     28 function ble/highlight/layer:RandomColor2/getg {
     29   # ここでは乱数を返しているが、実際は
     30   # PREV_BUFF=_ble_highlight_layer_RandomColor2_buff
     31   # に設定した物に対応する物を指定しないと表示が変になる。
     32   local x ret
     33   ble/color/gspec2g "fg=$((16+(x=RANDOM%27)*4-x%9*2-x%3))"; g=$ret
     34 }