Skip to content

v0.1.0

Choose a tag to compare

@kenshaw kenshaw released this 04 Oct 03:43
· 5 commits to main since this release

This is the first release of termcast. The package streams the screen of a chromedp page to a terminal that has graphics, with the screencast of the Chrome DevTools Protocol and the package rasterm. It works in Kitty, iTerm2 and Sixel terminals.

var tc termcast.Flags
tc.Register(flag.CommandLine)
flag.Parse()
// ... create the chromedp context ...
s, err := tc.Start(ctx, *verbose)
if err != nil {
	log.Fatal(err)
}
defer s.Stop()
log.SetOutput(s.LogWriter())

What it does

  • Start draws the page at 4 frames per second by default. A WithFPS option or the flag -terminal-fps changes the rate.
  • Each redraw clears the terminal and draws the latest frame. The package uses no alternate screen and does not hide the cursor, so a program that ends with log.Fatal never leaves the terminal in a changed state.
  • The browser sends a frame only when the page changes. The stream keeps the latest frame, so a page that stops changing stays on the screen.
  • Start returns ErrNoGraphics when the terminal has no graphics. The message names the terminals that work and the variable TERM_GRAPHICS that forces a type.
  • Stream.LogWriter holds the log lines of the program while the stream runs, and prints them after a final frame when the stream stops. Every method of *Stream is safe on a nil pointer, so a program can call s.Stop() and s.Fatal(err) whether the stream is on or off.
  • Flags registers -visible-on-terminal and -terminal-fps, and Flags.Start returns ErrVerbose when the stream is on together with -v, because the protocol messages would draw over the frames.
  • The options WithQuality, WithMaxSize, WithOutput, WithLogOutput and WithEncoder change the JPEG quality, the frame size, the writers and the encoder.

Install

go get github.com/chromedp/termcast@v0.1.0

The package needs Go 1.27 or later and chromedp v0.19.0.