Skip to content

Commit

Permalink
Implement box drawing for Fira Code spinner glyphs
Browse files Browse the repository at this point in the history
  • Loading branch information
kovidgoyal committed Mar 10, 2024
1 parent 36c79f3 commit 7d787e6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
4 changes: 2 additions & 2 deletions kitty/fonts.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions kitty/fonts/box_drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '╭'
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -928,6 +954,12 @@ def braille(buf: BufType, width: int, height: int, which: int = 0) -> None:
'': [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],

Expand Down

0 comments on commit 7d787e6

Please sign in to comment.