Skip to content

Commit

Permalink
DRYer
Browse files Browse the repository at this point in the history
  • Loading branch information
kovidgoyal committed Dec 28, 2024
1 parent c3dba00 commit c545ba3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
16 changes: 10 additions & 6 deletions kitty/line.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ typedef struct {
} GPUCell;
static_assert(sizeof(GPUCell) == 20, "Fix the ordering of GPUCell");

#define SCALE_BITS 3
#define WIDTH_BITS 3
#define SUBSCALE_BITS 4

typedef union CPUCell {
struct {
char_type ch_or_idx: sizeof(char_type) * 8 - 1;
Expand All @@ -52,12 +56,12 @@ typedef union CPUCell {
char_type next_char_was_wrapped : 1;
char_type is_multicell : 1;
char_type natural_width: 1;
char_type x : 8;
char_type y : 4;
char_type subscale_n: 4;
char_type subscale_d: 4;
char_type scale: 3;
char_type width: 3;
char_type x : WIDTH_BITS + SCALE_BITS + 1;
char_type y : SCALE_BITS + 1;
char_type subscale_n: SUBSCALE_BITS;
char_type subscale_d: SUBSCALE_BITS;
char_type scale: SCALE_BITS;
char_type width: WIDTH_BITS;
char_type vertical_align: 3;
char_type : 15;
};
Expand Down
5 changes: 3 additions & 2 deletions kitty/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -1209,8 +1209,9 @@ screen_handle_multicell_command(Screen *self, const MultiCellCommand *cmd, const
self->lc->count = decode_utf8_safe_string(payload, cmd->payload_sz, self->lc->chars);
if (!self->lc->count) return;
CPUCell mcd = {
.width=MIN(cmd->width, 15u), .scale=MAX(1u, MIN(cmd->scale, 15u)), .subscale_n=MIN(cmd->subscale_n, 15u),
.subscale_d=MIN(cmd->subscale_d, 15u), .vertical_align=MIN(cmd->vertical_align, 7u), .is_multicell=true
.width=MIN(cmd->width, (WIDTH_BITS << 1) - 1), .scale=MAX(1u, MIN(cmd->scale, (SCALE_BITS << 1) - 1)),
.subscale_n=MIN(cmd->subscale_n, (SUBSCALE_BITS << 1) - 1), .subscale_d=MIN(cmd->subscale_d, (SUBSCALE_BITS << 1) - 1),
.vertical_align=MIN(cmd->vertical_align, 7u), .is_multicell=true
};
if (mcd.width) handle_fixed_width_multicell_command(self, mcd, self->lc);
else {
Expand Down

0 comments on commit c545ba3

Please sign in to comment.