euporie.core.terminal

Contain classes related to querying terminal features.

Functions

add_cmd(**kwargs)

Add a command to the centralized command system.

b64decode(s[, altchars, validate])

Decode the Base64 encoded bytes-like object or ASCII string s.

edit_in_editor(filename[, line_number])

Suspend the current app and edit a file in an external editor.

extend_enum(enumeration, name, *args, **kwds)

Add a new member to an existing Enum.

get_app()

Get the current active (running) Application.

lru_cache([maxsize, typed])

Least-recently-used cache decorator.

passthrough(cmd)

Wrap an escape sequence for terminal passthrough.

register_bindings(bindings)

Update the key-binding registry.

run_in_terminal(func[, render_cli_done, ...])

Run function on the terminal above the current application or prompt.

Classes

ClipboardData(input_, output, config)

A terminal query to retrieve clipboard contents.

ColorDepth(value[, names, module, qualname, ...])

Possible color depth values for the output.

Colors(input_, output, config)

A terminal query to retrieve colours as hex codes.

CsiUStatus(input_, output, config)

A terminal query to check for CSI-u support.

DepthOfColor(input_, output, config)

Determine the suspected color depth of the terminal.

Event(sender[, handler])

Simple event to which event handlers can be attached. For instance::.

ItermGraphicsStatus(input_, output, config)

A terminal query to check for iTerm graphics support.

KeyProcessor(key_bindings)

Statemachine that receives KeyPress instances and according to the key bindings in the given KeyBindings, calls the matching handlers.

Keys(value[, names, module, qualname, type, ...])

List of keys for use in key bindings.

KittyGraphicsStatus(input_, output, config)

A terminal query to check for kitty graphics support.

PixelDimensions(input_, output, config)

A terminal query to check the terminal's dimensions in pixels.

SgrPixelStatus(input_, output, config)

A terminal query to check for Pixel SGR support.

SixelGraphicsStatus(input_, output, config)

A terminal query to check for sixel graphics support.

TerminalInfo(input_, output, config)

A class to gather and hold information about the terminal.

TerminalQuery(input_, output, config)

A class representing a terminal query.

dt

alias of datetime

class euporie.core.terminal.ClipboardData(input_: Input, output: Output, config: Config)

Bases: TerminalQuery

A terminal query to retrieve clipboard contents.

await_response(timeout: float = 0.2) bool

Wait for a response from the terminal.

cache = False
cmd = '\x1b]52;c;?\x1b\\'
default: Any | None = ''
pattern: re.Pattern | None = re.compile('^\\x1b\\]52;(?:c|p)?;(?P<data>[A-Za-z0-9+/=]+)\\x1b\\\\\\Z')
run_at_startup: bool = False
send(flush: bool = True) None

Send the terminal query command to the output.

property value: Any

Return the last known value for the query.

Returns:

The last value received, or the default value.

verify(data: str) str

Verify the terminal responds.

class euporie.core.terminal.Colors(input_: Input, output: Output, config: Config)

Bases: TerminalQuery

A terminal query to retrieve colours as hex codes.

await_response(timeout: float = 0.2) bool

Wait for a response from the terminal.

cache = True
cmd = '\x1b]10;?\x1b\\\x1b]11;?\x1b\\\x1b]4;0;?\x1b\\\x1b]4;1;?\x1b\\\x1b]4;2;?\x1b\\\x1b]4;3;?\x1b\\\x1b]4;4;?\x1b\\\x1b]4;5;?\x1b\\\x1b]4;6;?\x1b\\\x1b]4;7;?\x1b\\\x1b]4;8;?\x1b\\\x1b]4;9;?\x1b\\\x1b]4;10;?\x1b\\\x1b]4;11;?\x1b\\\x1b]4;12;?\x1b\\\x1b]4;13;?\x1b\\\x1b]4;14;?\x1b\\\x1b]4;15;?\x1b\\'
default: Any | None = {'ansiblack': '#000000', 'ansiblue': '#0d73cc', 'ansibrightblack': '#767676', 'ansibrightblue': '#1a8fff', 'ansibrightcyan': '#14ffff', 'ansibrightgreen': '#23fd00', 'ansibrightmagenta': '#fd28ff', 'ansibrightpurple': '#fd28ff', 'ansibrightred': '#f2201f', 'ansibrightwhite': '#ffffff', 'ansibrightyellow': '#fffd00', 'ansicyan': '#0dcdcd', 'ansigray': '#767676', 'ansigreen': '#19cb00', 'ansimagenta': '#cb1ed1', 'ansipurple': '#9841bb', 'ansired': '#cc0403', 'ansiwhite': '#dddddd', 'ansiyellow': '#cecb00', 'bg': '#232627', 'fg': '#fcfcfc'}
pattern: re.Pattern | None = re.compile('^\\x1b\\](?P<c>(\\d+;)?\\d+)+;rgb:(?P<r>[0-9A-Fa-f]{2,4})\\/(?P<g>[0-9A-Fa-f]{2,4})\\/(?P<b>[0-9A-Fa-f]{2,4})(\\x1b\\\\\\Z|\\0x7)')
run_at_startup: bool = True
send(flush: bool = True) None

Send the terminal query command to the output.

property value: Any

Return the last known value for the query.

Returns:

The last value received, or the default value.

verify(data: str) dict[str, str]

Verify the response contains a colour.

class euporie.core.terminal.CsiUStatus(input_: Input, output: Output, config: Config)

Bases: TerminalQuery

A terminal query to check for CSI-u support.

await_response(timeout: float = 0.2) bool

Wait for a response from the terminal.

cache = True
cmd = '\x1b[?u'
default: Any | None = False
pattern: re.Pattern | None = re.compile('^\\x1b\\[\\?\\d+u')
run_at_startup: bool = True
send(flush: bool = True) None

Send the terminal query command to the output.

property value: Any

Return the last known value for the query.

Returns:

The last value received, or the default value.

verify(data: str) bool

Verify the terminal responds.

class euporie.core.terminal.DepthOfColor(input_: Input, output: Output, config: Config)

Bases: TerminalQuery

Determine the suspected color depth of the terminal.

await_response(timeout: float = 0.2) bool

Wait for a response from the terminal.

cache = False
cmd = ''
default: Any | None = 'DEPTH_24_BIT'
pattern: re.Pattern | None = None
run_at_startup: bool = True
send(flush: bool = True) None

Send the terminal query command to the output.

property value: Any

Return the last known value for the query.

Returns:

The last value received, or the default value.

verify(data: str) Any | None

Verify the response from the terminal.

class euporie.core.terminal.ItermGraphicsStatus(input_: Input, output: Output, config: Config)

Bases: TerminalQuery

A terminal query to check for iTerm graphics support.

await_response(timeout: float = 0.2) bool

Wait for a response from the terminal.

cache = True
cmd = '\x1b[>q'
default: Any | None = False
pattern: re.Pattern | None = re.compile('^\\x1bP>\\|(?P<term>[^\\x1b]+)\\x1b\\\\')
run_at_startup: bool = True
send(flush: bool = True) None

Send the terminal query command to the output.

property value: Any

Return the last known value for the query.

Returns:

The last value received, or the default value.

verify(data: str) bool

Verify iterm graphics are supported by the terminal.

class euporie.core.terminal.KittyGraphicsStatus(input_: Input, output: Output, config: Config)

Bases: TerminalQuery

A terminal query to check for kitty graphics support.

await_response(timeout: float = 0.2) bool

Wait for a response from the terminal.

cache = True
cmd = '\x1b_Gi=4294967295,s=1,v=1,a=q,t=d,f=24;AAAA\x1b\\'
default: Any | None = False
pattern: re.Pattern | None = re.compile('^\\x1b_Gi=(4294967295|0);(?P<status>OK)\\x1b\\\\\\Z')
run_at_startup: bool = True
send(flush: bool = True) None

Send the terminal query command to the output.

property value: Any

Return the last known value for the query.

Returns:

The last value received, or the default value.

verify(data: str) bool

Verify the terminal response means kitty graphics are supported.

class euporie.core.terminal.PixelDimensions(input_: Input, output: Output, config: Config)

Bases: TerminalQuery

A terminal query to check the terminal’s dimensions in pixels.

await_response(timeout: float = 0.2) bool

Wait for a response from the terminal.

cache = True
cmd = '\x1b[14t'
default: Any | None = (0, 0)
pattern: re.Pattern | None = re.compile('^\\x1b\\[4;(?P<y>\\d+);(?P<x>\\d+)t')
run_at_startup: bool = True
send(flush: bool = True) None

Send the terminal query command to the output.

property value: Any

Return the last known value for the query.

Returns:

The last value received, or the default value.

verify(data: str) tuple[int, int] | None

Verify the terminal responded with pixel dimensions.

class euporie.core.terminal.SgrPixelStatus(input_: Input, output: Output, config: Config)

Bases: TerminalQuery

A terminal query to check for Pixel SGR support.

await_response(timeout: float = 0.2) bool

Wait for a response from the terminal.

cache = True
cmd = '\x1b[?1016h\x1b[?1016$p\x1b[?1016l'
default: Any | None = False
pattern: re.Pattern | None = re.compile('^\\x1b\\[\\?1016;(?P<Pm>\\d)\\$\\Z')
run_at_startup: bool = True
send(flush: bool = True) None

Send the terminal query command to the output.

property value: Any

Return the last known value for the query.

Returns:

The last value received, or the default value.

verify(data: str) bool

Verify the terminal response means SGR pixel-mode is supported.

class euporie.core.terminal.SixelGraphicsStatus(input_: Input, output: Output, config: Config)

Bases: TerminalQuery

A terminal query to check for sixel graphics support.

await_response(timeout: float = 0.2) bool

Wait for a response from the terminal.

cache = True
cmd = '\x1b[c'
default: Any | None = False
pattern: re.Pattern | None = re.compile('^\\x1b\\[\\?(?:\\d+;)*(?P<sixel>4)(?:;\\d+)*c\\Z')
run_at_startup: bool = True
send(flush: bool = True) None

Send the terminal query command to the output.

property value: Any

Return the last known value for the query.

Returns:

The last value received, or the default value.

verify(data: str) bool

Verify the terminal response means sixel graphics are supported.

class euporie.core.terminal.TerminalInfo(input_: Input, output: Output, config: Config)

Bases: object

A class to gather and hold information about the terminal.

property cell_size_px: tuple[int, int]

Get the pixel size of a single terminal cell.

input: Input
output: Output
register(query: type[euporie.core.terminal.TerminalQuery]) TerminalQuery

Instantiate and registers a query’s response with the input parser.

send_all() None

Send the command for all queries.

property terminal_size_px: tuple[int, int]

Get the pixel dimensions of the terminal.

class euporie.core.terminal.TerminalQuery(input_: Input, output: Output, config: Config)

Bases: object

A class representing a terminal query.

This allows a control sequence to sent to the terminal, the response interpreted, and the received value processed and stored.

await_response(timeout: float = 0.2) bool

Wait for a response from the terminal.

cache = False
cmd = ''
default: Any | None = None
pattern: re.Pattern | None = None
run_at_startup: bool = True
send(flush: bool = True) None

Send the terminal query command to the output.

property value: Any

Return the last known value for the query.

Returns:

The last value received, or the default value.

verify(data: str) Any | None

Verify the response from the terminal.

euporie.core.terminal.edit_in_editor(filename: str, line_number: int = 0) None

Suspend the current app and edit a file in an external editor.

euporie.core.terminal.passthrough(cmd: str) str

Wrap an escape sequence for terminal passthrough.