Drafter.Widget.Chart.Pixel (drafter v0.3.1)

Copy Markdown View Source

Renders chart data as terminal graphics via the frozen french_curve library.

Two outputs from a single rasterisation path: a true-image escape sequence for terminals that support a pixel protocol (kitty / iTerm2 / sixel), or anti-aliased braille Strips for any other truecolor terminal. Callers pick the mode with mode/2 ("best available" for :pixel) and pass a chart spec to image/4 (a {paint, clear} pair — clear is a kitty delete for the persistent-layer protocol, empty for cell-grid protocols) or braille_strips/2.

A spec is %{type, values, color: {r,g,b,a}, smooth, fill_opacity, min, max}. Add a raster/3 clause to support a new chart type; supported/0 gates which types use this path at all.

Summary

Functions

The list of mode atoms accepted by :renderer, DRAFTER_MODE, and the mode: run option: [:auto, :pixel, :kitty, :iterm2, :sixel, :braille, :text].

The graphics protocol to draw with, or nil when the terminal has none.

Resolve an effective mode from precedence: the DRAFTER_MODE env var forces and wins over everything; otherwise an explicit per-widget renderer (any mode atom), then the runtime :drafter :render_mode application env, then :text.

Functions

braille_strips(spec, arg)

@spec braille_strips(
  map(),
  {pos_integer(), pos_integer()}
) :: [Drafter.Draw.Strip.t()] | nil

image(spec, protocol, arg, id)

@spec image(map(), atom(), {pos_integer(), pos_integer()}, term()) ::
  {iodata(), iodata()} | nil

mode(renderer, type)

@spec mode(atom() | nil, atom()) :: :pixel | :braille | :text

modes()

@spec modes() :: [atom()]

The list of mode atoms accepted by :renderer, DRAFTER_MODE, and the mode: run option: [:auto, :pixel, :kitty, :iterm2, :sixel, :braille, :text].

protocol(renderer)

@spec protocol(atom() | nil) :: atom() | nil

The graphics protocol to draw with, or nil when the terminal has none.

A renderer naming a protocol (:kitty, :iterm2, :sixel) is used as given; any mode that is not :auto or :pixel has no protocol and returns nil.

:auto and :pixel take what the terminal answered when it was probed at startup — see Drafter.Terminal.Probe. A terminal that was never probed is guessed at from its environment instead, through FrenchCurve.Capability.detect/1.

Either way the terminal in question is the one this session is attached to, which for a session served over ssh or telnet is the connecting client's rather than the host's.

resolve(renderer)

@spec resolve(atom() | nil) :: atom()

Resolve an effective mode from precedence: the DRAFTER_MODE env var forces and wins over everything; otherwise an explicit per-widget renderer (any mode atom), then the runtime :drafter :render_mode application env, then :text.

supported()

@spec supported() :: [atom()]