Skip to content

Commit

Permalink
chafa: Use seqs instead of termios to turn echo off
Browse files Browse the repository at this point in the history
This avoids triggering a Ghostty heuristic for password entry
handling.

Issue reported by @edrozenberg (GitHub).
  • Loading branch information
hpjansson committed Dec 31, 2024
1 parent 87676ab commit 8aebfc8
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions tools/chafa/chafa.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
# include <signal.h> /* sigaction */
#endif
#include <stdlib.h> /* exit */
#ifdef HAVE_TERMIOS_H
# include <termios.h> /* tcgetattr, tcsetattr */
#endif

#include <glib/gstdio.h>

Expand Down Expand Up @@ -174,10 +171,6 @@ static volatile sig_atomic_t interrupted_by_user = FALSE;

static PlacementCounter *placement_counter;

#ifdef HAVE_TERMIOS_H
static struct termios saved_termios;
#endif

#ifdef G_OS_WIN32
static UINT saved_console_output_cp;
static UINT saved_console_input_cp;
Expand Down Expand Up @@ -1798,17 +1791,11 @@ tty_options_init (void)
gchar buf [CHAFA_TERM_SEQ_LENGTH_MAX * 2];
gchar *p0;

#ifdef HAVE_TERMIOS_H
if (options.is_interactive)
{
struct termios t;

tcgetattr (STDIN_FILENO, &saved_termios);
t = saved_termios;
t.c_lflag &= ~ECHO;
tcsetattr (STDIN_FILENO, TCSANOW, &t);
p0 = chafa_term_info_emit_disable_echo (options.term_info, buf);
write_to_stdout (buf, p0 - buf);
}
#endif

if (options.mode != CHAFA_CANVAS_MODE_FGBG && !options.is_conhost_mode)
{
Expand Down Expand Up @@ -1846,12 +1833,14 @@ tty_options_deinit (void)
write_to_stdout (buf, p0 - buf);
}

#ifdef HAVE_TERMIOS_H
if (options.is_interactive)
{
tcsetattr (STDIN_FILENO, TCSANOW, &saved_termios);
gchar buf [CHAFA_TERM_SEQ_LENGTH_MAX];
gchar *p0;

p0 = chafa_term_info_emit_enable_echo (options.term_info, buf);
write_to_stdout (buf, p0 - buf);
}
#endif
}
}

Expand Down

1 comment on commit 8aebfc8

@edrozenberg
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much for fixing this issue! I will definitely give it a try with the next Chafa release.

Please sign in to comment.