Skip to content

Commit

Permalink
chafa: Use 10x20 as the default cell size, in pixels
Browse files Browse the repository at this point in the history
This makes sixels print at the correct size in terminals with a fixed
virtual cell size, like Windows Terminal and legacy DEC terminals, if
this can not be detected at runtime.

Fixes #211 (GitHub).
  • Loading branch information
hpjansson committed Aug 21, 2024
1 parent e0f672c commit 7e5f5bd
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions tools/chafa/chafa.c
Original file line number Diff line number Diff line change
Expand Up @@ -2041,6 +2041,8 @@ parse_options (int *argc, char **argv [])
options.use_exact_size = TRISTATE_AUTO;
options.output_utf_16_on_windows = FALSE;
options.is_conhost_mode = FALSE;
options.cell_width = 10;
options.cell_height = 20;

if (!g_option_context_parse (context, argc, argv, &error))
{
Expand Down Expand Up @@ -2088,13 +2090,13 @@ parse_options (int *argc, char **argv [])
{
options.cell_width = detected_term_size.width_pixels / detected_term_size.width_cells;
options.cell_height = detected_term_size.height_pixels / detected_term_size.height_cells;
}

if (options.font_ratio <= 0.0
&& options.cell_width > 0
&& options.cell_height > 0)
{
options.font_ratio = (gdouble) options.cell_width / (gdouble) options.cell_height;
}
if (options.font_ratio <= 0.0
&& options.cell_width > 0
&& options.cell_height > 0)
{
options.font_ratio = (gdouble) options.cell_width / (gdouble) options.cell_height;
}

/* Assign detected or default dimensions if none specified */
Expand Down Expand Up @@ -2202,8 +2204,6 @@ parse_options (int *argc, char **argv [])
options.dither_grain_width = 4;
if (options.dither_grain_height < 0)
options.dither_grain_height = 4;
if (options.font_ratio <= 0.0)
options.font_ratio = 1.0 / 2.0;
if (options.scale <= 0.0)
options.scale = 4.0;
}
Expand All @@ -2217,8 +2217,6 @@ parse_options (int *argc, char **argv [])
options.dither_grain_width = 1;
if (options.dither_grain_height < 0)
options.dither_grain_height = 1;
if (options.font_ratio <= 0.0)
options.font_ratio = 1.0 / 2.0;
if (options.scale <= 0.0)
options.scale = 1.0;
}
Expand Down Expand Up @@ -2392,11 +2390,11 @@ pixel_to_cell_dimensions (gdouble scale,
/* Scale can't be zero or negative */
scale = MAX (scale, 0.00001);

/* Zero or negative cell dimensions -> presumably unknown, use 8x8 */
/* Zero or negative cell dimensions -> presumably unknown, use 10x20 */
if (cell_width < 1)
cell_width = 8;
cell_width = 10;
if (cell_height < 1)
cell_height = 8;
cell_height = 20;

extra_height = options.pixel_mode == CHAFA_PIXEL_MODE_SIXELS ? 5 : 0;

Expand Down

0 comments on commit 7e5f5bd

Please sign in to comment.