当我在运行高山分布的Docker容器中apk add python3
时,像Ctrl <left arrow>
这样的组合键,而不是用整个单词移动光标,打印这样的东西(这里,我输入&#39;垃圾邮件鸡蛋然后按住控件并点击左箭头键:
Python 3.5.1 (default, Dec 9 2015, 14:41:32)
[GCC 5.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> spam ham;5D
仅仅apk add
readline
或pip3 install
它本身并不能解决问题。
如何在这种环境下让readline使用python?
答案 0 :(得分:5)
看起来这个问题的关键主要是让readline正常工作,但你也可能需要正确处理你的TERM。
我试过像这样的Dockerfile:
FROM alpine
RUN apk update && \
apk add python3 python3-dev build-base ncurses-dev bash && \
python3 -m ensurepip && \
pip3 install readline
COPY ./inputrc /etc/inputrc
使用https://github.com/frol/docker-alpine-env/blob/master/etc/inputrc中的inputrc,复制如下:
# do not bell on tab-completion
#set bell-style none
set meta-flag on
set input-meta on
set convert-meta off
set output-meta on
$if mode=emacs
# for linux console and RH/Debian xterm
"\e[1~": beginning-of-line
"\e[4~": end-of-line
"\e[5~": beginning-of-history
"\e[6~": end-of-history
"\e[7~": beginning-of-line
"\e[3~": delete-char
"\e[2~": quoted-insert
"\e[5C": forward-word
"\e[5D": backward-word
"\e\e[C": forward-word
"\e\e[D": backward-word
"\e[1;5C": forward-word
"\e[1;5D": backward-word
# for rxvt
"\e[8~": end-of-line
# for non RH/Debian xterm, can't hurt for RH/DEbian xterm
"\eOH": beginning-of-line
"\eOF": end-of-line
# for freebsd console
"\e[H": beginning-of-line
"\e[F": end-of-line
$endif
以下是我从以下网站收集的一些链接:
注意 - 我知道安装bash似乎很愚蠢,但pip3 install readline
没有它就失败了。如果您需要通过apk del
进行一些操作,可以在此之后进行清理,这也不是必须安装gcc等的理想选择。
有了这一切,它在我的Mac上工作,但不是立即在腻子上,虽然我怀疑只是TERM设置,YMMV。