Merge branch 'dotted-dashed-underline' of https://github.com/jcla1/kitty

This commit is contained in:
Kovid Goyal 2022-01-18 21:03:30 +05:30
commit 17a3be8cb1
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
7 changed files with 33 additions and 16 deletions

View File

@ -13,8 +13,8 @@ To set the underline style::
<ESC>[4:1m # this is a straight underline <ESC>[4:1m # this is a straight underline
<ESC>[4:2m # this is a double underline <ESC>[4:2m # this is a double underline
<ESC>[4:3m # this is a curly underline <ESC>[4:3m # this is a curly underline
<ESC>[4:4m # this is a dotted underline (not implemented in kitty) <ESC>[4:4m # this is a dotted underline
<ESC>[4:5m # this is a dashed underline (not implemented in kitty) <ESC>[4:5m # this is a dashed underline
<ESC>[4m # this is a straight underline (for backwards compat) <ESC>[4m # this is a straight underline (for backwards compat)
<ESC>[24m # this is no underline (for backwards compat) <ESC>[24m # this is no underline (for backwards compat)

View File

@ -79,8 +79,8 @@ const uint COLOR_MASK = uint(0x4000);
const uint ZERO = uint(0); const uint ZERO = uint(0);
const uint ONE = uint(1); const uint ONE = uint(1);
const uint TWO = uint(2); const uint TWO = uint(2);
const uint THREE = uint(3);
const uint FOUR = uint(4); const uint FOUR = uint(4);
const uint SEVEN = uint(7);
vec3 color_to_vec(uint c) { vec3 color_to_vec(uint c) {
uint r, g, b; uint r, g, b;
@ -193,7 +193,7 @@ void main() {
foreground = choose_color(float(is_selected & ONE), selection_color, foreground); foreground = choose_color(float(is_selected & ONE), selection_color, foreground);
decoration_fg = choose_color(float(is_selected & ONE), selection_color, decoration_fg); decoration_fg = choose_color(float(is_selected & ONE), selection_color, decoration_fg);
// Underline and strike through (rendered via sprites) // Underline and strike through (rendered via sprites)
underline_pos = choose_color(in_url, to_sprite_pos(pos, url_style, ZERO, ZERO), to_sprite_pos(pos, (text_attrs >> DECORATION_SHIFT) & THREE, ZERO, ZERO)); underline_pos = choose_color(in_url, to_sprite_pos(pos, url_style, ZERO, ZERO), to_sprite_pos(pos, (text_attrs >> DECORATION_SHIFT) & SEVEN, ZERO, ZERO));
strike_pos = to_sprite_pos(pos, ((text_attrs >> STRIKE_SHIFT) & ONE) * FOUR, ZERO, ZERO); strike_pos = to_sprite_pos(pos, ((text_attrs >> STRIKE_SHIFT) & ONE) * FOUR, ZERO, ZERO);
// Cursor // Cursor

View File

@ -90,7 +90,7 @@ START_ALLOW_CASE_RANGE
case 3: case 3:
self->italic = true; break; self->italic = true; break;
case 4: case 4:
if (i < count) { self->decoration = MIN(3, params[i]); i++; } if (i < count) { self->decoration = MIN(5, params[i]); i++; }
else self->decoration = 1; else self->decoration = 1;
break; break;
case 7: case 7:
@ -161,7 +161,7 @@ apply_sgr_to_cells(GPUCell *first_cell, unsigned int cell_count, int *params, un
S(italic, true); S(italic, true);
case 4: { case 4: {
uint8_t val = 1; uint8_t val = 1;
if (i < count) { val = MIN(3, params[i]); i++; } if (i < count) { val = MIN(5, params[i]); i++; }
S(decoration, val); S(decoration, val);
} }
case 7: case 7:

View File

@ -142,7 +142,7 @@ typedef struct {
typedef union CellAttrs { typedef union CellAttrs {
struct { struct {
uint16_t width : 2; uint16_t width : 2;
uint16_t decoration : 2; uint16_t decoration : 3;
uint16_t bold : 1; uint16_t bold : 1;
uint16_t italic : 1; uint16_t italic : 1;
uint16_t reverse : 1; uint16_t reverse : 1;

View File

@ -17,7 +17,7 @@ from kitty.fast_data_types import (
test_render_line, test_shape test_render_line, test_shape
) )
from kitty.fonts.box_drawing import ( from kitty.fonts.box_drawing import (
BufType, render_box_char, render_missing_glyph BufType, distribute_dots, render_box_char, render_missing_glyph
) )
from kitty.options.types import Options, defaults from kitty.options.types import Options, defaults
from kitty.typing import CoreTextFont, FontConfigPattern from kitty.typing import CoreTextFont, FontConfigPattern
@ -279,6 +279,23 @@ def add_curl(buf: CBufType, cell_width: int, position: int, thickness: int, cell
add_intensity(x, y1 + t, 255) add_intensity(x, y1 + t, 255)
def add_dots(buf: CBufType, cell_width: int, position: int, thickness: int, cell_height: int) -> None:
spacing, size = distribute_dots(cell_width, cell_width // (2 * thickness))
y = 1 + position - thickness // 2
for i in range(y, min(y + thickness, cell_height)):
for j, s in enumerate(spacing):
buf[cell_width * i + j * size + s: cell_width * i + (j + 1) * size + s] = [255] * size
def add_dashes(buf: CBufType, cell_width: int, position: int, thickness: int, cell_height: int) -> None:
halfspace_width = cell_width // 4
y = 1 + position - thickness // 2
for i in range(y, min(y + thickness, cell_height)):
buf[cell_width * i:cell_width * i + (cell_width - 3 * halfspace_width)] = [255] * (cell_width - 3 * halfspace_width)
buf[cell_width * i + 3 * halfspace_width:cell_width * (i + 1)] = [255] * (cell_width - 3 * halfspace_width)
def render_special( def render_special(
underline: int = 0, underline: int = 0,
strikethrough: bool = False, strikethrough: bool = False,
@ -313,7 +330,7 @@ def render_special(
t = underline_thickness t = underline_thickness
if underline > 1: if underline > 1:
t = max(1, min(cell_height - underline_position - 1, t)) t = max(1, min(cell_height - underline_position - 1, t))
dl([add_line, add_line, add_dline, add_curl][underline], underline_position, t, cell_height) dl([add_line, add_line, add_dline, add_curl, add_dots, add_dashes][underline], underline_position, t, cell_height)
if strikethrough: if strikethrough:
dl(add_line, strikethrough_position, strikethrough_thickness, cell_height) dl(add_line, strikethrough_position, strikethrough_thickness, cell_height)
@ -384,7 +401,7 @@ def prerender_function(
render_cursor, cursor_beam_thickness=cursor_beam_thickness, render_cursor, cursor_beam_thickness=cursor_beam_thickness,
cursor_underline_thickness=cursor_underline_thickness, cell_width=cell_width, cursor_underline_thickness=cursor_underline_thickness, cell_width=cell_width,
cell_height=cell_height, dpi_x=dpi_x, dpi_y=dpi_y) cell_height=cell_height, dpi_x=dpi_x, dpi_y=dpi_y)
cells = f(1), f(2), f(3), f(0, True), f(missing=True), c(1), c(2), c(3) cells = f(1), f(2), f(3), f(4), f(5), f(0, strikethrough=True), f(missing=True), c(1), c(2), c(3)
return tuple(map(ctypes.addressof, cells)), cells return tuple(map(ctypes.addressof, cells)), cells

View File

@ -314,7 +314,7 @@ cell_update_uniform_block(ssize_t vao_idx, Screen *screen, int uniform_buffer, c
} }
rd->use_cell_for_selection_bg = IS_SPECIAL_COLOR(highlight_bg) ? 1. : 0.; rd->use_cell_for_selection_bg = IS_SPECIAL_COLOR(highlight_bg) ? 1. : 0.;
// Cursor position // Cursor position
enum { BLOCK_IDX = 0, BEAM_IDX = 6, UNDERLINE_IDX = 7, UNFOCUSED_IDX = 8 }; enum { BLOCK_IDX = 0, BEAM_IDX = 8, UNDERLINE_IDX = 9, UNFOCUSED_IDX = 10 };
if (cursor->is_visible) { if (cursor->is_visible) {
rd->cursor_x = screen->cursor->x, rd->cursor_y = screen->cursor->y; rd->cursor_x = screen->cursor->x, rd->cursor_y = screen->cursor->y;
if (cursor->is_focused) { if (cursor->is_focused) {

View File

@ -28,7 +28,7 @@ class Rendering(BaseTest):
self.test_ctx.__enter__() self.test_ctx.__enter__()
self.sprites, self.cell_width, self.cell_height = self.test_ctx.__enter__() self.sprites, self.cell_width, self.cell_height = self.test_ctx.__enter__()
try: try:
self.assertEqual([k[0] for k in self.sprites], [0, 1, 2, 3, 4, 5, 6, 7, 8]) self.assertEqual([k[0] for k in self.sprites], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
except Exception: except Exception:
self.test_ctx.__exit__() self.test_ctx.__exit__()
del self.test_ctx del self.test_ctx
@ -44,15 +44,15 @@ class Rendering(BaseTest):
sprite_map_set_limits(10, 2) sprite_map_set_limits(10, 2)
sprite_map_set_layout(5, 5) sprite_map_set_layout(5, 5)
self.ae(test_sprite_position_for(0), (0, 0, 0)) self.ae(test_sprite_position_for(0), (0, 0, 0))
self.ae(test_sprite_position_for(0), (0, 0, 0))
self.ae(test_sprite_position_for(1), (1, 0, 0)) self.ae(test_sprite_position_for(1), (1, 0, 0))
self.ae(test_sprite_position_for(2), (0, 1, 0)) self.ae(test_sprite_position_for(2), (0, 1, 0))
self.ae(test_sprite_position_for(3), (1, 1, 0)) self.ae(test_sprite_position_for(3), (1, 1, 0))
self.ae(test_sprite_position_for(4), (0, 0, 1)) self.ae(test_sprite_position_for(4), (0, 0, 1))
self.ae(test_sprite_position_for(5), (1, 0, 1)) self.ae(test_sprite_position_for(5), (1, 0, 1))
self.ae(test_sprite_position_for(0, 1), (0, 1, 1)) self.ae(test_sprite_position_for(6), (0, 1, 1))
self.ae(test_sprite_position_for(0, 2), (1, 1, 1)) self.ae(test_sprite_position_for(7), (1, 1, 1))
self.ae(test_sprite_position_for(0, 2), (1, 1, 1)) self.ae(test_sprite_position_for(0, 1), (0, 0, 2))
self.ae(test_sprite_position_for(0, 2), (1, 0, 2))
def test_box_drawing(self): def test_box_drawing(self):
prerendered = len(self.sprites) prerendered = len(self.sprites)