Implement box drawing for Fira Code spinner glyphs

This commit is contained in:
Kovid Goyal 2024-03-10 21:08:23 +05:30
parent 36c79f3d50
commit 7d787e6c22
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
3 changed files with 36 additions and 2 deletions

View file

@ -92,6 +92,8 @@ Detailed list of changes
- Ignore :opt:`startup_session` when kitty is invoked with command line options specifying a command to run (:pull:`7198`)
- Box drawing: Specialize rendering for the Fira Code progress bar/spinner glyphs
0.32.2 [2024-02-12]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View file

@ -577,7 +577,7 @@ START_ALLOW_CASE_RANGE
case 0x2574 ... 0x259f:
case 0x2800 ... 0x28ff:
case 0xe0b0 ... 0xe0bf: // powerline box drawing
case 0xee00 ... 0xee05: // fira code progress bar
case 0xee00 ... 0xee0b: // fira code progress bar/spinner
case 0x1fb00 ... 0x1fbae: // symbols for legacy computing
return BOX_FONT;
default:
@ -613,7 +613,7 @@ START_ALLOW_CASE_RANGE
switch(ch) {
case 0x2500 ... 0x259f:
return ch - 0x2500; // IDs from 0x00 to 0x9f
case 0xe0b0 ... 0xee08:
case 0xe0b0 ... 0xee0b:
return 0xa0 + ch - 0xe0b0; // IDs from 0xa0 to 0xd58
case 0x2800 ... 0x28ff:
return 0xe00 + ch - 0x2800; // IDs from 0xe00 to 0xeff

View file

@ -443,6 +443,24 @@ def draw_parametrized_curve(
buf[pos] = min(255, buf[pos] + 255)
def circle_equations(
origin_x: int = 0, origin_y: int = 0, radius: float = 10., # radius is in pixels as are origin co-ords
start_at: float = 0., end_at: float = 360.
) -> Tuple[ParameterizedFunc, ParameterizedFunc]:
conv = math.pi / 180.
start = start_at * conv
end = end_at * conv
amt = end - start
def x(t: float) -> float:
return origin_x + radius * math.cos(start + amt * t)
def y(t: float) -> float:
return origin_y + radius * math.sin(start + amt * t)
return x, y
def rectircle_equations(
cell_width: int, cell_height: int, supersample_factor: int,
which: str = ''
@ -522,6 +540,14 @@ def rounded_separator(buf: SSByteArray, width: int, height: int, level: int = 1,
buf[offset + dest_x] = mbuf[offset + src_x]
@supersampled()
def spinner(buf: SSByteArray, width: int, height: int, level: int = 1, start: float = 0, end: float = 360) -> None:
w, h = width // 2, height // 2
radius = min(w, h) - int(thickness(level) * buf.supersample_factor) // 2
arc_x, arc_y = circle_equations(w, h, radius, start_at=start, end_at=end)
draw_parametrized_curve(buf, width, height, level, arc_x, arc_y)
def half_dhline(buf: BufType, width: int, height: int, level: int = 1, which: str = 'left', only: Optional[str] = None) -> Tuple[int, int]:
x1, x2 = (0, width // 2) if which == 'left' else (width // 2, width)
gap = thickness(level + 1, horizontal=False)
@ -928,6 +954,12 @@ box_chars: Dict[str, List[Callable[[BufType, int, int], Any]]] = {
'': [p(progress_bar, which='l', filled=True)],
'': [p(progress_bar, which='m', filled=True)],
'': [p(progress_bar, which='r', filled=True)],
'': [p(spinner, start=235, end=305)],
'': [p(spinner, start=270, end=390)],
'': [p(spinner, start=315, end=470)],
'': [p(spinner, start=360, end=540)],
'': [p(spinner, start=80, end=220)],
'': [p(spinner, start=170, end=270)],
'': [dhline],
'': [dvline],