ArgUtils
Module: terminaltexteffects.utils.argutils
Command line argument validators and METAVARs for consistent type parsing and help output.
This module includes a custom formatter for argparse, which combines the features of
argparse.ArgumentDefaultsHelpFormatter and argparse.RawDescriptionHelpFormatter.
Classes:
| Name | Description |
|---|---|
CustomFormatter |
A custom formatter for argparse that combines the features of
|
CharacterGroup |
An enum specifying character groupings. |
CharacterGroupArg |
Argument type for character groupings. |
CharacterSort |
An enum specifying character sorts. |
CharacterSortArg |
Argument type for character sorts. |
CharacterOrder |
Unified spatial grouping and individual traversal options. |
CharacterOrderArg |
Argument type normalizing character orders and compatibility enums. |
CharacterGroupOrSortArg |
Argument type accepting character groups or sorts. |
ColorSort |
An enum specifying color sorts. |
ColorSortArg |
Argument type for color sorts. |
TupleAction |
Custom argparse action to convert a list of values into a tuple. |
ParserSpec |
Specification for a parser in the argument parser. |
ArgSpec |
Specification for a command-line argument and default value. |
GradientDirection |
Argument type for gradient directions. |
ColorArg |
Argument type for color values. |
Symbol |
Argument type for single ASCII/UTF-8 characters. |
Ease |
Argument type for easing functions. |
PositiveInt |
Argument type for positive integers. |
NonNegativeInt |
Argument type for nonnegative integers. |
PositiveIntRange |
Argument type for integer ranges. |
PositiveFloat |
Argument type for positive floats. |
NonNegativeFloat |
Argument type for nonnegative floats. |
PositiveFloatRange |
Argument type for float ranges. |
TerminalDimension |
Argument type for terminal dimensions. |
CanvasDimension |
Argument type for canvas dimensions. |
NonNegativeRatio |
Argument type for float values between zero and one. |
PositiveRatio |
Argument type for positive float values greater than zero and less than or equal to one. |
EasingStep |
Argument type for easing step size values. |
Constants
EASING_EPILOG (str): A detailed description of the easing functions supported.
ArgSpec
dataclass
Specification for a command-line argument and config default value.
Non-missing fields map directly to keyword arguments for
argparse.ArgumentParser.add_argument(). The default value is also used by
BaseConfig._build_config() when constructing configs without parsed CLI input.
The type callable is the normalization contract shared by CLI parsing and
library configuration. Custom callables must accept both CLI strings and
values that are already in their canonical library form.
default_formatter, when supplied, formats the canonical default for CLI
help text only. It does not affect parsing or configuration construction.
Source code in terminaltexteffects/utils/argutils.py
normalize(value)
Normalize and validate a configuration value described by this spec.
Explicit sequences for a TupleAction with nargs="+" must contain
at least one value. Scalar values remain valid for library callers.
Source code in terminaltexteffects/utils/argutils.py
CanvasDimension
Validate argument is a nonnegative integer or -1.
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
Value is not a valid canvas dimension. |
Source code in terminaltexteffects/utils/argutils.py
type_parser(arg)
staticmethod
Validate argument is a nonnegative integer or -1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
str
|
argument to validate |
required |
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
Value is not a valid canvas dimension. |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
validated canvas dimension |
Source code in terminaltexteffects/utils/argutils.py
CharacterGroup
Bases: Enum
Specify character groupings based on immutable input coordinates.
DIAMONDS_CENTER_TO_OUTSIDE and DIAMONDS_OUTSIDE_TO_CENTER use Manhattan distance from the
text's lower central cell. The CIRCLE_* options use one-column-wide radial
bands around the text's geometric midpoint, accounting for terminal cell height.
Retained for compatibility; use CharacterOrder for new ordering configurations.
Source code in terminaltexteffects/utils/argutils.py
CharacterGroupArg
Validate argument is a valid CharacterGroup.
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
Value is not a valid CharacterGroup. |
Source code in terminaltexteffects/utils/argutils.py
type_parser(arg)
staticmethod
Validate argument is a valid CharacterGroup.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
str
|
argument to validate |
required |
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
Value is not a valid CharacterGroup. |
Returns:
| Name | Type | Description |
|---|---|---|
CharacterGroup |
CharacterGroup
|
validated CharacterGroup |
Source code in terminaltexteffects/utils/argutils.py
CharacterGroupOrSortArg
Validate a CharacterGroup or CharacterSort ordering choice.
Source code in terminaltexteffects/utils/argutils.py
type_parser(arg)
staticmethod
Accept case-insensitive CLI names or canonical group/sort enum values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
str | CharacterGroup | CharacterSort
|
Ordering choice to normalize. |
required |
Returns:
| Type | Description |
|---|---|
CharacterGroup | CharacterSort
|
CharacterGroup | CharacterSort: The selected grouping or sorting enum. |
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
If |
Source code in terminaltexteffects/utils/argutils.py
CharacterOrder
Bases: Enum
Specify ordered spatial groups or individual character traversal.
Spatial options retain their original group boundaries and internal ordering. Individual traversal options, including spirals and random order, produce singleton groups. Flattening either form yields its complete character traversal.
Source code in terminaltexteffects/utils/argutils.py
is_grouped
property
Whether this order has spatial groups rather than singleton entries.
CharacterOrderArg
Normalize character orders, including legacy group and sort values.
Source code in terminaltexteffects/utils/argutils.py
type_parser(arg)
staticmethod
Accept CLI names, CharacterOrder, and compatibility enum values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
str | CharacterOrder | CharacterGroup | CharacterSort
|
Traversal choice. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
CharacterOrder |
CharacterOrder
|
The canonical character order. |
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
If the value is not a valid character order. |
Source code in terminaltexteffects/utils/argutils.py
CharacterSort
Bases: Enum
Specify character ordering based on immutable input coordinates.
The outside/middle options order complete rows by distance from the selected rows' vertical midpoint, retain left-to-right order within a row, and place the top row first when two rows are equally distant from the midpoint.
Spiral options wind inward through rectangular rings of the selected input
coordinates' bounding box. Single spirals start at top-left, double spirals
at top-left and bottom-right, and quad spirals at all four corners. Multiple
arms are interleaved by distance traveled around each ring.
Retained for compatibility; use CharacterOrder for new ordering configurations.
Source code in terminaltexteffects/utils/argutils.py
CharacterSortArg
Validate argument is a valid CharacterSort.
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
Value is not a valid CharacterSort. |
Source code in terminaltexteffects/utils/argutils.py
type_parser(arg)
staticmethod
Validate argument is a valid CharacterSort.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
str
|
argument to validate |
required |
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
Value is not a valid CharacterSort. |
Returns:
| Name | Type | Description |
|---|---|---|
CharacterSort |
CharacterSort
|
validated CharacterSort |
Source code in terminaltexteffects/utils/argutils.py
ColorArg
Validate argument is a valid color value.
Color values can be either an XTerm color value (0-255) or an RGB hex value (000000-ffffff).
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
Value is not in range of valid XTerm colors or RGB hex colors. |
Source code in terminaltexteffects/utils/argutils.py
type_parser(arg)
staticmethod
Validate argument is a valid color value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
str
|
argument to validate |
required |
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
Color value is not in range. |
Returns:
| Name | Type | Description |
|---|---|---|
Color |
Color
|
validated color value |
Source code in terminaltexteffects/utils/argutils.py
ColorSort
Bases: Enum
An enum for specifying color sorts for the colors derived from the input text ansi sequences.
Source code in terminaltexteffects/utils/argutils.py
ColorSortArg
Validate argument is a valid ColorSort.
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
Value is not a valid ColorSort. |
Source code in terminaltexteffects/utils/argutils.py
type_parser(arg)
staticmethod
Validate argument is a valid ColorSort.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
str
|
argument to validate |
required |
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
Value is not a valid ColorSort. |
Returns:
| Name | Type | Description |
|---|---|---|
ColorSort |
ColorSort
|
validated ColorSort |
Source code in terminaltexteffects/utils/argutils.py
CustomFormatter
Bases: ArgumentDefaultsHelpFormatter, RawDescriptionHelpFormatter
Combine ArgumentDefaultsHelpFormatter and RawDescriptionHelpFormatter for argparse.
Source code in terminaltexteffects/utils/argutils.py
Ease
Validate argument is a valid easing function.
Easing functions are prefixed by "in", "out", or "in_out" and suffixed by a valid easing function.
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
Value is not a valid easing function. |
Source code in terminaltexteffects/utils/argutils.py
1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 | |
type_parser(arg)
staticmethod
Validate argument is a valid easing function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
str
|
argument to validate |
required |
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
Ease value is not a valid easing function. |
Returns:
| Type | Description |
|---|---|
Callable
|
typing.Callable: The validated easing function. |
Source code in terminaltexteffects/utils/argutils.py
EasingStep
Validate argument is a valid easing step size value.
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
Value is not a valid easing step size. |
Source code in terminaltexteffects/utils/argutils.py
type_parser(arg)
staticmethod
Validate argument is a valid easing step size value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
str
|
argument to validate |
required |
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
Value is not a valid easing step size. |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
validated easing step size value |
Source code in terminaltexteffects/utils/argutils.py
GradientDirection
Validate argument is a valid gradient direction.
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
Argument value is not a valid gradient direction. |
Source code in terminaltexteffects/utils/argutils.py
type_parser(arg)
staticmethod
Validate argument is a valid gradient direction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
str
|
argument to validate |
required |
Returns:
| Type | Description |
|---|---|
Direction
|
Gradient.Direction: validated gradient direction |
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
Argument value is not a valid gradient direction. |
Source code in terminaltexteffects/utils/argutils.py
NonNegativeFloat
Validate argument is a nonnegative float. n >= 0.
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
Argument value is not in range. |
Source code in terminaltexteffects/utils/argutils.py
type_parser(arg)
staticmethod
Validate argument is a nonnegative float. n >= 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
str
|
argument to validate |
required |
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
Argument value is not in range. |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
validated value |
Source code in terminaltexteffects/utils/argutils.py
NonNegativeInt
Validate argument is a nonnegative integer. n >= 0.
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
Value is not in range. |
Source code in terminaltexteffects/utils/argutils.py
type_parser(arg)
staticmethod
Validate argument is a nonnegative integer. n >= 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
str
|
argument to validate |
required |
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
Value is not in range. |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
validated gap value |
Source code in terminaltexteffects/utils/argutils.py
NonNegativeRatio
Validate argument is a float value between zero and one.
0 <= float(n) <= 1
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
Value is not in range. |
Source code in terminaltexteffects/utils/argutils.py
type_parser(arg)
staticmethod
Validate argument is a float value between zero and one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
str
|
argument to validate |
required |
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
Value is not in range. |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
validated float value |
Source code in terminaltexteffects/utils/argutils.py
ParserSpec
dataclass
Specification for creating an argparse subparser for an effect config.
Each field maps directly to keyword arguments passed to
argparse._SubParsersAction.add_parser().
Source code in terminaltexteffects/utils/argutils.py
PositiveFloat
Validate argument is a positive float. n > 0.
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
Value is not in range. |
Source code in terminaltexteffects/utils/argutils.py
type_parser(arg)
staticmethod
Validate argument is a positive float. n > 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
str
|
argument to validate |
required |
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
value is not in range. |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
validated positive float |
Source code in terminaltexteffects/utils/argutils.py
PositiveFloatRange
Validate argument is a nondecreasing range of positive floats.
Float ranges are expressed as two floats separated by a hyphen, for example
0.1-1.0.
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
Value is not a valid float range. |
Source code in terminaltexteffects/utils/argutils.py
type_parser(arg)
staticmethod
Validate argument is a valid range of positive floats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
str
|
argument to validate |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
tuple[float,float]: validated range |
Source code in terminaltexteffects/utils/argutils.py
PositiveInt
Validate argument is a positive integer. n > 0.
int(n) > 0
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
Value is not a positive integer. |
Source code in terminaltexteffects/utils/argutils.py
type_parser(arg)
staticmethod
Validate argument is a positive integer. n > 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
str
|
argument to validate |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
validated positive integer |
Source code in terminaltexteffects/utils/argutils.py
PositiveIntRange
Validate argument is a nondecreasing range that starts with a positive integer.
Positive integer ranges are expressed as two integers separated by a hyphen,
for example 1-10.
Example
'1-10' is a valid input.
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
Value is not a valid positive integer range. |
Source code in terminaltexteffects/utils/argutils.py
type_parser(arg)
staticmethod
Validate argument is a valid range of integers n > 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
str
|
argument to validate |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, int]
|
tuple[int,int]: validated range |
Source code in terminaltexteffects/utils/argutils.py
PositiveRatio
Validate argument is a positive float.
0 < float(n) <= 1
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
Value is not in range. |
Source code in terminaltexteffects/utils/argutils.py
type_parser(arg)
staticmethod
Validate argument is a positive float.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
str
|
argument to validate |
required |
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
Value is not in range. |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
validated float value |
Source code in terminaltexteffects/utils/argutils.py
Symbol
Validate argument is a single printable character.
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
Value is not a valid symbol. |
Source code in terminaltexteffects/utils/argutils.py
type_parser(arg)
staticmethod
Validate argument is a single printable character.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
str
|
argument to validate |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
validated symbol |
Source code in terminaltexteffects/utils/argutils.py
TerminalDimension
Validate argument is a valid terminal dimension.
A Terminal Dimension is an integer >= 0.
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
Value is not a valid terminal dimension. |
Source code in terminaltexteffects/utils/argutils.py
type_parser(arg)
staticmethod
Validate argument is a valid terminal dimension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
str
|
argument to validate |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
validated terminal dimension |
Source code in terminaltexteffects/utils/argutils.py
TupleAction
Bases: Action
Convert parsed multi-value arguments into tuples.
Used for arguments that accept multiple values via nargs. If argparse provides
None, the destination is set to an empty tuple.
Source code in terminaltexteffects/utils/argutils.py
__call__(_, namespace, values, __=None)
Convert a list of values into a tuple.
Source code in terminaltexteffects/utils/argutils.py
format_cli_default(value, type_parser=_MISSING)
Format a canonical value using its equivalent command-line spelling.
This is the fallback used for argument defaults when an ArgSpec does not
provide a more specific default_formatter.
Source code in terminaltexteffects/utils/argutils.py
format_cli_range(value)
Format a two-value range using the hyphenated command-line syntax.
Example Usage
The RandomSequenceConfig.speed option uses ArgSpec with PositiveFloat.type_parser
to require a value greater than zero. This minimal config follows the same declaration
pattern and works with both direct construction and CLI parsing:
import argparse
from dataclasses import dataclass
from terminaltexteffects.engine.base_config import BaseConfig
from terminaltexteffects.utils import argutils
@dataclass
class SpeedConfig(BaseConfig):
parser_spec: argutils.ParserSpec = argutils.ParserSpec(
name="speed-example",
help="Show the speed option.",
description="Example speed configuration.",
epilog="",
)
speed: float = argutils.ArgSpec(
name="--speed",
type=argutils.PositiveFloat.type_parser,
default=0.007,
metavar=argutils.PositiveFloat.METAVAR,
help="Speed of the animation.",
) # pyright: ignore[reportAssignmentType]
assert SpeedConfig(speed="0.01").speed == 0.01
parser = argparse.ArgumentParser()
SpeedConfig._populate_parser(parser)
config = SpeedConfig._build_config(parser.parse_args(["--speed", "0.01"]))
assert config.speed == 0.01