Skip to content

Commit

Permalink
Now I am hopefully done
Browse files Browse the repository at this point in the history
  • Loading branch information
oshaboy committed Nov 10, 2023
1 parent 183f6cd commit f1dcc84
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
31 changes: 16 additions & 15 deletions tools/chafa/chafa.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,16 +235,13 @@ write_to_stdout (gconstpointer buf, gsize len)

for (total_written = 0; total_written < len; )
{

gsize n_written = fwrite (((const gchar *) buf) + total_written, 1,
len - total_written, stdout);
total_written += n_written;
if (total_written < len && n_written == 0 && errno != EINTR)
result = FALSE;
}
}


#endif
return result;
}
Expand Down Expand Up @@ -883,7 +880,6 @@ parse_format_arg (G_GNUC_UNUSED const gchar *option_name, const gchar *value, G_
options.is_conhost_mode = TRUE;
#endif
pixel_mode = CHAFA_PIXEL_MODE_SYMBOLS;

}
else
{
Expand Down Expand Up @@ -1502,17 +1498,22 @@ tty_options_init (void)
DWORD bitmask = ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT;
if (!options.is_conhost_mode)
bitmask |= ENABLE_VIRTUAL_TERMINAL_PROCESSING | DISABLE_NEWLINE_AUTO_RETURN;
if (!SetConsoleMode (chd, bitmask) ){
if (!SetConsoleMode (chd, bitmask))
{
if (GetLastError() == ERROR_INVALID_HANDLE)
win32_stdout_is_file = TRUE;
else
/* Compatibility with older Windowses */
SetConsoleMode (chd,ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT);

}

}
}


/* Set UTF-8 code page output */
SetConsoleOutputCP (65001);

/* Set UTF-8 code page input, for good measure */
SetConsoleCP (65001);
}
#endif

Expand Down Expand Up @@ -1617,7 +1618,6 @@ detect_terminal (ChafaTermInfo **term_info_out, ChafaCanvasMode *mode_out,
pixel_mode = CHAFA_PIXEL_MODE_SIXELS;
else
pixel_mode = CHAFA_PIXEL_MODE_SYMBOLS;

if (chafa_term_info_have_seq (term_info, CHAFA_TERM_SEQ_BEGIN_SCREEN_PASSTHROUGH))
{
/* We can do passthrough for sixels and iterm too, but we won't do so
Expand Down Expand Up @@ -1866,9 +1866,9 @@ parse_options (int *argc, char **argv [])
options.file_duration_s = -1.0; /* Unset */
options.anim_fps = -1.0;
options.anim_speed_multiplier = 1.0;

options.output_utf_16_on_windows = FALSE;
options.is_conhost_mode = FALSE;

if (!g_option_context_parse (context, argc, argv, &error))
{
g_printerr ("%s: %s\n", options.executable_name, error->message);
Expand Down Expand Up @@ -2184,8 +2184,8 @@ parse_options (int *argc, char **argv [])
chafa_set_n_threads (options.n_threads);

#ifdef G_OS_WIN32
if (options.is_conhost_mode){

if (options.is_conhost_mode)
{
options.output_utf_16_on_windows = TRUE;
if (options.mode == CHAFA_CANVAS_MODE_INDEXED_240 ||
options.mode == CHAFA_CANVAS_MODE_INDEXED_256 ||
Expand Down Expand Up @@ -2449,13 +2449,12 @@ write_image (GString **gsa, gint dest_width)
}

static ChafaCanvasConfig *
build_config (
gint dest_width, gint dest_height,
build_config (gint dest_width, gint dest_height,
gboolean is_animation)
{
ChafaCanvasConfig *config;
config = chafa_canvas_config_new ();

config = chafa_canvas_config_new ();
chafa_canvas_config_set_geometry (config, dest_width, dest_height);
chafa_canvas_config_set_canvas_mode (config, options.mode);
chafa_canvas_config_set_pixel_mode (config, options.pixel_mode);
Expand Down Expand Up @@ -2489,6 +2488,7 @@ build_config (
chafa_canvas_config_set_optimizations (config, options.optimizations);
return config;
}

static ChafaCanvas *
build_canvas (ChafaPixelType pixel_type, const guint8 *pixels,
gint src_width, gint src_height, gint src_rowstride,
Expand Down Expand Up @@ -2850,6 +2850,7 @@ int
main (int argc, char *argv [])
{
int ret;

proc_init ();

if (!parse_options (&argc, &argv))
Expand Down
14 changes: 7 additions & 7 deletions tools/chafa/conhost.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
#include <chafa.h>
#include <windows.h>

typedef WORD attribute;
typedef struct {
gunichar2 * str;
attribute * attributes;
typedef WORD ConhostAttribute;
typedef struct {
gunichar2 *str;
ConhostAttribute *attributes;
size_t length;
size_t utf16_string_length;
} ConhostRow;
gboolean safe_WriteConsoleA (HANDLE chd, const gchar *data, gsize len);
gboolean safe_WriteConsoleW (HANDLE chd, const gunichar2 *data, gsize len);
gsize canvas_to_conhost (ChafaCanvas * canvas, ConhostRow ** lines);
void write_image_conhost (const ConhostRow * lines, gsize s);
void destroy_lines (ConhostRow * lines, gsize s);
gsize canvas_to_conhost (ChafaCanvas *canvas, ConhostRow **lines);
void write_image_conhost (const ConhostRow *lines, gsize s);
void destroy_lines (ConhostRow *lines, gsize s);

/* We must determine if stdout is redirected to a file, and if so, use a
* different set of I/O functions. */
Expand Down

0 comments on commit f1dcc84

Please sign in to comment.