@@ -539,29 +539,10 @@ void TerminalUI::redraw(bool force)
539539 format_with (writer, " \033 [{};{}H" , (int )c.line + 1 , (int )c.column + 1 );
540540 };
541541
542- DisplayCoord target_pos;
543542 if (m_cursor.mode == CursorMode::Prompt)
544- target_pos = {m_status_on_top ? 0 : m_dimensions.line , m_cursor.coord .column };
543+ set_cursor_pos ( {m_status_on_top ? 0 : m_dimensions.line , m_cursor.coord .column }) ;
545544 else
546- target_pos = m_cursor.coord + content_line_offset ();
547-
548- if (m_terminal_cursor_native)
549- {
550- // Always position cursor in native mode to ensure it's correct after screen updates
551- set_cursor_pos (target_pos);
552-
553- // Only send show cursor command when cursor changes or on force refresh
554- if (m_cursor.mode != m_prev_cursor.mode || m_cursor.coord != m_prev_cursor.coord || force)
555- {
556- format_with (writer, " \033 [?25h" ); // ensure cursor is visible
557- m_prev_cursor = m_cursor;
558- }
559- }
560- else
561- {
562- // Always position cursor (original behavior)
563- set_cursor_pos (target_pos);
564- }
545+ set_cursor_pos (m_cursor.coord + content_line_offset ());
565546}
566547
567548void TerminalUI::set_cursor (CursorMode mode, DisplayCoord coord)
@@ -1504,17 +1485,13 @@ void TerminalUI::set_resize_pending()
15041485
15051486void TerminalUI::setup_terminal ()
15061487{
1507- const char * cursor_cmd = instance ().m_terminal_cursor_native ? " \033 [?25h" : " \033 [?25l" ;
1508-
15091488 write (STDOUT_FILENO,
15101489 " \033 [?1049h" // enable alternative screen buffer
15111490 " \033 [?1004h" // enable focus notify
15121491 " \033 [>4;1m" // request CSI u style key reporting
15131492 " \033 [>5u" // kitty progressive enhancement - report shifted key codes
15141493 " \033 [22t" // save the current window title
1515- );
1516- write (STDOUT_FILENO, cursor_cmd); // show or hide cursor based on mode
1517- write (STDOUT_FILENO,
1494+ " \033 [?25l" // hide cursor
15181495 " \033 =" // set application keypad mode, so the keypad keys send unique codes
15191496 " \033 [?2004h" // force enable bracketed-paste events
15201497 );
@@ -1524,13 +1501,7 @@ void TerminalUI::restore_terminal()
15241501{
15251502 write (STDOUT_FILENO,
15261503 " \033 >"
1527- );
1528-
1529- // Only restore cursor visibility if it was hidden (non-native mode)
1530- if (not instance ().m_terminal_cursor_native )
1531- write (STDOUT_FILENO, " \033 [?25h" );
1532-
1533- write (STDOUT_FILENO,
1504+ " \033 [?25h"
15341505 " \033 [23t"
15351506 " \033 [<u"
15361507 " \033 [>4;0m"
@@ -1604,7 +1575,14 @@ void TerminalUI::set_ui_options(const Options& options)
16041575
16051576 m_padding_char = find (" terminal_padding_char" ).map ([](StringView s) { return s.column_length () < 1 ? ' ' : s[0_char]; }).value_or (Codepoint{' ~' });
16061577 m_padding_fill = find (" terminal_padding_fill" ).map (to_bool).value_or (false );
1607- m_terminal_cursor_native = find (" terminal_cursor_native" ).map (to_bool).value_or (false );
1578+
1579+ bool new_cursor_native = find (" terminal_cursor_native" ).map (to_bool).value_or (false );
1580+ if (new_cursor_native != m_terminal_cursor_native)
1581+ {
1582+ m_terminal_cursor_native = new_cursor_native;
1583+ // Emit cursor visibility command when the option changes
1584+ write (STDOUT_FILENO, m_terminal_cursor_native ? " \033 [?25h" : " \033 [?25l" );
1585+ }
16081586
16091587 m_info_max_width = find (" terminal_info_max_width" ).map (str_to_int_ifp).value_or (0 );
16101588}
0 commit comments