Skip to content

Releases

v0.3.1

Choose a tag to compare

@kenshaw kenshaw released this 14 Nov 02:12

Builds with Go 1.25

rasterm now builds with Go 1.25. go.mod declares go 1.25.0, with golang.org/x/sys v0.47.0 and golang.org/x/term v0.45.0. These are the newest releases of those modules that build with Go 1.25.

The code and the API did not change. CI tests on Linux, macOS and Windows, on Go 1.25 and on the latest release. D30 in docs/PLAN.md records the change.

v0.3.0

Choose a tag to compare

@kenshaw kenshaw released this 14 Nov 00:17

New: KittyStream

A stream shows pictures of one size as one Kitty image, at the times that the program chooses. The terminal stores two frames however many pictures come, so a stream suits an animation of any length, such as video.

A Kitty animation from Animate stores every frame in the terminal, and kitty and Ghostty keep at most about 320 MB of images. A longer animation did not fit, and the frame that did not fit was lost without an error.

k, ok := term.Encoder().(rasterm.KittyEncoder)
if !ok {
	return rasterm.ErrTermGraphicsNotAvailable
}
s, err := k.Stream(os.Stdout, frames[0])
if err != nil {
	return err
}
for _, frame := range frames[1:] {
	// wait until the frame is due, then draw it
	if err := s.Draw(frame); err != nil {
		return err
	}
}
return s.Delete()

Stream sends the first picture and stops the animation of the image, so the terminal does not play it. Draw writes the next picture into the frame that is not shown, and then shows that frame, in one call to Write. Each picture must have the size of the first one, or Draw returns ErrFrameSize. PNGImage, RGBImage and RGBAImage are sent as they are, and tmux gets the passthrough and the placeholder cells, as with Encode.

The escape sequences are tested. The stream was not yet tested in a terminal.

v0.2.0

Choose a tag to compare

@kenshaw kenshaw released this 13 Nov 23:38

This release changes the API. A program that uses v0.1.23 must change, as shown below.

New: Detect asks the terminal

Detect replaces Available, Encode, DefaultEncoder and PendingInput. Call it once, when the program starts, and keep the Terminal that it returns:

term, pending, err := rasterm.Detect(ctx)
if err != nil {
	return err
}
enc := term.Encoder()
if enc == nil {
	return rasterm.ErrTermGraphicsNotAvailable
}
return enc.Encode(os.Stdout, img)

Detect finds the protocol in this order:

  1. TERM_GRAPHICS, if it names a protocol. Detect then asks the terminal nothing.
  2. In tmux, the answer of tmux about the terminal of its client.
  3. The answers of the terminal to its queries, sent in one write: the Kitty query, the Kitty feature query for animation, XTVERSION, the Sixel colors, the cell size and DA1. It waits up to 250 ms by default.
  4. The other variables of the environment, such as TERM and TERM_PROGRAM, only when the terminal cannot be asked or does not answer.

Detection by query works over SSH, where the variables of the terminal are often lost. The Terminal also holds the name and the version of the terminal, the cell size, each protocol that the terminal supports, and whether it reported Kitty animation.

pending holds the keys that the user typed while Detect waited. A program that reads standard input, such as a line editor, must use them as its first input.

The options are WithInput, WithOutput, WithTimeout and WithGetenv for Detect, and WithNoNewline and WithZlib for Terminal.Encoder.

New: Kitty animation

KittyEncoder.Animate streams the frames of a finite animation, such as a GIF. The terminal stores the frames under one image id, and plays them with the delay of each frame:

k, ok := term.Encoder().(rasterm.KittyEncoder)
if !ok {
	return rasterm.ErrTermGraphicsNotAvailable
}
anim, err := k.Animate(os.Stdout, frames[0], delays[0])
if err != nil {
	return err
}
for i := 1; i < len(frames); i++ {
	if _, err := anim.Frame(frames[i], rasterm.KittyFrame{Delay: delays[i]}); err != nil {
		return err
	}
}
return anim.End(0) // 0 loops forever

A frame can cover a part of the root frame, over a base frame or a background color. Stop holds the frame that shows, and Delete removes the image and its frames. kitty 0.20.0 and later and Ghostty 1.4.0 play animations. The escape sequences are tested, and the animation was not yet tested in a terminal.

Changed

  • Protocol replaces TermType. ParseProtocol reads a name as TERM_GRAPHICS does. The value Default is gone.
  • The encoders read no package state. KittyEncoder has Tmux and Cell, and ITermEncoder has Tmux. Terminal.Encoder sets them.
  • ErrUnknownProtocol replaces ErrUnknownTermType. ErrUnexpectedTermResponse is gone.
  • The test images are new, and testdata/README.md records the source, the license and the checksum of each one.

Moving from v0.1.23

v0.1.23 v0.2.0
rasterm.Available() term.Protocol != rasterm.None
rasterm.Kitty.Available() term.Protocol == rasterm.Kitty
rasterm.Encode(w, img) term.Encoder().Encode(w, img)
rasterm.PendingInput() the second value of Detect
rasterm.TermType rasterm.Protocol
NewDefaultEncoder(KittyEncoder{NoNewline: true}, ...) term.Encoder(rasterm.WithNoNewline())

v0.1.23

Choose a tag to compare

@kenshaw kenshaw released this 05 Nov 03:23

Fix: the query for Sixel lost the keys that the user typed before the reply

To find Sixel, the package asks the terminal for its device attributes, and waits up to 250 ms for the reply. A key that the user typed before the reply came was read and lost. In usql, select 1; written at once ran as elect 1;.

Now the package sets aside each byte that cannot be in the reply, and goes on waiting for the reply. An Escape or arrow key before the reply is set aside too, and the reply after it is still read.

New: PendingInput

rasterm.PendingInput() []byte returns the bytes that the package set aside, in order. Each byte is returned once. A program that reads standard input, such as a line editor, must call it after Available, and use the bytes as its first input:

ok := rasterm.Available()
pending := rasterm.PendingInput() // keys typed during the query

The query no longer returns ErrUnexpectedTermResponse. The constant stays.

rasterm v0.1.22

Choose a tag to compare

@kenshaw kenshaw released this 04 Nov 07:29

Fix: the query for Sixel lost the keys of the user

To find Sixel, the package asks the terminal for its device attributes. It read the reply from standard input with no deadline. A terminal that does not answer, such as Emacs, a serial console or some multiplexers, left the read waiting, and the package took the next key or paste of the user. In usql, \echo hello ran as echo hello.

Now the query works as follows:

  • The package waits for the reply for at most 250 ms. With no reply, there is no Sixel.
  • It reads one byte at a time, and stops at the end of the reply, so input after the reply reaches the program.
  • It no longer writes a cursor query, whose reply could reach the program as input.
  • It asks the terminal once in each process.
  • It does not ask when TERM is dumb, inside Emacs, or when standard input or output is not a terminal.

A key that is typed in the moment before the terminal replies is still lost, because a terminal does not take bytes back.

The new error ErrUnexpectedTermResponse is returned internally when the terminal writes a byte that cannot be in the reply.

rasterm v0.1.21

Choose a tag to compare

@kenshaw kenshaw released this 19 Oct 21:54

Images in tmux

Kitty and iTerm images now show in tmux. This fixes xo/usql#594.

  • Passthrough. In a tmux pane, Kitty and iTerm wrap each escape sequence in the DCS passthrough of tmux, so that tmux sends it to the terminal. Kitty wraps each chunk on its own, so a large image fits under the 1 MiB input limit of tmux. Sixel and half blocks are not wrapped: tmux draws Sixel itself, and half blocks are text.
  • Detection. In tmux, the package asks tmux once for the terminal of its client. It finds Kitty and Ghostty for Kitty graphics, and iTerm2 and WezTerm for iTerm images, with no TERM_GRAPHICS. TERM_GRAPHICS still selects a protocol.
  • Images keep their place. In tmux, Kitty draws each image with Unicode placeholder cells, which tmux keeps as text. Images no longer draw on top of each other, and tmux does not draw over them.

tmux sends the images only when passthrough is on. Add this to your tmux configuration:

set -g allow-passthrough on

When it is off, Kitty and iTerm are not available, and Encode returns ErrTermGraphicsNotAvailable in place of an empty screen.

Known issues

  • Ghostty 1.3.1 can close after a clear of the terminal in tmux, when it shows images with placeholder cells. This is a fault in Ghostty, related to ghostty-org/ghostty#5453.
  • tmux drops an iTerm image whose file is larger than about 786 KB, unless its input-buffer-size is raised.
  • iTerm images in tmux do not keep their rows.

rasterm v0.1.20

Choose a tag to compare

@kenshaw kenshaw released this 15 Oct 06:22

Fix: Ghostty closes on compressed raw pixels

In v0.1.19, Kitty's automatic zlib mode flushed the zlib stream at each check. Each flush adds small stored blocks to the stream, and Ghostty 1.3.1 closes when it reads such a stream. The same pixels in one stream with no flush display correctly.

ZlibAuto now never flushes. It still checks the compression after each 64 KiB, and a stream that is sent is the same as one zlib stream of all the pixels. The API does not change.

A flat image is now smaller, and a photo still goes raw:

Image (RGBA) v0.1.19 v0.1.20
orca.png 329 KiB, 5.00 ms 309 KiB, 4.74 ms
a flat 1024 x 1024 image 46 KiB, 1.46 ms 44 KiB, 1.46 ms
jpg1.jpg, a photo raw, 3.69 ms raw, 3.67 ms

Upgrade from v0.1.19 if you use Kitty graphics in Ghostty with RGBImage or RGBAImage.

rasterm v0.1.19

Choose a tag to compare

@kenshaw kenshaw released this 15 Oct 01:47

Kitty compresses raw pixels with zlib

Kitty now compresses the raw pixels of an RGBImage or an RGBAImage with zlib (o=z) when they compress well. A PNG is never compressed again.

KittyEncoder.Zlib sets the mode:

  • ZlibAuto, the default, sends pixels under 64 KiB raw. For more, it checks the compression after each 64 KiB, and sends the pixels raw at the first check where the output is not less than a quarter of the input.
  • ZlibAlways compresses pixels of any size.
  • ZlibNever sends the pixels raw.

With the default, a flat or rendered image sends few bytes, and a photo stays raw. The size is what the terminal reads, after base64:

Image (RGBA) Raw Automatic
a flat 1024 x 1024 image 5473 KiB, 1.66 ms 46 KiB, 1.46 ms
orca.png 6938 KiB, 2.12 ms 329 KiB, 5.00 ms
random noise, 1024 x 1024 5473 KiB, 1.68 ms 5473 KiB, 1.71 ms (raw)
jpg1.jpg, a photo 4378 KiB, 1.35 ms 4378 KiB, 3.69 ms (raw)

rasterm v0.1.18

Choose a tag to compare

@kenshaw kenshaw released this 14 Oct 21:58

Faster output

Each encoder builds its output in memory and writes it to the terminal in one call. Kitty made up to 398 calls for one image before.

Over the images in testdata/, Kitty takes 53% less time and makes 98% fewer allocations, and iTerm takes 26% less time. A JPEG sent with Kitty takes 25.7 ms, and took 62.9 ms. The README has the full results.

Send the bytes of an image as is

An image can carry the bytes that it already holds, and the encoder then sends them without encoding the image again:

Interface Method Encoders
PNGImage PNG() []byte Kitty, iTerm
JPEGImage JPEG() []byte iTerm
RGBImage RGB() []byte Kitty
RGBAImage RGBA() []byte Kitty

rasterm.DecodePNG and rasterm.DecodeJPEG decode a file and keep its bytes. A PNG or a JPEG sent as is takes 180 to 220 times less time than one encoded again.

Half blocks

HalfblockEncoder draws an image as text, with the ▀ character and 24-bit color. It does not scale the image. Set TERM_GRAPHICS=halfblock to use it.

TERM_GRAPHICS

TERM_GRAPHICS now selects one protocol and turns off each other protocol. Before, TERM_GRAPHICS=sixel in Kitty or Ghostty still drew with Kitty. Case, hyphens and a final s do not matter, so half-blocks selects half blocks.

Other changes

  • The module requires Go 1.26.
  • CI tests on Linux, macOS and Windows.

rasterm v0.1.10

Choose a tag to compare

@kenshaw kenshaw released this 01 Apr 19:21

A sustainable release.

⌂ 换网址