There are two ways to configure the underlying readline library, using a configuration file or the parse_and_bind() function. Configuration options include the keybinding to invoke completion, editing modes (vi or emacs), and many other values. Refer to the GNU readline library documentation for details.
The easiest way to enable tab-completion is through a call to parse_and_bind(). Other options can be set at the same time. This example changes the default editing controls to use “vi” mode instead of the default of “emacs”. To edit the line, press ESC then normal vi navigation keys.
import readline
readline.parse_and_bind('tab: complete')
readline.parse_and_bind('set editing-mode vi')
while True:
line = raw_input('Prompt ("stop" to quit): ')
if line == 'stop':
break
print 'ENTERED: "%s"' % line
The same configuration can be stored as instructions in a file read by the library with a single call. If myreadline.rc contains:
# Turn on tab completion
tab: complete
# Use vi editing mode instead of emacs
set editing-mode vi
the file can be read with read_init_file():
import readline
readline.read_init_file('myreadline.rc')
while True:
line = raw_input('Prompt ("stop" to quit): ')
if line == 'stop':
break
print 'ENTERED: "%s"' % line
分享到:
相关推荐
readline
readline-5.1.tar.gz
包含readline-7.0.tar.gzr和readline-7.0-10.el8.src.rpm两个安装包,可以直接解压tar包编译安装,也可以通过rpm方式安装源码。解压后在源码目录执行以下指令可完成编译和安装: #./configure #make #make install ...
readline-devel-6.2-10.el7.x86_64.rpm
readline-6.2-11.el7.x86_64.rpm
readline-devel-6.2-11.el7.x86_64.rpm
ncurses-base-5.7-4.20090207.el6.x86_64.rpm、ncurses-devel-5.7-4.20090207.el6.x86_64.rpm、ncurses-libs-5.7-4.20090207.el6.x86_64.rpm、readline-devel-6.0-4.el6.x86_64.rpm
readline-devel 用于 AMD下那颗gru工具的安装,所需要的依赖
Linux上使用SQL*Plus有一个相当不方便的地方,那就是没有历史回调功能。在Windows上的SQL*Plus可以用“向上向下”箭头来调用之前使用过的命令,修改、编辑...安装Uniread之前先安装 readline,Term,IO这3个工具。
原理讲解-ServletInputStream.readLine(byte[] b, int off, int len) 方法原理讲解-ServletInputStream.readLine(byte[] b, int off, int len) 方法
手动安装readline-devel-6.0-4.el6.x86_64。完美解决报错:readline-devel-6.0-4.el6.x86_64: failure: Packages/readline-devel-6.0-4.el6.x86_64.rpm from c6-media
GNU Readline Library 编程指南, Readline库说明和编程范例. 命令行编程利器.
readline-4.3.tar.gz
readline-5.1-3.el5 安装uniread前必须的包
Linux上使用SQL*Plus有一个相当不方便的地方,那就是没有历史回调功能。在Windows上的SQL*Plus可以用“向上向下”箭头来调用之前使用过的命令,修改、编辑...安装Uniread之前先安装 readline,Term,IO这3个工具。
compat-readline5-5.2-17.1.el6.i686.rpm是centos工具包。
readline-5.0.tar.gz.
readline-7.0.tar.gz,方便查找下载,解压后直接通过指令进行安装
readline-7.0.tar.gz