Skip to content

Commit 1c47902

Browse files
committed
ChafaTerm: Bail out of probe early if terminal doesn't support it
1 parent 6f4ff07 commit 1c47902

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

tools/chafa/chafa-term.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,7 @@ chafa_term_sync_probe (ChafaTerm *term, gint timeout_ms)
902902
struct termios saved_termios;
903903
gboolean termios_changed = FALSE;
904904
#endif
905+
gint printed_len = 0;
905906

906907
if (term->probe_success)
907908
return TRUE;
@@ -917,14 +918,21 @@ chafa_term_sync_probe (ChafaTerm *term, gint timeout_ms)
917918
ensure_raw_mode_enabled (term, &saved_termios, &termios_changed);
918919
#endif
919920

920-
chafa_term_print_seq (term, CHAFA_TERM_SEQ_QUERY_DEFAULT_FG, -1);
921-
chafa_term_print_seq (term, CHAFA_TERM_SEQ_QUERY_DEFAULT_BG, -1);
922-
chafa_term_print_seq (term, CHAFA_TERM_SEQ_QUERY_TEXT_AREA_SIZE_CELLS, -1);
923-
chafa_term_print_seq (term, CHAFA_TERM_SEQ_QUERY_TEXT_AREA_SIZE_PX, -1);
924-
chafa_term_print_seq (term, CHAFA_TERM_SEQ_QUERY_CELL_SIZE_PX, -1);
925-
chafa_term_print_seq (term, CHAFA_TERM_SEQ_QUERY_PRIMARY_DEVICE_ATTRIBUTES, -1);
921+
printed_len += chafa_term_print_seq (term, CHAFA_TERM_SEQ_QUERY_DEFAULT_FG, -1);
922+
printed_len += chafa_term_print_seq (term, CHAFA_TERM_SEQ_QUERY_DEFAULT_BG, -1);
923+
printed_len += chafa_term_print_seq (term, CHAFA_TERM_SEQ_QUERY_TEXT_AREA_SIZE_CELLS, -1);
924+
printed_len += chafa_term_print_seq (term, CHAFA_TERM_SEQ_QUERY_TEXT_AREA_SIZE_PX, -1);
925+
printed_len += chafa_term_print_seq (term, CHAFA_TERM_SEQ_QUERY_CELL_SIZE_PX, -1);
926+
printed_len += chafa_term_print_seq (term, CHAFA_TERM_SEQ_QUERY_PRIMARY_DEVICE_ATTRIBUTES, -1);
926927
term->probe_attempt = TRUE;
927928

929+
if (printed_len == 0)
930+
{
931+
/* Terminal doesn't support any of the probe sequences */
932+
term->probe_success = FALSE;
933+
return FALSE;
934+
}
935+
928936
while ((event = in_sync_pull (term, timeout_ms > 0 ? remain_ms : -1)))
929937
{
930938
g_queue_push_head (term->event_queue, event);

0 commit comments

Comments
 (0)