Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to prevent more flickering #172

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/NOM/IO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ runUpdate output_builder_var state_var refresh_display_var updater input = do
modifyTVar' output_builder_var (log_output :)
modifyTVar' refresh_display_var (|| display_changed)

-- https://gitlab.com/gnachman/iterm2/-/wikis/synchronized-updates-spec
startAtomicUpdate, endAtomicUpdate :: Builder.Builder
startAtomicUpdate = "\x1b[?2026h"
endAtomicUpdate = "\x1b[?2026l"

writeStateToScreen ::
forall state.
Bool ->
Expand Down Expand Up @@ -126,7 +131,8 @@ writeStateToScreen pad printed_lines_var nom_state_var nix_output_buffer_var ref
output =
toStrict
. Builder.toLazyByteString
$
$ startAtomicUpdate
<>
-- when we clear the line, but don‘t use cursorUpLine, the cursor needs to be moved to the start for printing.
-- we do that before clearing because we can
memptyIfFalse (last_printed_line_count == 1) (Builder.stringUtf8 $ Terminal.setCursorColumnCode 0)
Expand Down Expand Up @@ -154,6 +160,7 @@ writeStateToScreen pad printed_lines_var nom_state_var nix_output_buffer_var ref
)
-- Corner case: If nom is not outputting anything but we are printing output from nix, then we want to append a newline
<> memptyIfFalse (nom_output_length == 0 && nix_output_length > 0) Builder.byteString "\n"
<> endAtomicUpdate

-- Actually write to the buffer. We do this all in one step and with a strict
-- ByteString so that everything is precalculated and the actual put is
Expand Down