click_extra.accessibility module¶

        classDiagram
  ExtraOption <|-- AccessibleOption
    

Accessibility helpers switching CLI output to a screen-reader-friendly mode.

A screen reader consumes a terminal as a linear stream of characters. Several of the defaults that make output pleasant for sighted users actively harm that stream:

  • ANSI color codes, which carry no meaning once flattened to text;

  • tables drawn with Unicode box characters (│, â•­, ─, …), whose separators and whitespace-based column alignment are read out as noise;

  • animated progress spinners and bars, whose cursor-driven frames repeat endlessly to a reader that cannot watch them advance;

  • interactive takeovers like a pager or a screen-clear, which trap or wipe the linear stream the reader is following.

The AccessibleOption collapses these concerns into a single --accessible switch (also driven by the ACCESSIBLE environment variable), which is the same rationale that leads Click Extra to render help screens as minimal-width text rather than inside a terminal-wide table. It lowers the --color, --progress and --table-format defaults and publishes ACCESSIBLE, which clear() and echo_via_pager() read to drop their interactive behavior. See the --accessible section of docs/colorize.md for the full reasoning.

click_extra.accessibility.ACCESSIBLE_ENVVAR: Final[str] = 'ACCESSIBLE'¶

Environment variable that requests accessible mode.

Global and CLI-agnostic, unlike the <CLI>_ACCESSIBLE variable Click derives from the option itself. Its bare presence activates the mode, unless its value reads as false (see parse_envvar_flag()). The flag and the <CLI>_ACCESSIBLE variable outrank it: see set_accessible(), which also says why a configuration file does not, and why it is read directly instead of being wired through the option’s envvar.

class click_extra.accessibility.AccessibleOption(param_decls=None, *, is_flag=True, default=False, is_eager=True, expose_value=False, help='Accessibility mode: disable colors and render tables in a borderless, screen-reader-friendly format.', **kwargs)[source]¶

Bases: ExtraOption

A pre-configured --accessible switch.

Turning it on (either via the flag or the ACCESSIBLE environment variable) is equivalent to passing --no-color --no-progress --table-format plain, and additionally streams echo_via_pager() output without a pager and turns clear() into a no-op: it strips ANSI codes, silences progress spinners and bars, renders tables without box-drawing characters, and avoids interactive screen takeovers.

Note

It is a one-way flag with no --no-accessible counterpart: to opt back out, pass the explicit --color / --table-format you want, which take precedence anyway (see below). A negation flag would also be the widest option label in the help screen, pushing every other option’s description column to the right.

The switch only adjusts the defaults of the --color and --table-format options, through the context’s default_map. An explicit --color / --table-format on the command line (or in a configuration file) therefore keeps precedence over --accessible.

This option is eager so it lands its defaults before --color and --table-format are resolved.

Note

The values are injected with dict.setdefault(), so they never clobber a colorization or table format already requested by the user. Combined with the ChainMap that ConfigOption layers on top of default_map, this yields the precedence: command line > configuration file > --accessible > built-in defaults.

set_accessible(ctx, param, value)[source]¶

Publish the accessibility intent and lower color/progress/table defaults.

Reconciles --accessible with the ACCESSIBLE environment variable, stores the result at ACCESSIBLE for output helpers (clear(), echo_via_pager()) to read, then lowers the --color / --progress / --table-format defaults when active. A CLI that never sees --accessible (nor ACCESSIBLE) keeps every default untouched.

ACCESSIBLE is a machine-wide variable, so the command line and the variable of the option outrank it, as they do for every machine-wide variable (see machine_envvars_apply()). The precedence is: --accessible > <CLI>_ACCESSIBLE > ACCESSIBLE > configuration file > built-in default.

Important

ACCESSIBLE outranks a configuration file, where the other machine-wide variables rank below one. The mode works by lowering the defaults of other options, and parse_args() settles it from the command line and the environment before the configuration file loads, so that --help and --version render in accessible mode too. A file read later could not take those lowered defaults back: it would leave the colors off while the mode reads as off.

Note

The global ACCESSIBLE environment variable is read here rather than wired through the option’s envvar. Click would otherwise list it alongside the auto-generated <CLI>_ACCESSIBLE variable in the --params table, making the combined string the widest cell of the env-var column and pushing every other row’s padding out. This mirrors how ColorOption reads NO_COLOR and friends.

Return type:

None

click_extra.accessibility.clear()[source]¶

Drop-in for click.clear() that becomes a no-op under --accessible.

Clearing the screen wipes the scrollback a screen reader relies on and carries no meaning in a linear stream, so accessibility mode skips it entirely. Outside accessibility mode (or with no active context) it defers to click.clear(), which already no-ops when stdout is not a terminal.

Return type:

None

click_extra.accessibility.echo_via_pager(text_or_generator, color=None)[source]¶

Drop-in for click.echo_via_pager() that streams plainly under –accessible.

A pager is a full-screen, cursor-driven TUI: it traps output behind its own keybindings, hostile to a screen reader consuming a linear stream. Under --accessible the text is written straight to stdout via click.echo() instead. Outside accessibility mode (or with no active context) it defers to click.echo_via_pager(), which already falls back to a plain write when stdout is not a terminal.

The argument is normalized exactly as click.echo_via_pager() does (a generator function is called, a string is emitted as-is, anything else is iterated), so the two behave identically on their inputs.

Return type:

None