Metadata-Version: 2.4
Name: jk_argparsing_textprimitive
Version: 0.2026.11.10
Summary: This module assist with providing a text model for processing command line arguments. See jk_argparsing for details.
Keywords: program,arguments,commands,options,args,argparsing
Author-email: Jürgen Knauth <pubsrc@binary-overflow.de>
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Classifier: Development Status :: 6 - Mature
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Environment :: Console
Classifier: License :: OSI Approved :: Apache Software License
License-File: LICENSE.txt
Project-URL: Home, https://github.com/jkpubsrc/python-module-jk-argparsing-textprimitive
Project-URL: Homepage, https://github.com/jkpubsrc/python-module-jk-argparsing-textprimitive

jk_argparsing_textprimitive
================================================================================================================================

Introduction
--------------------------------------------------------------------------------------------------------------------------------

This module `jk_argparsing_textprimitive` provides a small, composable data model for creating structured terminal output.

Its primary purpose is to support CLI tools that need to display information such as commands, arguments, options, descriptions, and other structured data in a readable, optionally colored format. By doing so it assists `jk_argparsing`.

Rather than constructing terminal output directly, applications build a hierarchy of text components. These components describe the content and its structure independently of the final output. A layout process then determines the dimensions and positioning of the individual components and produces lines of text ready for console output.

Information about this module can be found here:

* [github.org](https://github.com/jkpubsrc/python-module-jk-argparsing-textprimitive)
* [pypi.python.org](https://pypi.python.org/pypi/jk_argparsing_textprimitive)

How to use this module
--------------------------------------------------------------------------------------------------------------------------------

## Import

To import this module use the following statement:

```python
import jk_argparsing_textprimitive
```

Class Hierarchy
--------------------------------------------------------------------------------------------------------------------------------

The data model is based on two fundamental interfaces:

* `ITextBlock` – Base interface for all text components. Defines the common properties and operations required for measuring, laying out, and retrieving text.
* `ITextBlockContainer` (inheriting from `ITextBlock`) – Specialized interface for components that contain other text blocks. Provides access to their child components and allows hierarchical composition.

The concrete implementations are:

* `ITextBlock` - Base interface for all blocks.
	* `TextBlock` - Represents a paragraph or other continuous piece of text. Supports automatic word wrapping, indentation, list-item prefixes, and optional foreground/background coloring.
	* `TextEmpty` - Represents a sequence of empty lines. Useful for introducing vertical spacing between components.
	* `ITextBlockContainer` - Base interface for all block containers
		* `TextBlockSequence` - Combines multiple text blocks into a vertical sequence. Supports indentation and configurable vertical spacing between consecutive blocks.
		* `TextGridBlock` - Arranges text blocks in rows and columns. Supports configurable horizontal and vertical spacing, column width distribution, and individual column wrapping modes.
		* `TextPrefixBlock` - Wraps another text block and adds a prefix to each output line. Useful for introducing labels, markers, or other repeated line prefixes.

Layout and Output
--------------------------------------------------------------------------------------------------------------------------------

All components follow a common processing model:

1. **Build the data model:** Create primitive components and combine them into larger structures using container components.
2. **Perform layout:** Invoke layout(availableWidth) to determine the dimensions and line structure of the components. Containers recursively distribute available space to their children.
3. **Generate output:** Invoke getLines(bColor) to retrieve the resulting lines as XLineFragment instances.

The layout process considers indentation, minimum and maximum widths, wrapping behavior, and spacing requirements. If the available width is insufficient to accommodate the minimum required width, components may exceed the requested width rather than violating their minimum width requirements.

Output Representation
--------------------------------------------------------------------------------------------------------------------------------

**XLineFragment** represents a positioned fragment of a terminal output line. It stores the indentation, text content, and text length, allowing fragments produced by different components to be combined into complete output lines.

The resulting fragments can contain ANSI color escape sequences and are intended for direct console output.

The separation between the data model, layout process, and output representation allows applications to construct complex terminal presentations from a small set of reusable building blocks.

Author(s)
--------------------------------------------------------------------------------------------------------------------------------

* Jürgen Knauth: pubsrc@binary-overflow.de

License
--------------------------------------------------------------------------------------------------------------------------------

This software is provided under the following license:

* Apache Software License 2.0




