linux shell gui,用户界面 – 如何使bash脚本的GUI?

在实际使用GUI对话之前,请考虑使用控制台提示。很多时候你可以用简单的“y / n?”提示,在bash中你通过

read command实现..

read -p "Do something? ";

if [ $REPLY == "y" ]; then

echo yay;

fi

如果控制台提示只是不会剪切它,Zenity是真的easy to use,例如:

zenity --error --text="Testing..."

zenity --question --text="Continue?"

这只适用于Linux / Gnome(或者更确切地说,它只会在这样的系统上默认安装)。读取方法将在几乎任何平台(包括无头机器,或通过SSH)

如果你需要更复杂的读取或Zenity提供,“改为C”是真正的最好的方法(虽然我建议Python / Ruby over C这样的shell脚本替换任务)

I want to do simple interface for some strange game,the progress bar for health or something is the example for what I want. Variable “HEALTH” is 34,so make progress bar filled in 34/100

作为命令行脚本,它将使用Python:

$ export HEALTH=34

$ python -c "import os; print '*' * int(os.environ.get('HEALTH',0))"

**********************************

或者标准化1和78之间的值(所以你不能在标准终端大小上包装):

$ python -c "import os; print '*' * int((int(os.environ.get('HEALTH',0)) / 100.0) * 78)"

#!/bin/sh

(

echo "10" ; sleep 1

echo "# Updating mail logs" ; sleep 1

echo "20" ; sleep 1

echo "# Resetting cron jobs" ; sleep 1

echo "50" ; sleep 1

echo "This line will just be ignored" ; sleep 1

echo "75" ; sleep 1

echo "# Rebooting system" ; sleep 1

echo "100" ; sleep 1

) |

zenity --progress \

--title="Update System Logs" \

--text="Scanning mail logs..." \

--percentage=0

if [ "$?" = -1 ] ; then

zenity --error \

--text="Update canceled."

fi

正如我之前说的,如果Zenity不能做你所需要的,看看在Python / Ruby / Perl / C / etc中把你的游戏作为一个“正确”脚本,因为它听起来像你在推动shell的边界-script可以做..

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值