学习完 bash 操作屏幕的成果

sh/bash/dash/ksh/zsh等Shell脚本
回复
头像
cjxgm
帖子: 1952
注册时间: 2010-04-23 20:40
系统: Arch Linux
来自: 浙江·杭州
联系:

学习完 bash 操作屏幕的成果

#1

帖子 cjxgm » 2011-08-03 20:48

[bash]#!/bin/bash

# Screen-funcs

# proto: e(...)
# Print a Command Sequence Introducer
e() { echo -ne "\e[$*"; }

# proto: pos(y, x)
# Position the cursor
pos() { e "$1;$2H"; }

# proto: topleft()
# Move cursor to the top-left corner
topleft() { e "H"; }

# proto: clear_screen()
# Clear screen but do NOT move the cursor
clear_screen() { e "J"; }

# proto: cls()
# Clear screen and move the cursor
cls() { topleft; clear_screen; }

# proto: cl_XoY()
# Clear XoY, where X = E(nd) / B(egining)
# and Y = L(ine) / S(creen).
cl_eol() { e "K"; }
cl_bol() { e "1K"; }
cl_eos() { e "0J"; }
cl_bos() { e "1J"; }

# proto: cu_hide(), cu_show()
# Hide/show cursor
cu_hide() { e "?25l"; }
cu_show() { e "?12l"; e "?25h"; }

# proto: cu_save(), cu_restore()
# Save/restore cursor position
cu_save() { e "s"; }
cu_restore() { e "u"; }

# FIXME: This don't work.
## proto: cu_D()
## Move cursor D, where D = up / down / left / right
#cu_up() { e "1A"; }
#cu_down() { e "1B"; }
#cu_left() { e "1C"; }
#cu_right() { e "1D"; }

# proto: attr(attr), sfg(color), sbg(color), rac()
# Set attribute / screen fg color
# / screen bg color, and restore attrs & colors.
# attr:
BOLD=1
UL=4 # UnderLine
REV=7 # REVerse
# color:
BLACK=0
RED=1
GREEN=2
YELLOW=3
BLUE=4
MAGENTA=5
CYAN=6
WHITE=7
# function:
attr() { e "$1m"; }
sfg() { e "3$1m"; }
sbg() { e "4$1m"; }
rac() { e "m"; }

# Test

rac

cls
cu_save
cu_hide
sleep 1
pos 5 3
attr $BOLD
echo 囗囗囗囗
cu_show
sleep 1
cu_restore
sleep 1

cu_hide
attr $UL
sfg $BLUE
for i in `seq 0 70`; do
echo -n "F"
sleep 0.01
done

sbg $YELLOW
for i in `seq 0 70`; do
echo -ne "\bF\b"
sleep 0.01
done

attr $REV
for i in `seq 0 70`; do
echo -n "F"
sleep 0.01
done

rac
attr "$UL"
sfg $GREEN
for i in `seq 0 70`; do
echo -ne "\bF\b"
sleep 0.01
done

rac
attr "$BOLD"
sfg $RED
for i in `seq 0 70`; do
echo -n "F"
sleep 0.01
done
echo

sfg $YELLOW
for i in `seq 0 70`; do
echo -n "u"
sleep 0.01
done
echo

sfg $CYAN
for i in `seq 0 70`; do
echo -n "c"
sleep 0.01
done
echo

sfg $MAGENTA
for i in `seq 0 70`; do
echo -n "k"
sleep 0.01
done
echo

rac
cu_save
attr $BOLD
pos 5 10
echo -n "^_^"
cu_restore
cu_show
sleep 2
[/bash]
很口口的一个动画 :em05
Clanjor Prods. | Develop for Developers. (C++, Lua) | 作曲编曲 | 实时渲染引擎
头像
黄美姬
帖子: 8428
注册时间: 2009-10-08 11:15
来自: 大城市铁岭

Re: 学习完 bash 操作屏幕的成果

#2

帖子 黄美姬 » 2011-08-03 21:17

无图无真相
我们是命运的妓女,它把我们都嫖了

N卡驱动:http://www.nvidia.cn/Download/index.aspx?lang=cn
极品飞车:http://www.geforce.cn/optimize/optimal- ... ts-450-ops
孤岛危机优化设置:http://www.geforce.cn/optimize/optimal- ... tx-450-ops
:cp /etc/skel/.bashrc ~/
PS1="\[\e]2;\u@\H \w\a\e[32;1m\]\T$\[\e[0m\] "
http://cdimage.ubuntu.com/
http://releases.ubuntu.com/
头像
月下叹逍遥
论坛版主
帖子: 33994
注册时间: 2010-10-07 14:23
系统: Archdows10
来自: 某系某星某洲某国某省某市
联系:

Re: 学习完 bash 操作屏幕的成果

#3

帖子 月下叹逍遥 » 2011-08-04 10:08

狠口口……
浮生七十今三十,从此凄惶未可知
回复