Utilities to assist with ASCII art such as railroad diagrams; since these use Unicode box drawing characters and are better for diagrams such as railroad diagrams, this is neither ASCII nor art.
Project description
Utilities to assist with ASCII art such as railroad diagrams; since these use Unicode box drawing characters and are better for diagrams such as railroad diagrams, this is neither ASCII nor art.
Latest release 20260403: Add LARGE_CIRCLE.
This is still pretty alpha.
The current demo mode runs:
rrprint(
RR_START,
RRRepeat("repeat me"),
"2 lines\naaaa",
(
"one",
"two",
"three",
"one\n"
"two\n"
"three\n"
"four\n"
"five",
["a", "sequence"],
),
RR_END,
)
which prints:
╭|one|──────────╮
├|two|──────────┤
├|three|────────┤
╭───────╮ │╭─────╮ │
│2 lines│ ││one │ │
├┼──┬|repeat me|┬──┤aaaa ├──┤│two │ ├──┼┤
╰─────←─────╯ ╰───────╯ ├┤three├────────┤
││four │ │
││five │ │
│╰─────╯ │
╰|a|──|sequence|╯
Short summary:
box_char: Return the Unicode entity for a box drawing glyph with the specified line weight and lines.box_char_name: Compute the Unicode entity name for a box drawing glyph with the specified line weight and lines.Cell: A representation of a character cell for a hypothetical future "drawing on a canvas" mode.render: A decorator to wrap rendering methods with the prevailing render context, as updated by any keyword arguments supplied to the method.render_mode: A context manager to temporarily applyrender_kwto the rendering mode contextctx(default fromRRBase.render_context). Yields the render context.RR_END: A bare text based symbol likeRR_STARTorRR_END.RR_START: A bare text based symbol likeRR_STARTorRR_END.RRBase: The abstract base class for various boxes.RRChoice: RRChoice(content: list[cs.ascii_art.RRBase] = ).RRMerge: RRMerge multiple inputs into a single output.RROptional: RROptional(content: cs.ascii_art.RRBase, above: bool = False, middle: str = '→').rrprint: Promote the arguments toRRBaseinstances, make into anRRSequenceand print it.RRRepeat: RRRepeat(content: cs.ascii_art.RRBase, above: bool = False, middle: str = '←').RRSequence: A railroad sequence.RRSplit: RRSplit a single input into multiple outputs.RRStack: An unadorned vertical stack of the content.RRTextBox: A text box with borders.Symbol: A bare text based symbol likeRR_STARTorRR_END.Terminal: Like a symbol, but with a marker either side.test_railroad: Exercise various boxes.
Module contents:
-
box_char_name(heavy=False, arc=False, up=False, down=False, left=False, right=False): Compute the Unicode entity name for a box drawing glyph with the specified line weight and lines.See: https://www.unicode.org/charts/nameslist/n_2500.html
Parameters:
arc: return an arc character instead of a rectangluar box cornerheavy: the line wieght:HEAVYforTrue,LIGHTforFalseup: with a line upward from the centredown: with a line downward from the centreleft: with a line leftward from the centreright: with a line rightward from the centre
-
class Cell: A representation of a character cell for a hypothetical future "drawing on a canvas" mode. -
render(*da, **dkw): A decorator to wrap rendering methods with the prevailing render context, as updated by any keyword arguments supplied to the method.The decorator may be suplied with its own defaults; these will be applied to the render context first, then whatever render keyword arguments as supplied to the method.
The decorated method accepts an optional
ctxparameter to use as the render context; the default comes fromself.render_contextwhich is normally an attribute ofself.__class__.The wrapped method is called with a keyword argument for every attribute of the updated render context. The render context is returned to its previous state on return from the method.
This means that the render methods have an unusual signature, for example:
@render(heavy=True) def renderlines(self, *, heavy, attach_w, attach_e, **_):This:
- enumerates only the keyword parameters of interest to the method
- "default" values should not be supplied as
Nonein the method definition - has a
_to collect any uninteresting render parameters
The interesting parameters should arrive prefilled and also do not need to be passed into interior calls to render methods because the render context has these values. Only values different from the render context need provision.
-
render_mode(ctx=None, **render_kw): A context manager to temporarily applyrender_kwto the rendering mode contextctx(default fromRRBase.render_context). Yields the render context. -
RR_END = Symbol:'┼┤': A bare text based symbol likeRR_STARTorRR_END. -
RR_START = Symbol:'├┼': A bare text based symbol likeRR_STARTorRR_END. -
class RRBase(cs.deco.Promotable): The abstract base class for various boxes.
RRBase.__str__(self):
Return the default rendering of the text box.
RRBase.conn_char(li, lefts: list[int], rights: list[int], arc=True, heavy=False) -> str:
Compute the connective box_char for a column of connective characters.
RRBase.from_str(s: str) -> Union[ForwardRef('Terminal'), ForwardRef('RRTextBox')]:
Promote a string to a Terminal or RRTextBox.
Nonempty strings with no newlines become Terminals,
otherwise a RRTextBox.
RRBase.horiz(width: int, *, middle='', arc, heavy, ascii=False, left_up=False, left_down=False, right_up=False, right_down=False, **_):
Compute a horizontal line with an optional symbol in the
middle and up or down connections.
RRBase.pprint(self, **ppkw):
Call pprint.pprint with this railroad node.
RRBase.render(self, **render_kw):
Render the text box as a single multiline string.
RRBase.render_lines(self, **render_kw):
Render the box as a list of single line strings.
class RRChoice(RRStack): RRChoice(content: list[cs.ascii_art.RRBase] = )class RRMerge(RRStack): RRMerge multiple inputs into a single output.
RRMerge.e:
The east attachment points of the RRMerge, the midpoint of
the interior top and bottom attachment points.
RRMerge.es:
The east attachment points of the RRMerge, the midpoint of
the interior top and bottom attachment points.
RRMerge.render_lines(self, *, arc, heavy, attach_e, **_):
Render the RRMerge as a list of strings.
RRMerge.width:
The width of the RRMerge, the width of the RRStack plus 1
for the right attachments.
class RROptional(_RailRoadAround): RROptional(content: cs.ascii_art.RRBase, above: bool = False, middle: str = '→')rrprint(*seq, sep=''): Promote the arguments toRRBaseinstances, make into anRRSequenceand print it.class RRRepeat(_RailRoadAround): RRRepeat(content: cs.ascii_art.RRBase, above: bool = False, middle: str = '←')class RRSequence(_RailRoadMulti): A railroad sequence.
RRSequence.height:
The render height ofthe RRSequence in lines.
RRSequence.render_lines(self, *, sep_len, middle='', **_):
Render the RRSequence as a list of one line strings.
RRSequence.width:
The render width of the RRSequence in characters..
RRSplit.render_lines(self, *, arc, heavy, attach_w, **_):
Render the RRSplit as a list of strings.
RRSplit.w:
The west attachment point, the midpoint of the top and
bottom interior west attachment points.
RRSplit.width:
The width of the RRSplit in characters.
RRSplit.ws:
The west attachment points of the RRSplit.
RRStack.width:
The overall width of the content.
RRTextBox.e:
The vertical offset to the east connection point.
RRTextBox.height:
The height including the borders
RRTextBox.n:
The horizontal offset to the north connection point.
RRTextBox.render_lines(self, *, heavy, attach_w, attach_e, **_):
Render the text box as a list of single line strings.
RRTextBox.s:
The horizontal offset to the south connection point.
RRTextBox.w:
The vertical offset to the west connection point.
RRTextBox.width:
The width including the borders
class Symbol(RRBase): A bare text based symbol likeRR_STARTorRR_END.class Terminal(Symbol): Like a symbol, but with a marker either side.test_railroad(): Exercise various boxes.
Release Log
Release 20260403: Add LARGE_CIRCLE.
Release 20260228: Initial release. Basic railroad diagrams and associated utilities.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cs_ascii_art-20260403.tar.gz.
File metadata
- Download URL: cs_ascii_art-20260403.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
756c92cd7aba94b8890ae9fc9e9ec76247da6bda672b604216bd97b20ffcae4b
|
|
| MD5 |
81449c3ebf5901f74e207c8fe75f63cb
|
|
| BLAKE2b-256 |
24145b2e30963afa1ea8f11a2977fd1e413ae4ef11d76f826aaefd364c5d0d2c
|
File details
Details for the file cs_ascii_art-20260403-py2.py3-none-any.whl.
File metadata
- Download URL: cs_ascii_art-20260403-py2.py3-none-any.whl
- Upload date:
- Size: 11.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c8a3e706f1d4fee9519e98d47a74a492273e21680c5bcb45cf6e977838a8bed
|
|
| MD5 |
b68e3c4d66b962d76e46bd71b8467444
|
|
| BLAKE2b-256 |
92c085ef32292e54d3eeebf63b4a6de03e95d1377afa5df8406e05d890a3586d
|