我在 Python3 中有以下基本的诅咒实现。
#!/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 数据通常保存到结构中以进行恢复……这可能是一种追求途径。
谢谢你的帮助!