Terminal Info

import chafa

db           = chafa.TermDb()
capabilities = db.detect_capabilities()

print("CanvasMode:", capabilities.canvas_mode)
print("PixelMode: ", capabilities.pixel_mode)

TermInfo

A TermInfo describes the characteristics of one particular kind of display terminal. It stores control sequences that can be used to move the cursor, change text attributes, mark the beginning and end of sixel graphics data, etc.

TermInfo also implements an efficient low-level API for formatting these sequences with marshaled arguments so they can be sent to the terminal.

class chafa.TermInfo
copy()

Returns a new TermInfo that is a copy of this one.

Return type:

TermInfo

supplement(source: TermInfo)

Supplements missing sequences in this TermInfo with ones copied from source.

Parameters:

source (TermInfo) – The TermInfo to copy sequences from.

have_seq(seq: TermSeq)

Checks if TermInfo can emit seq.

Parameters:

seq (TermSeq) – A TermSeq to query for.

Return type:

bool

emit(*args)

Returns the terminal sequences asked for as bytes.

Note

To “use” the sequence with print() you will first need to decode it with bytes.decode()

For an example, check out the Animating with control sequences example.

Parameters:

*args (TermSeq) – The sequences to emit

Return type:

bytes

Added in version 1.2.0.

detect_capabilities()

A method that tries to automatically detect the current terminal’s capabilities.

The priority for CanvasMode is

  1. CanvasMode.CHAFA_CANVAS_MODE_TRUECOLOR

  2. CanvasMode.CHAFA_CANVAS_MODE_INDEXED_240

  3. CanvasMode.CHAFA_CANVAS_MODE_INDEXED_16

  4. CanvasMode.CHAFA_CANVAS_MODE_FGBG_BGFG

  5. CanvasMode.CHAFA_CANVAS_MODE_FGBG

The priority for PixelMode is

  1. PixelMode.CHAFA_PIXEL_MODE_KITTY

  2. PixelMode.CHAFA_PIXEL_MODE_SIXELS

  3. PixelMode.CHAFA_PIXEL_MODE_SYMBOLS

You can use the results for CanvasConfig.canvas_mode and CanvasConfig.pixel_mode in your CanvasConfig.

Return type:

TerminalCapabilities

TerminalCapabilities

This class is just a simple dataclass representing the capabilities of a terminal. It is generated by TermInfo.detect_capabilities()

class TermInfo.TerminalCapabilities
canvas_mode
Type:

CanvasMode

pixel_mode
Type:

PixelMode

self == other

Returns True if both of

  1. other.canvas_mode == this.canvas_mode

  2. other.pixel_mode == this.pixel_mode

are True. Returns False otherwise.

Return type:

bool

Added in version 1.1.0.