【发布时间】:2018-07-09 14:40:27
【问题描述】:
我在 Python3 中有以下基本的 curses 实现。
#!/usr/bin/env python3
import curses
import time
from curses import wrapper
stdscr = curses.initscr() # required
curses.noecho() # don't show keyboard input
curses.cbreak() # don't require enter to send input
stdscr.keypad(True)
def main(stdscr):
# curses.newwin(5, 10, 7, 20)
stdscr.addstr("SUMMON SHOGGOTHS")
stdscr.addstr(20, 30, "Razzmatazz")
stdscr.refresh()
time.sleep(3)
wrapper(main)
# Unwind
curses.nocbreak()
stdscr.keypad(False)
curses.echo()
curses.endwin()
几乎所有事情都发生了我所期望的:Shoggoths 被召唤,Razzes 被matazzed,然而当我输入 git status 时,我的换行符被打破了。
在显示前后stty -a 之间进行比较:
5c5
< iflags: -istrip icrnl -inlcr -igncr ixon -ixoff ixany imaxbel -iutf8
---
> iflags: -istrip -icrnl -inlcr -igncr ixon -ixoff ixany imaxbel -iutf8
7c7
< oflags: opost onlcr -oxtabs -onocr -onlret
---
> oflags: opost -onlcr -oxtabs -onocr -onlret
在调查了这些选项后,我发现发出stty onlcr 可以修复终端。然而,我很惊讶,因为我认为curses.endwin() 会重置我:
取消初始化库,使终端恢复正常状态。
我认为这可能是 iTerm2 中的问题,所以我尝试使用 Terminal.app。这产生了相同的行为。
我很难过,还有其他的重置技术吗?我在基于 C 的实现中看到 stty 数据通常保存到结构中以进行恢复……这可能是一种追求。
感谢您的帮助!
【问题讨论】:
标签: python terminal curses stty