linux - BASH:带方向键的子菜单

标签 linux bash menu submenu arrow-keys

我目前正在尝试更改 this script到带有子菜单的菜单。 问题是如果我进入子菜单,菜单不会完全清除。 它将主菜单的单行替换为子菜单的条目。

你知道我可以改变什么来让它工作吗?

这是我的最后一个版本

    #/bin/bash

E='echo -e';e='echo -en';trap "R;exit" 2
ESC=$( $e "\033")
TPUT(){ $e "\033[${1};${2}H";}
CL(){ $e "\033c";}
CIVIS(){ $e "\033[?25l";}
DRAW(){ $e "\033%@\033(0";}
WRITE(){ $e "\033(B";}
MARK(){ $e "\033[7m";}
UNMARK(){ $e "\033[27m";}
C(){ CL;}

    i=0;CL;CIVIS;NULL=/dev/null

ARROW(){ read -s -n3 key 2>/dev/null >&2
    if [[ $key = $ESC[A ]];then echo up;fi
    if [[ $key = $ESC[B ]];then echo dn;fi;}

POSITION(){ if [[ $cur = up ]];then ((i--));fi
    if [[ $cur = dn ]];then ((i++));fi
    if [[ i -lt 0   ]];then i=$LM;fi
    if [[ i -gt $LM ]];then i=0;fi;}

REFRESH(){ after=$((i+1)); before=$((i-1))
    if [[ $before -lt 0  ]];then before=$LM;fi
    if [[ $after -gt $LM ]];then after=0;fi
    if [[ $j -lt $i      ]];then UNMARK; M$before; else UNMARK; M$after;fi
    if [[ $after -eq 0   ]] || [[ $before -eq $LM ]];then
    UNMARK; M$before; M$after; fi; j=$i; UNMARK; M$before; M$after;}

M0(){ TPUT 3 4; $e "A) Firewall-Management & Gateway";}
M1(){ TPUT 4 4; $e "B) Bla bla bla";}

A0(){ TPUT 3 4; $e "1) Zweite Ebene";}
A1(){ TPUT 4 4; $e "2) Zweite Geile Ebene";}

MENU(){ LM=1; for each in $(seq 0 $LM);do M${each};done;}
INIT(){ MENU;}
SC(){ REFRESH;MARK;$S;cur=`ARROW`;}
ES(){ MARK;$e;read;INIT;};INIT

MENU2() {

    REFRESH(){ after=$((i+1)); before=$((i-1))
    if [[ $before -lt 0  ]];then before=$LM;fi
    if [[ $after -gt $LM ]];then after=0;fi
    if [[ $j -lt $i      ]];then UNMARK; A$before; else UNMARK; A$after;fi
    if [[ $after -eq 0   ]] || [[ $before -eq $LM ]];then
    UNMARK; A$before; A$after; fi; j=$i; UNMARK; A$before; A$after;}

    u_MENU() {
    LM=1; for each in $(seq 0 $LM);do A${each};done;}

    INIT(){ u_MENU;}
    SC(){ REFRESH;MARK;$S;cur=`ARROW`;}
    ES(){ MARK;$e;read;INIT;};INIT

while [[ "$O" != " " ]]; do case $i in
      0) S=A0;SC;if [[ $cur = "" ]];then C; exit 0;fi;;
      1) S=A1;SC;if [[ $cur = "" ]];then C; $e "a3:\n$(route -n )\n";ES;fi;;
        esac;POSITION;done
}

while [[ "$O" != " " ]]; do case $i in
      0) S=M0;SC;if [[ $cur = "" ]];then C; MENU2;ES;fi;;
      1) S=M1;SC;if [[ $cur = "" ]];then C;exit 0;ES;fi;;
esac;POSITION;done

最佳答案

1)

whileMENU2 中循环:

-        esac;POSITION;C;done
+        esac;POSITION;done

尝试将背景设置回蓝色。您会看到 C 似乎输出换行符。

2)

REFRESH调用了M0/M1/M2,所以我们需要添加一个新的REFRESH MENU2 中调用 A0/A1/A2:

REFRESH(){ after=$((i+1)); before=$((i-1))
        if [[ $before -lt 0  ]];then before=$LM;fi
        if [[ $after -gt $LM ]];then after=0;fi
        if [[ $j -lt $i      ]];then UNMARK; A$before; else UNMARK; A$after;fi
        if [[ $after -eq 0   ]] || [[ $before -eq $LM ]];then
        UNMARK; A$before; A$after; fi; j=$i; UNMARK; A$before; A$after;}

关于linux - BASH:带方向键的子菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49531797/

相关文章:

linux - X10 - 多地点的段错误

linux - 从 shell 编写 shell 脚本,还是从 shell 脚本编写?

linux - 使用 SED 替换长字符串 - 但在正则表达式中得到未终止的替换

java - 子文件夹不是通过 java 通过 scp 命令复制的

bash - 我可以从命令行启动 pgAdmin3 吗?

css - 水平菜单/列表对齐问题

css - 如何修复 Wordpress 中的 float 菜单?

linux - 在 Bash 脚本中运行用户安装的二进制文件

linux - sh - 按分隔符分割字符串

html - Accordion 展开折叠,多一种选择