charmbracelet / vhs

Your CLI home video recorder 📼
MIT License
15.12k stars 254 forks source link

VHS fails to render background color changes on whitespace. #344

Closed joshka closed 1 year ago

joshka commented 1 year ago

Describe the bug I'm trying to capture demos for Ratatui (a rust tui crate) and I'm seeing some discrepancy between what the terminal sees, what ttyd sees and what vhs captures. Particularly this is visible with backgrounds. https://github.com/tui-rs-revival/ratatui/pull/303 is an issue that highlights some of the problem.

Setup Please complete the following information along with version numbers, if applicable.

To Reproduce Steps to reproduce the behavior (on a machine with rust installed)

  1. git clone https://github.com/joshka/ratatui.git --branch=docs-examples
  2. cd ratatui
  3. cargo run --example=gauge
  4. vhs examples/gauge.tape
  5. ttyd --interface 127.0.0.1 --port 11122 -t renderType=canvas -t disableResizeOverlay=true -t enableSixel=true -t customGlyphs=true --once zsh and then cargo run --example=gauge at http://localhost:11122

Source Code Please include source code if needed to reproduce the behavior.

 This is a vhs script. See https://github.com/charmbracelet/vhs for more info.
# To run this script, install vhs and run `vhs ./examples/gauge.tape`
Output "target/gauge.gif"
Set Width 1200
Set Height 600
Hide
Type "cargo run --example=gauge --features=crossterm"
Enter
Sleep 1s
Show
Sleep 20s

Expected behavior A clear and concise description of what you expected to happen.

Screenshots iterm view:

image

vhs gif: gauge

ttyd (in firefox):

image

Additional context Add any other context about the problem here. Our popup example has a similar issue (and several other examples did, but some changes have avoided the issue). popup It seems like something is not quite capturing the start / end of the set background commands correctly. I haven't done a minimal repro for this, but have at least narrowed the place the issue could be I hope.

hasezoey commented 1 year ago

easy VHS repro:

Output bleed.gif
Set Width 500
Set Height 500
Set Shell zsh
Set TypingSpeed 1ms
Type "printf 'Test \033[0;31mTest\033[0;60m Test\033[0m           '"
Sleep 2s
Enter

Type "printf 'Test \033[0;31mTest\033[0;103m Test\033[0m          '"
Sleep 2s
Enter

Sleep 2s

renders: bleed

but in Konsole (zsh) it renders as: Screenshot_20230812_170553

vhs currently seems to ignore \033[0m (ansi reset), if the next character is a whitespace, see: bleed

joshka commented 1 year ago

Installing the source version of ttyd which contains an updated xterm.js fixes the issue. On a mac: brew install ttyd --HEAD

bleed

This is a duplicate of #249 (and several other issues) but I'd suggest to leave this or some other issue open until ttyd is updated (I've made a request for a release in https://github.com/tsl0922/ttyd/issues/1201).

joshka commented 1 year ago

The upstream of ttyd is updated now - which should make it possible to use the release version rather than the head version.