mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-06 01:05:48 +02:00
More convenient API for getting QColors from attrs
This commit is contained in:
@@ -124,4 +124,13 @@ def build_ansi_color_tables(opts: Options) -> Tuple[dict, dict]:
|
||||
bg = {40 + i: getattr(opts, 'color{}'.format(i)) for i in range(8)}
|
||||
bg[49] = opts.background
|
||||
bg.update({100 + i: getattr(opts, 'color{}'.format(i + 8)) for i in range(8)})
|
||||
return fg, bg
|
||||
build_ansi_color_tables.fg, build_ansi_color_tables.bg = fg, bg
|
||||
build_ansi_color_tables(defaults)
|
||||
|
||||
|
||||
def fg_color_table():
|
||||
return build_ansi_color_tables.fg
|
||||
|
||||
|
||||
def bg_color_table():
|
||||
return build_ansi_color_tables.bg
|
||||
|
||||
@@ -8,6 +8,8 @@ from itertools import repeat
|
||||
|
||||
from PyQt5.QtGui import QColor
|
||||
|
||||
from .config import fg_color_table, bg_color_table
|
||||
|
||||
code = 'I' if array.array('I').itemsize >= 4 else 'L'
|
||||
lcode = 'L' if array.array('L').itemsize >= 8 else 'Q'
|
||||
|
||||
@@ -59,6 +61,9 @@ class Cursor:
|
||||
return self.__class__.__name__ + '({})'.format(', '.join(
|
||||
'{}={}'.format(x, getattr(self, x)) for x in self.__slots__))
|
||||
|
||||
def colors(self):
|
||||
return as_color(self.fg, fg_color_table()), as_color(self.bg, bg_color_table()), as_color(self.decoration_fg, fg_color_table())
|
||||
|
||||
CHAR_MASK = 0xFFFFFF
|
||||
ATTRS_SHIFT = 24
|
||||
ATTRS_MASK = 0xFF << ATTRS_SHIFT
|
||||
|
||||
@@ -9,7 +9,7 @@ from PyQt5.QtGui import QColor, QPainter, QFont, QFontMetrics, QRegion, QPen
|
||||
from PyQt5.QtWidgets import QWidget
|
||||
|
||||
from .config import build_ansi_color_tables, Options
|
||||
from .data_types import Line, as_color
|
||||
from .data_types import Line
|
||||
from .utils import set_current_font_metrics
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ class TerminalWidget(QWidget):
|
||||
self.setPalette(pal)
|
||||
self.current_bg = pal.color(pal.Window)
|
||||
self.current_fg = pal.color(pal.WindowText)
|
||||
self.ansi_fg, self.ansi_bg = build_ansi_color_tables(opts)
|
||||
build_ansi_color_tables(opts)
|
||||
f = QFont(opts.font_family)
|
||||
f.setPointSizeF(opts.font_size)
|
||||
self.setFont(f)
|
||||
@@ -104,10 +104,10 @@ class TerminalWidget(QWidget):
|
||||
|
||||
def paint_cell(self, painter: QPainter, line: Line, col: int, y: int) -> None:
|
||||
x = self.cell_positions[col]
|
||||
fg = as_color(line.fg[col], self.ansi_fg)
|
||||
c = line.cursor_from(x)
|
||||
fg, bg, decoration_fg = c.colors()
|
||||
if fg is not None:
|
||||
painter.setPen(QPen(fg))
|
||||
bg = as_color(line.bg[col], self.ansi_bg)
|
||||
if bg is not None:
|
||||
r = QRect(x, y, self.cell_width, self.cell_height)
|
||||
painter.fillRect(r, bg)
|
||||
|
||||
Reference in New Issue
Block a user