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>_ACCESSIBLEvariable Click derives from the option itself. Its bare presence activates the mode, unless its value reads as false (seeparse_envvar_flag()). The flag and the<CLI>_ACCESSIBLEvariable outrank it: seeset_accessible(), which also says why a configuration file does not, and why it is read directly instead of being wired through the option’senvvar.
- 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:
ExtraOptionA pre-configured
--accessibleswitch.Turning it on (either via the flag or the
ACCESSIBLEenvironment variable) is equivalent to passing--no-color --no-progress --table-format plain, and additionally streamsecho_via_pager()output without a pager and turnsclear()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-accessiblecounterpart: to opt back out, pass the explicit--color/--table-formatyou 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
--colorand--table-formatoptions, through the context’sdefault_map. An explicit--color/--table-formaton the command line (or in a configuration file) therefore keeps precedence over--accessible.This option is eager so it lands its defaults before
--colorand--table-formatare 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 theChainMapthatConfigOptionlayers on top ofdefault_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
--accessiblewith theACCESSIBLEenvironment variable, stores the result atACCESSIBLEfor output helpers (clear(),echo_via_pager()) to read, then lowers the--color/--progress/--table-formatdefaults when active. A CLI that never sees--accessible(norACCESSIBLE) keeps every default untouched.ACCESSIBLEis a machine-wide variable, so the command line and the variable of the option outrank it, as they do for every machine-wide variable (seemachine_envvars_apply()). The precedence is:--accessible><CLI>_ACCESSIBLE>ACCESSIBLE> configuration file > built-in default.Important
ACCESSIBLEoutranks a configuration file, where the other machine-wide variables rank below one. The mode works by lowering the defaults of other options, andparse_args()settles it from the command line and the environment before the configuration file loads, so that--helpand--versionrender 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
ACCESSIBLEenvironment variable is read here rather than wired through the option’senvvar. Click would otherwise list it alongside the auto-generated<CLI>_ACCESSIBLEvariable in the--paramstable, making the combined string the widest cell of the env-var column and pushing every other row’s padding out. This mirrors howColorOptionreadsNO_COLORand friends.- Return type:
- 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:
- 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
--accessiblethe text is written straight to stdout viaclick.echo()instead. Outside accessibility mode (or with no active context) it defers toclick.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: