put the terminal into raw mode

For whatever reason, urwid puts the terminal into cbreak mode during
initialization. If we put the terminal into raw mode instead, then we
don't have to ignore SIGINT and SIGQUIT, which is good, because when we
support dropping to a subshell we don't want to run that subshell with
those signals ignored, because that is extremely confusing.

This also lets me dump the code that puts the terminal into raw mode
during keyboard detection.
This commit is contained in:
Michael Hudson-Doyle 2019-08-15 13:50:23 +12:00
parent 8b2a59bf2e
commit 90d376fbbd
3 changed files with 6 additions and 26 deletions

View File

@ -17,7 +17,6 @@
import argparse import argparse
import sys import sys
import logging import logging
import signal
from subiquitycore.log import setup_logger from subiquitycore.log import setup_logger
from subiquitycore import __version__ as VERSION from subiquitycore import __version__ as VERSION
from console_conf.core import ConsoleConf from console_conf.core import ConsoleConf
@ -83,9 +82,6 @@ def main():
logger.info("Starting console-conf v{}".format(VERSION)) logger.info("Starting console-conf v{}".format(VERSION))
logger.info("Arguments passed: {}".format(sys.argv)) logger.info("Arguments passed: {}".format(sys.argv))
signal.signal(signal.SIGINT, signal.SIG_IGN)
signal.signal(signal.SIGQUIT, signal.SIG_IGN)
env_ok = environment_check(ENVIRONMENT) env_ok = environment_check(ENVIRONMENT)
if env_ok is False and not opts.dry_run: if env_ok is False and not opts.dry_run:
print('Failed environment check. ' print('Failed environment check. '

View File

@ -18,7 +18,6 @@ import argparse
import logging import logging
import os import os
import fcntl import fcntl
import signal
import sys import sys
from subiquitycore.log import setup_logger from subiquitycore.log import setup_logger
@ -126,9 +125,6 @@ def main():
logging.getLogger('curtin').addHandler(handler) logging.getLogger('curtin').addHandler(handler)
logging.getLogger('block-discover').addHandler(handler) logging.getLogger('block-discover').addHandler(handler)
signal.signal(signal.SIGINT, signal.SIG_IGN)
signal.signal(signal.SIGQUIT, signal.SIG_IGN)
env_ok = environment_check(ENVIRONMENT) env_ok = environment_check(ENVIRONMENT)
if env_ok is False and not opts.dry_run: if env_ok is False and not opts.dry_run:
print('Failed environment check. ' print('Failed environment check. '

View File

@ -20,7 +20,6 @@ import logging
import os import os
import struct import struct
import sys import sys
import termios
import tty import tty
import urwid import urwid
@ -156,25 +155,13 @@ class KeyCodesFilter:
def enter_keycodes_mode(self): def enter_keycodes_mode(self):
log.debug("enter_keycodes_mode") log.debug("enter_keycodes_mode")
self.filtering = True self.filtering = True
# Read the old keyboard mode (it will proably always be # Read the old keyboard mode (it will proably always be K_UNICODE but
# K_UNICODE but well). # well).
o = bytearray(4) o = bytearray(4)
fcntl.ioctl(self._fd, KDGKBMODE, o) fcntl.ioctl(self._fd, KDGKBMODE, o)
self._old_mode = struct.unpack('i', o)[0] self._old_mode = struct.unpack('i', o)[0]
# Make some changes to the terminal settings. # Set the keyboard mode to K_MEDIUMRAW, which causes the keyboard
# If you don't do this, sometimes writes to the terminal hang (and no, # driver in the kernel to pass us keycodes.
# I don't know exactly why).
self._old_settings = termios.tcgetattr(self._fd)
new_settings = termios.tcgetattr(self._fd)
new_settings[tty.IFLAG] = 0
new_settings[tty.LFLAG] = new_settings[tty.LFLAG] & ~(termios.ECHO |
termios.ICANON |
termios.ISIG)
new_settings[tty.CC][termios.VMIN] = 0
new_settings[tty.CC][termios.VTIME] = 0
termios.tcsetattr(self._fd, termios.TCSAFLUSH, new_settings)
# Finally, set the keyboard mode to K_MEDIUMRAW, which causes
# the keyboard driver in the kernel to pass us keycodes.
log.debug("old mode was %s, setting mode to %s", log.debug("old mode was %s, setting mode to %s",
self._old_mode, K_MEDIUMRAW) self._old_mode, K_MEDIUMRAW)
fcntl.ioctl(self._fd, KDSKBMODE, K_MEDIUMRAW) fcntl.ioctl(self._fd, KDSKBMODE, K_MEDIUMRAW)
@ -184,7 +171,6 @@ class KeyCodesFilter:
self.filtering = False self.filtering = False
log.debug("setting mode back to %s", self._old_mode) log.debug("setting mode back to %s", self._old_mode)
fcntl.ioctl(self._fd, KDSKBMODE, self._old_mode) fcntl.ioctl(self._fd, KDSKBMODE, self._old_mode)
termios.tcsetattr(self._fd, termios.TCSANOW, self._old_settings)
def filter(self, keys, codes): def filter(self, keys, codes):
# Luckily urwid passes us the raw results from read() we can # Luckily urwid passes us the raw results from read() we can
@ -526,6 +512,8 @@ class Application:
except Skip: except Skip:
self.next_screen() self.next_screen()
self.common['loop'].set_alarm_in(
0.00, lambda loop, ud: tty.setraw(0))
self.common['loop'].set_alarm_in( self.common['loop'].set_alarm_in(
0.05, select_initial_screen, initial_controller_index) 0.05, select_initial_screen, initial_controller_index)
self._connect_base_signals() self._connect_base_signals()