staging.inyokaproject.org

Bash Menu

Status: Ungelöst | Ubuntu-Version: Kein Ubuntu
Antworten |

gerasifbesmumu

Anmeldungsdatum:
11. Dezember 2019

Beiträge: Zähle...

Hallo, 😉 es geht um dieser code "Menu".

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
Code

function select_option {
                ESC=$( printf "\033")
                cursor_blink_on()  { printf "${ESC}[?25h%s"; }
                cursor_blink_off() { printf "${ESC}[?25l%s"; }
                cursor_to()        { printf "${ESC}[$1;${2:-1}H%s"; }
                print_option()     { printf "   $1%s "; }
                print_selected()   { printf "  ${ESC}[7m%s $1 ${ESC}[27m"; }
                get_cursor_row()   { IFS=';' read -r -sdR -p $'\E[6n' ROW COL; echo "${ROW#*[}"; }
                key_input()        { read -r -s -n3 key 2>/dev/null >&2
                if [[ $key = ${ESC}[A ]]; then echo up;    fi
                if [[ $key = ${ESC}[B ]]; then echo down;  fi
                if [[ $key = ""     ]]; then echo enter; fi; }
                for opt; do printf "\n"; done
                    lastrow=$(get_cursor_row)
                    local startrow=$((lastrow - COL))
                    trap "cursor_blink_on; stty echo; printf '\n'; exit" 2
                    cursor_blink_off
                    local selected=0
                    while true; do
                        local idx=0
                        for opt; do
                            cursor_to $((startrow + idx))
                            if [ $idx -eq $selected ]; then
                                print_selected "$opt"
                            else
                                print_option "$opt"
                            fi
                            ((idx++))
                        done
                        case $(key_input) in
                            enter) break;;
                            up)    ((selected--));
                                if [ $selected -lt 0 ]; then selected=$(($# - 1)); fi;;
                            down)  ((selected++));
                                if [ "$selected" -ge $# ]; then selected=0; fi;;
                        esac
                    done
                    cursor_to "$lastrow"
                    printf "\n"
                    cursor_blink_on
                return $selected
            }

ich möchte gerne erweitern:

  1. wenn mehr als 20 einträge, soll in nächste spalte anzeigen!

  2. cursor eweitern, auf rechs, links, oben, und unter, um schnelle auszuwählen!

Danke 👍

Bearbeitet von rklm:

Aufzählung. Bitte beachte Forum/Syntax und nutze die Vorschaufunktion!

Antworten |