我目前正在尝试更改 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)
while
在 MENU2
中循环:
- 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/