Skip to content

Commit

Permalink
Support synchronized update
Browse files Browse the repository at this point in the history
  • Loading branch information
EpicDima committed Apr 28, 2024
1 parent 0edc283 commit f8e1f1e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [Unreleased]

New:
- Support synchronized terminal update for rendering.
-

Changed:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.yield

private const val TerminalBeginSynchronizedUpdateControlSequence = "\u001B[?2026h"
private const val TerminalEndSynchronizedUpdateControlSequence = "\u001B[?2026l"

/**
* True for a debug-like output that renders each "frame" on its own with a timestamp delta.
* False when using ANSI control sequences to overwrite output.
Expand Down Expand Up @@ -74,7 +77,7 @@ public suspend fun runMosaic(body: suspend MosaicScope.() -> Unit): Unit = corou
var displaySignal: CompletableDeferred<Unit>? = null
val applier = MosaicNodeApplier(rootNode) {
val render = rendering.render(rootNode)
platformDisplay(render)
platformDisplay("$TerminalBeginSynchronizedUpdateControlSequence$render$TerminalEndSynchronizedUpdateControlSequence")

displaySignal?.complete(Unit)
hasFrameWaiters = false
Expand Down

0 comments on commit f8e1f1e

Please sign in to comment.