Changing UNIX tty driver keys -- Suggested changes to "termios" module

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Derek Peschel

    #1

    Changing UNIX tty driver keys -- Suggested changes to "termios" module

    Should I add an RFE to SourceForge too? I'd like a wide audience in case
    someone has enough experience to comment or is solving the same problem.

    I'm using the urwid library which uses curses. On my system (Mac OS 10.3.7)
    I specifically have ncurses. The programs I'm running turn off echoing and
    set raw mode but don't disable interrupts. For development purposes I like
    having interrupts, but my preferred keystrokes (WordStar) conflict with the
    tty driver's use of ^C, ^Z, ^V, and maybe other keys.

    Here's a piece of code based on the example in section 8.8.1 of the Python
    Library Reference. It doesn't handle ^V yet.
    ------------------------------------------------------------------------------
    termios_cc = 6 # magic index -- not 4 which is position
    # in the C struct
    termios__POSIX_ VDISABLE = '\xff' # signals are set to this
    # when they don't corres-
    # pond to any char.

    fd = sys.stdin.filen o()
    oldterm = termios.tcgetat tr(fd)
    oldterm_int = oldterm[termios_cc][termios.VINTR]
    oldterm_quit = oldterm[termios_cc][termios.VQUIT]
    if ord(oldterm_int ) != 3: # ^C
    sys.exit("inter rupt char isn't ^C")
    if ord(oldterm_qui t) != 28: # ^\
    sys.exit("quit char isn't ^\\")
    # no way to check whether applications (telnet, screen)
    # are looking for ^^
    # no check yet for any signals set to ^^

    newterm = termios.tcgetat tr(fd)
    newterm[termios_cc][termios.VQUIT] = chr(30) # ^^
    newterm[termios_cc][termios.VINTR] = chr(28) # ^\
    try:
    termios.tcsetat tr(fd, termios.TCSADRA IN, newterm)
    self.ui.run_wra pper(self.run)
    finally:
    termios.tcsetat tr(fd, termios.TCSADRA IN, oldterm)
    ------------------------------------------------------------------------------

    I'd like to handle errors and race conditions better, but I don't know what
    kinds can happen in practice. I'd also like to make the code work on other
    versions of UNIX.

    Easy suggested improvements to the library: Define _POSIX_VDISABLE and names
    for the fields of the struct, so that termios__POSIX_ VDISABLE and termios_cc
    become termios._POSIX_ VDISABLE and termios.cc.

    Harder improvements: Some functions that abstract the things I'm doing
    (checking the current characters, changing a group of them in one operation).
    I assume two signals should never be set to the same character, unless they
    are disabled. Is it possible to make the state variables invisible? Is that
    a good idea?

    Thanks,

    -- Derek
Working...