mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-06 01:05:48 +02:00
Implement changing of default colors
This commit is contained in:
@@ -49,6 +49,7 @@ class Screen(QObject):
|
||||
title_changed = pyqtSignal(object)
|
||||
icon_changed = pyqtSignal(object)
|
||||
write_to_child = pyqtSignal(object)
|
||||
change_default_color = pyqtSignal(object, object)
|
||||
_notify_cursor_position = True
|
||||
|
||||
def __init__(self, opts, tracker, columns: int=80, lines: int=24, parent=None):
|
||||
@@ -983,14 +984,29 @@ class Screen(QObject):
|
||||
else: # DECLL
|
||||
pass
|
||||
|
||||
def set_cursor_color(self, color_name):
|
||||
def set_dynamic_color(self, base, color_names=None):
|
||||
# See http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Operating-System-Commands
|
||||
try:
|
||||
color_name = color_name.decode('utf-8') if color_name else None
|
||||
color_names = color_names.decode('utf-8') if color_names else ''
|
||||
except Exception:
|
||||
return
|
||||
old, self.cursor.color = self.cursor.color, color_name
|
||||
if old != self.cursor.color:
|
||||
self.cursor_changed(self.cursor)
|
||||
|
||||
def handle_val(val, param=None):
|
||||
val %= 100
|
||||
if val == 10: # foreground
|
||||
self.change_default_color.emit('fg', param)
|
||||
elif val == 11: # background
|
||||
self.change_default_color.emit('bg', param)
|
||||
elif val == 12: # cursor color
|
||||
old, self.cursor.color = self.cursor.color, param
|
||||
if old != self.cursor.color:
|
||||
self.cursor_changed(self.cursor)
|
||||
|
||||
if color_names:
|
||||
for i, cn in enumerate(filter(None, color_names.split(';'))):
|
||||
handle_val(base + i, cn)
|
||||
else:
|
||||
handle_val(base)
|
||||
|
||||
def normal_keypad_mode(self):
|
||||
pass # Useless for us, since Qt takes care of handling the numpad
|
||||
|
||||
@@ -62,7 +62,7 @@ class TerminalWidget(QWidget):
|
||||
self.tracker.dirtied.connect(self.update_screen)
|
||||
sclass = DebugStream if dump_commands else Stream
|
||||
self.screen = Screen(opts, self.tracker, parent=self)
|
||||
for s in 'write_to_child title_changed icon_changed'.split():
|
||||
for s in 'write_to_child title_changed icon_changed change_default_color'.split():
|
||||
getattr(self.screen, s).connect(getattr(self, s))
|
||||
self.stream = sclass(self.screen)
|
||||
self.feed = self.stream.feed
|
||||
@@ -87,8 +87,8 @@ class TerminalWidget(QWidget):
|
||||
pal.setColor(pal.Window, QColor(opts.background))
|
||||
pal.setColor(pal.WindowText, QColor(opts.foreground))
|
||||
self.setPalette(pal)
|
||||
self.default_bg = pal.color(pal.Window)
|
||||
self.default_fg = pal.color(pal.WindowText).getRgb()[:3]
|
||||
self.default_bg = self.original_bg = pal.color(pal.Window)
|
||||
self.default_fg = self.original_fg = pal.color(pal.WindowText).getRgb()[:3]
|
||||
build_ansi_color_tables(opts)
|
||||
self.current_font = f = QFont(opts.font_family)
|
||||
f.setPointSizeF(opts.font_size)
|
||||
@@ -102,6 +102,20 @@ class TerminalWidget(QWidget):
|
||||
c.setAlphaF(opts.cursor_opacity)
|
||||
self.do_layout()
|
||||
|
||||
def change_default_color(self, which, val):
|
||||
if which in ('fg', 'bg'):
|
||||
if not val:
|
||||
setattr(self, 'default_' + which, getattr(self, 'original_' + which))
|
||||
self.update()
|
||||
else:
|
||||
val = QColor(val)
|
||||
if val.isValid():
|
||||
if which == 'fg':
|
||||
self.default_fg = val.getRgb()[:3]
|
||||
else:
|
||||
self.default_bg = val
|
||||
self.update()
|
||||
|
||||
def do_layout(self):
|
||||
previous, self.cells_per_line = self.cells_per_line, self.width() // self.cell_width
|
||||
previousl, self.lines_per_screen = self.lines_per_screen, self.height() // self.cell_height
|
||||
|
||||
@@ -127,7 +127,7 @@ class Stream(object):
|
||||
events = frozenset(itertools.chain(
|
||||
basic.values(), escape.values(), sharp.values(), csi.values(),
|
||||
["define_charset", "select_other_charset"],
|
||||
["set_icon", "set_title", 'set_cursor_color'], # OSC.
|
||||
["set_icon", "set_title", 'set_dynamic_color'], # OSC.
|
||||
["draw", "debug"]))
|
||||
|
||||
#: A regular expression pattern matching everything what can be
|
||||
@@ -338,14 +338,21 @@ class Stream(object):
|
||||
param.extend(char)
|
||||
|
||||
param = bytes(param)
|
||||
if code in b"01":
|
||||
listener.set_icon_name(param)
|
||||
if code in b"02":
|
||||
try:
|
||||
code = int(code)
|
||||
except Exception:
|
||||
code = None
|
||||
if code == 0:
|
||||
listener.set_title(param)
|
||||
elif code == b"12":
|
||||
listener.set_cursor_color(param)
|
||||
elif code == b"112":
|
||||
listener.set_cursor_color(b'')
|
||||
listener.set_icon_name(param)
|
||||
elif code == 1:
|
||||
listener.set_icon_name(param)
|
||||
elif code == 2:
|
||||
listener.set_title(param)
|
||||
elif 9 < code < 20:
|
||||
listener.set_dynamic_color(code, param)
|
||||
elif 109 < code < 120:
|
||||
listener.set_dynamic_color(code)
|
||||
elif char == DCS:
|
||||
# See http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Device-Control-functions
|
||||
code = yield
|
||||
|
||||
Reference in New Issue
Block a user