Skip to content

Commit

Permalink
Reverted API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
oshaboy committed Nov 5, 2023
1 parent 5c13560 commit ece03e5
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 30 deletions.
1 change: 0 additions & 1 deletion chafa/chafa-canvas-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ typedef enum
CHAFA_PIXEL_MODE_SIXELS,
CHAFA_PIXEL_MODE_KITTY,
CHAFA_PIXEL_MODE_ITERM2,
CHAFA_PIXEL_MODE_CONHOST,

CHAFA_PIXEL_MODE_MAX
}
Expand Down
4 changes: 2 additions & 2 deletions chafa/chafa-canvas.c
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,7 @@ draw_all_pixels (ChafaCanvas *canvas, ChafaPixelType src_pixel_type,

destroy_pixel_canvas (canvas);

if (canvas->config.pixel_mode == CHAFA_PIXEL_MODE_SYMBOLS || canvas->config.pixel_mode == CHAFA_PIXEL_MODE_CONHOST)
if (canvas->config.pixel_mode == CHAFA_PIXEL_MODE_SYMBOLS)
{
/* Symbol mode */

Expand Down Expand Up @@ -1386,7 +1386,7 @@ chafa_canvas_new (const ChafaCanvasConfig *config)

canvas->refs = 1;

if (canvas->config.pixel_mode == CHAFA_PIXEL_MODE_SYMBOLS || canvas->config.pixel_mode == CHAFA_PIXEL_MODE_CONHOST)
if (canvas->config.pixel_mode == CHAFA_PIXEL_MODE_SYMBOLS)
{
/* ANSI art */
canvas->width_pixels = canvas->config.width * CHAFA_SYMBOL_WIDTH_PIXELS;
Expand Down
30 changes: 15 additions & 15 deletions tools/chafa/chafa.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
# ifdef HAVE_WINDOWS_H
# include <windows.h>
# include <wchar.h>
# include "character_canvas_to_conhost.h"
# include "conhost.h"
# endif
# include <io.h>
#endif
Expand Down Expand Up @@ -137,7 +137,7 @@ typedef struct
ChafaTermInfo *term_info;

gboolean output_utf_16_on_windows;

gboolean is_conhost_mode;
}
GlobalOptions;

Expand Down Expand Up @@ -986,10 +986,10 @@ parse_format_arg (G_GNUC_UNUSED const gchar *option_name, const gchar *value, G_
else if (!strcasecmp (value, "conhost"))
{
#ifdef G_OS_WIN32
pixel_mode = CHAFA_PIXEL_MODE_CONHOST;
#else
options.is_conhost_mode=true;
#endif
pixel_mode = CHAFA_PIXEL_MODE_SYMBOLS;
#endif

}
else
{
Expand Down Expand Up @@ -1606,7 +1606,7 @@ tty_options_init (void)
if (chd != INVALID_HANDLE_VALUE)
{
DWORD bitmask = ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT;
if (options.pixel_mode != CHAFA_PIXEL_MODE_CONHOST)
if (!options.is_conhost_mode)
bitmask |= ENABLE_VIRTUAL_TERMINAL_PROCESSING | DISABLE_NEWLINE_AUTO_RETURN;
if (!SetConsoleMode (chd, bitmask) ){
if (GetLastError() == ERROR_INVALID_HANDLE)
Expand All @@ -1628,7 +1628,7 @@ tty_options_init (void)

if (win32_stdout_is_file &&
options.output_utf_16_on_windows &&
(options.pixel_mode == CHAFA_PIXEL_MODE_SYMBOLS || options.pixel_mode == CHAFA_PIXEL_MODE_CONHOST)
(options.pixel_mode == CHAFA_PIXEL_MODE_SYMBOLS)

) safe_WriteConsoleW (chd, u"\xfeff", 1);

Expand All @@ -1652,7 +1652,7 @@ tty_options_init (void)
}
#endif

if (options.mode != CHAFA_CANVAS_MODE_FGBG && options.pixel_mode != CHAFA_PIXEL_MODE_CONHOST)
if (options.mode != CHAFA_CANVAS_MODE_FGBG && !options.is_conhost_mode)
{
p0 = chafa_term_info_emit_disable_cursor (options.term_info, buf);
write_to_stdout (buf, p0 - buf);
Expand All @@ -1679,7 +1679,7 @@ tty_options_deinit (void)

if (!options.polite)
{
if (options.mode != CHAFA_CANVAS_MODE_FGBG && options.pixel_mode != CHAFA_PIXEL_MODE_CONHOST)
if (options.mode != CHAFA_CANVAS_MODE_FGBG && !options.is_conhost_mode)
{
gchar buf [CHAFA_TERM_SEQ_LENGTH_MAX];
gchar *p0;
Expand Down Expand Up @@ -1987,7 +1987,7 @@ parse_options (int *argc, char **argv [])
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 @@ -2137,8 +2137,7 @@ parse_options (int *argc, char **argv [])

/* Now we've established the pixel mode, apply dependent defaults */

if (options.pixel_mode == CHAFA_PIXEL_MODE_SYMBOLS ||
options.pixel_mode == CHAFA_PIXEL_MODE_CONHOST)
if (options.pixel_mode == CHAFA_PIXEL_MODE_SYMBOLS)
{
/* Character cell defaults */

Expand Down Expand Up @@ -2304,7 +2303,7 @@ parse_options (int *argc, char **argv [])
chafa_set_n_threads (options.n_threads);

#ifdef G_OS_WIN32
if (options.pixel_mode == CHAFA_PIXEL_MODE_CONHOST){
if (options.is_conhost_mode){

options.output_utf_16_on_windows = TRUE;
if (options.mode == CHAFA_CANVAS_MODE_INDEXED_240 ||
Expand All @@ -2316,6 +2315,7 @@ parse_options (int *argc, char **argv [])
#else
/*Force it to not output UTF16 when not Windows*/
options.output_utf_16_on_windows = FALSE;
options.is_conhost_mode = FALSE;
#endif

result = TRUE;
Expand Down Expand Up @@ -2851,8 +2851,8 @@ run_generic (const gchar *filename, gboolean is_first_file, gboolean is_first_fr
placement_id >= 0 ? placement_id + ((frame_count++) % 2) : -1);
*/
#ifdef G_OS_WIN32
if (options.pixel_mode == CHAFA_PIXEL_MODE_CONHOST){
CONHOST_LINE * lines;
if (options.is_conhost_mode){
ConhostRow * lines;
gsize s;
s=canvas_to_conhost(canvas, &lines);
write_image_conhost(lines, s);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "character_canvas_to_conhost.h"
#include "conhost.h"

static gsize unichar_to_utf16(gunichar c, gunichar2 * str){
if (c>=0x110000 ||
Expand All @@ -17,7 +17,7 @@ static gsize unichar_to_utf16(gunichar c, gunichar2 * str){


#define FOREGROUND_ALL FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE
gsize canvas_to_conhost(ChafaCanvas * canvas, CONHOST_LINE ** lines){
gsize canvas_to_conhost(ChafaCanvas * canvas, ConhostRow ** lines){
gint width, height;
ChafaCanvasConfig * config;
ChafaCanvasMode canvas_mode;
Expand All @@ -32,14 +32,14 @@ gsize canvas_to_conhost(ChafaCanvas * canvas, CONHOST_LINE ** lines){
canvas_mode == CHAFA_CANVAS_MODE_TRUECOLOR
) return (gsize) -1;
chafa_canvas_config_get_geometry(config, &width, &height);
(*lines)=g_malloc(height*sizeof(CONHOST_LINE));
(*lines)=g_malloc(height*sizeof(ConhostRow));
static const gchar color_lut[16] = {
0,4,2,6,1,5,3,7,
8,12,10,14,9,13,11,15
};
for (int y=0; y<height; y++){
CONHOST_LINE * const line = (*lines)+y;
*line=(CONHOST_LINE) {
ConhostRow * const line = (*lines)+y;
*line=(ConhostRow) {
.attributes=g_malloc(width*sizeof(attribute)),
.str=g_malloc(width*sizeof(gunichar2)*2),
.length=width,
Expand Down Expand Up @@ -74,7 +74,7 @@ gsize canvas_to_conhost(ChafaCanvas * canvas, CONHOST_LINE ** lines){
}
return height;
}
void write_image_conhost(const CONHOST_LINE * lines, gsize s){
void write_image_conhost(const ConhostRow * lines, gsize s){
HANDLE outh;
COORD curpos;
DWORD idc;
Expand All @@ -86,7 +86,7 @@ void write_image_conhost(const CONHOST_LINE * lines, gsize s){
}

for (gsize y=0 ;y<s ; y++){
const CONHOST_LINE line = lines[y];
const ConhostRow line = lines[y];
WriteConsoleOutputCharacterW(outh, line.str, line.utf16_string_length, curpos,&idc);
WriteConsoleOutputAttribute(outh, line.attributes, line.length, curpos, &idc);
/* WriteConsoleOutput family doesn't scroll the screen
Expand All @@ -97,7 +97,7 @@ void write_image_conhost(const CONHOST_LINE * lines, gsize s){
}
}

void destroy_lines(CONHOST_LINE * lines, gsize s){
void destroy_lines(ConhostRow * lines, gsize s){
for (gsize i=0; i<s; i++){
g_free(lines[i].attributes);
g_free(lines[i].str);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ typedef struct {
attribute * attributes;
size_t length;
size_t utf16_string_length;
} CONHOST_LINE;
} 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, CONHOST_LINE ** lines);
void write_image_conhost(const CONHOST_LINE * lines, gsize s);
void destroy_lines(CONHOST_LINE * 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);
#endif

0 comments on commit ece03e5

Please sign in to comment.