Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Sep 3, 2025

This PR implements the synchronized updates feature (DEC mode 2026) as requested in issue #203. Synchronized updates prevent screen flickering during complex terminal operations by deferring display updates until explicitly released.

Features

The implementation adds support for the following escape sequences:

  • ESC[?2026h - Enable synchronized updates mode
  • ESC[?2026l - Disable synchronized updates mode and flush deferred updates
  • ESC[?2026$p - Query synchronized updates mode state

How it works

When synchronized updates are enabled:

  1. All display update ranges are stored in deferred variables instead of active ones
  2. Frontend queries via getUpdateRange() return nil, preventing screen updates
  3. When synchronized updates are disabled, all deferred updates are flushed to active ranges in a single batch

This prevents the visual artifacts that can occur when applications perform multiple rapid screen updates, such as:

# Enable synchronized updates
printf '\e[?2026h'

# Perform multiple operations that would normally cause flicker
clear
echo "Line 1"
echo "Line 2" 
echo "Line 3"

# Disable synchronized updates - all changes appear at once
printf '\e[?2026l'

Implementation details

  • Added synchronizedUpdates: Bool property to track mode state
  • Enhanced escape sequence handlers for DEC mode 2026 in setMode() and resetMode()
  • Modified refresh logic with deferred update range variables
  • Implemented flushDeferredUpdates() to merge deferred ranges into active ranges
  • Updated getUpdateRange() and getScrollInvariantUpdateRange() to respect synchronized mode
  • Added proper reset behavior in terminal setup() method

The implementation follows the specification referenced in the issue comments and uses the DEC mode 2026 approach as recommended by the terminal working group.

Testing

Includes comprehensive tests covering:

  • Mode enable/disable functionality
  • Update deferral behavior
  • Proper flushing of deferred updates
  • Full screen update handling

Fixes #203


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@Copilot Copilot AI changed the title [WIP] Look at addressing issue #203 considering the comments linked there. Implement synchronized updates (DEC mode 2026) support Sep 3, 2025
@Copilot Copilot AI requested a review from migueldeicaza September 3, 2025 15:43
Copilot finished work on behalf of migueldeicaza September 3, 2025 15:43
@migueldeicaza
Copy link
Owner

This needs a timeout or it can be exploited, might also want to set a threshold to get out after some bytes processed, screen size multiplied by 4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Synchronized Updates

2 participants