summaryrefslogtreecommitdiff
path: root/urwid/raw_display.py
diff options
context:
space:
mode:
Diffstat (limited to 'urwid/raw_display.py')
-rw-r--r--urwid/raw_display.py66
1 files changed, 46 insertions, 20 deletions
diff --git a/urwid/raw_display.py b/urwid/raw_display.py
index e5275bd..f07c50d 100644
--- a/urwid/raw_display.py
+++ b/urwid/raw_display.py
@@ -91,9 +91,17 @@ class Screen(BaseScreen, RealTerminal):
self._resize_pipe_rd, self._resize_pipe_wr = os.pipe()
fcntl.fcntl(self._resize_pipe_rd, fcntl.F_SETFL, os.O_NONBLOCK)
+ def _input_fileno(self):
+ """Returns the fileno of the input stream, or None if it doesn't have one. A stream without a fileno can't participate in whatever.
+ """
+ if hasattr(self._term_input_file, 'fileno'):
+ return self._term_input_file.fileno()
+ else:
+ return None
+
def _on_update_palette_entry(self, name, *attrspecs):
# copy the attribute to a dictionary containing the escape seqences
- a = attrspecs[{16:0,1:1,88:2,256:3}[self.colors]]
+ a = attrspecs[{16:0,1:1,88:2,256:3,2**24:3}[self.colors]]
self._pal_attrspec[name] = a
self._pal_escape[name] = self._attrspec_to_escape(a)
@@ -216,8 +224,8 @@ class Screen(BaseScreen, RealTerminal):
else:
self._rows_used = 0
- fd = self._term_input_file.fileno()
- if os.isatty(fd):
+ fd = self._input_fileno()
+ if fd is not None and os.isatty(fd):
self._old_termios_settings = termios.tcgetattr(fd)
tty.setcbreak(fd)
@@ -244,10 +252,9 @@ class Screen(BaseScreen, RealTerminal):
self.signal_restore()
- fd = self._term_input_file.fileno()
- if os.isatty(fd):
- termios.tcsetattr(fd, termios.TCSADRAIN,
- self._old_termios_settings)
+ fd = self._input_fileno()
+ if fd is not None and os.isatty(fd):
+ termios.tcsetattr(fd, termios.TCSADRAIN, self._old_termios_settings)
self._mouse_tracking(False)
@@ -367,11 +374,17 @@ class Screen(BaseScreen, RealTerminal):
polled in external event loops to check for user input.
Use this method if you are implementing your own event loop.
+
+ This method is only called by `hook_event_loop`, so if you override
+ that, you can safely ignore this.
"""
if not self._started:
return []
- fd_list = [self._term_input_file.fileno(), self._resize_pipe_rd]
+ fd_list = [self._resize_pipe_rd]
+ fd = self._input_fileno()
+ if fd is not None:
+ fd_list.append(fd)
if self.gpm_mev is not None:
fd_list.append(self.gpm_mev.stdout.fileno())
return fd_list
@@ -525,7 +538,10 @@ class Screen(BaseScreen, RealTerminal):
def _wait_for_input_ready(self, timeout):
ready = None
- fd_list = [self._term_input_file.fileno()]
+ fd_list = []
+ fd = self._input_fileno()
+ if fd is not None:
+ fd_list.append(fd)
if self.gpm_mev is not None:
fd_list.append(self.gpm_mev.stdout.fileno())
while True:
@@ -550,8 +566,9 @@ class Screen(BaseScreen, RealTerminal):
if self.gpm_mev is not None:
if self.gpm_mev.stdout.fileno() in ready:
self.gpm_event_pending = True
- if self._term_input_file.fileno() in ready:
- return ord(os.read(self._term_input_file.fileno(), 1))
+ fd = self._input_fileno()
+ if fd is not None and fd in ready:
+ return ord(os.read(fd, 1))
return -1
def _encode_gpm_event( self ):
@@ -648,9 +665,10 @@ class Screen(BaseScreen, RealTerminal):
"""Return the terminal dimensions (num columns, num rows)."""
y, x = 24, 80
try:
- buf = fcntl.ioctl(self._term_output_file.fileno(),
- termios.TIOCGWINSZ, ' '*4)
- y, x = struct.unpack('hh', buf)
+ if hasattr(self._term_output_file, 'fileno'):
+ buf = fcntl.ioctl(self._term_output_file.fileno(),
+ termios.TIOCGWINSZ, ' '*4)
+ y, x = struct.unpack('hh', buf)
except IOError:
# Term size could not be determined
pass
@@ -931,7 +949,9 @@ class Screen(BaseScreen, RealTerminal):
bg = escape.ESC + '[2;%d}' % (a.background_number,)
return fg + bg
- if a.foreground_high:
+ if a.foreground_true:
+ fg = "38;2;%d;%d;%d" %(a.get_rgb_values()[0:3])
+ elif a.foreground_high:
fg = "38;5;%d" % a.foreground_number
elif a.foreground_basic:
if a.foreground_number > 7:
@@ -946,7 +966,9 @@ class Screen(BaseScreen, RealTerminal):
st = ("1;" * a.bold + "3;" * a.italics +
"4;" * a.underline + "5;" * a.blink +
"7;" * a.standout + "9;" * a.strikethrough)
- if a.background_high:
+ if a.background_true:
+ bg = "48;2;%d;%d;%d" %(a.get_rgb_values()[3:6])
+ elif a.background_high:
bg = "48;5;%d" % a.background_number
elif a.background_basic:
if a.background_number > 7:
@@ -965,7 +987,7 @@ class Screen(BaseScreen, RealTerminal):
def set_terminal_properties(self, colors=None, bright_is_bold=None,
has_underline=None):
"""
- colors -- number of colors terminal supports (1, 16, 88 or 256)
+ colors -- number of colors terminal supports (1, 16, 88, 256, or 2**24)
or None to leave unchanged
bright_is_bold -- set to True if this terminal uses the bold
setting to create bright colors (numbers 8-15), set to False
@@ -1005,15 +1027,19 @@ class Screen(BaseScreen, RealTerminal):
"""
if self.colors == 1:
return
+ elif self.colors == 2**24:
+ colors = 256
+ else:
+ colors = self.colors
def rgb_values(n):
- if self.colors == 16:
+ if colors == 16:
aspec = AttrSpec("h%d"%n, "", 256)
else:
- aspec = AttrSpec("h%d"%n, "", self.colors)
+ aspec = AttrSpec("h%d"%n, "", colors)
return aspec.get_rgb_values()[:3]
- entries = [(n,) + rgb_values(n) for n in range(self.colors)]
+ entries = [(n,) + rgb_values(n) for n in range(min(colors, 256))]
self.modify_terminal_palette(entries)