Expect脚本的终端模拟与应用实践
1. 终端模拟绑定与功能实现
在终端模拟中,有一系列的绑定与功能实现。例如,对于特定的转义序列有相应的处理:
term_update_cursor
} "^\x1b\\\[H\x1b\\\[J" {
# (clear,cl) Clear screen
term_clear
term_update_cursor
} "^\x1b\\\[7m" {
# (smso,so) Begin standout mode
set term_standout 1
} "^\x1b\\\[m" {
# (rmso,se) End standout mode
set term_standout 0
}
这里, ^\x1b\\\[H\x1b\\\[J 用于清屏并更新光标位置, ^\x1b\\\[7m 开启突出显示模式, ^\x1b\\\[m 结束突出显示模式。
同时,还提供了一些按键绑定:
bind $term <Any-Enter> {
focus %W
}
bind $term <Meta-KeyPress> {
if {"%A" != ""} {
exp_send -i $term_spawn_id "\033%A"
}
}
bind $term <Any-KeyPress>
超级会员免费看
订阅专栏 解锁全文
55

被折叠的 条评论
为什么被折叠?



