2

当我apk add python3在运行 alpine 发行版的 Docker 容器中时,像这样的组合键Ctrl <left arrow>,而不是按整个单词移动光标,打印这样的内容(在这里,我输入了“垃圾邮件鸡蛋”,然后按住 control 并按下左箭头键):

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 addingreadlinepip3 installing 它本身并不能解决问题。

如何在这种环境中让 readline 与 python 一起工作?

4

1 回答 1

6

看起来这主要是让 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没有它就会失败。必须安装 gcc 等也不理想,但如果您需要apk del-ing 一些东西,您可以在此之后进行清理。

有了这一切,它就可以在我的 mac 上运行,但不能立即在 putty 上运行,尽管我怀疑只是 TERM 设置,YMMV。

于 2016-05-10T15:19:57.703 回答