yapping-ansirithm 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
ansirithm/__init__.py ADDED
File without changes
ansirithm/ansirithm.py ADDED
@@ -0,0 +1,114 @@
1
+ from enum import Enum, IntEnum
2
+
3
+
4
+ class ForegroundColor(IntEnum):
5
+ BLACK = 30
6
+ RED = 31
7
+ GREEN = 32
8
+ YELLOW = 33
9
+ BLUE = 34
10
+ MAGENTA = 35
11
+ CYAN = 36
12
+ WHITE = 37
13
+
14
+
15
+ class BackgroundColor(IntEnum):
16
+ BLACK = 40
17
+ RED = 41
18
+ GREEN = 42
19
+ YELLOW = 43
20
+ BLUE = 44
21
+ MAGENTA = 45
22
+ CYAN = 46
23
+ WHITE = 47
24
+
25
+
26
+ class Fonts(IntEnum):
27
+ BOLD = 1
28
+ FAINT = 2
29
+ ITALIC = 3
30
+
31
+
32
+ class Decorators(IntEnum):
33
+ UNDERLINE = 4
34
+ DOUBLE_UNDERLINE = 21
35
+ STRIKE = 9
36
+ OVERLINE = 53
37
+
38
+
39
+ class Effects(IntEnum):
40
+ BLINK = 5
41
+ REVERSE = 7
42
+ HIDDEN = 8
43
+
44
+
45
+ class Reset(IntEnum):
46
+ RESET = 0
47
+
48
+
49
+ class CursorMovement(Enum):
50
+ UP = "A"
51
+ DOWN = "B"
52
+ RIGHT = "C"
53
+ LEFT = "D"
54
+
55
+
56
+ class CursorVisibility(Enum):
57
+ HIDE = "?25l"
58
+ SHOW = "?25h"
59
+
60
+
61
+ class LineNavigation(Enum):
62
+ NEXT = "E"
63
+ PREV = "F"
64
+
65
+
66
+ class Erasing(Enum):
67
+ SCREEN = "2J"
68
+ SCROLL = "3J"
69
+ LINE = "K"
70
+ TO_START = "1K"
71
+
72
+
73
+ class Teleportation(Enum):
74
+ HOME = "H"
75
+ SAVE = "s"
76
+ RESTORE = "u"
77
+
78
+
79
+ class Ansi:
80
+ @staticmethod
81
+ def ansi(*codes) -> str:
82
+ flattened = []
83
+
84
+ for code in codes:
85
+ if isinstance(code, (list, tuple)):
86
+ flattened.extend(code)
87
+ elif code is not None:
88
+ flattened.append(code)
89
+
90
+ if not flattened:
91
+ return ""
92
+
93
+ styling = [str(code) for code in flattened if isinstance(code ,int)]
94
+ action = [str(code) for code in flattened if isinstance(code, str)]
95
+
96
+ sequence = []
97
+
98
+ if styling:
99
+ sequence.append(f"\033[{";".join(styling)}m")
100
+
101
+ for code in action:
102
+ sequence.append(f"\033[{code}")
103
+
104
+ return "".join(sequence)
105
+
106
+ class _Reset:
107
+ def __enter__(self):
108
+ return Ansi.ansi
109
+
110
+ def __exit__(self, *_):
111
+ print(Ansi.ansi(Reset.RESET), end="")
112
+
113
+ reset = _Reset()
114
+ clear = "\033[2J\033[H"
@@ -0,0 +1,972 @@
1
+ Metadata-Version: 2.4
2
+ Name: yapping-ansirithm
3
+ Version: 0.1.0
4
+ Author-email: Patrick Ghetea <ghetea_patrick@outlook.com>
5
+ Classifier: Programming Language :: Python :: 3
6
+ Classifier: Programming Language :: Python :: 3.12
7
+ Classifier: Programming Language :: Python :: 3 :: Only
8
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
9
+ Requires-Python: >=3.12
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Dynamic: license-file
13
+
14
+ # Ansirithm
15
+
16
+ **A little color. A little cursor control. Much less escape-code archaeology.**
17
+
18
+ Ansirithm is a lightweight Python utility for terminal styling, cursor control, screen manipulation, and text decoration. You get readable enums and a small sequence builder, so your application can say what it means without scattering mysterious escape strings through the code.
19
+
20
+ If you'd rather write this:
21
+
22
+ ```python
23
+ Ansi.ansi(ForegroundColor.RED)
24
+ ```
25
+
26
+ than remember that red is `31`, you're in the right place. The terminal can keep its secret numerical language; you can keep your afternoon.
27
+
28
+ > **IMPORTANT**
29
+ > **Now on PyPI!** You no longer need to clone the repository, sacrifice a weekend, and manually summon the source code. Just install it:
30
+ >
31
+ > ```bash
32
+ > pip install yapping-ansirithm
33
+ > ```
34
+ >
35
+ > Then import it in Python using the module name, minus the `yapping-` prefix:
36
+ >
37
+ > ```python
38
+ > import ansirithm
39
+ > ```
40
+ >
41
+ > Remember: `yapping-ansirithm` is the package name; `ansirithm` is the import name. Two names, one project. Don't overthink it. Python already does enough of that.
42
+ >
43
+ > Happy hacking!
44
+
45
+ [What it does](#what-it-does) · [Get started](#get-started) · [A quick example](#a-quick-example) · [How it fits together](#how-it-fits-together) · [Reference](#reference) · [Examples](#examples) · [Good to know](#good-to-know) · [Design notes](#design-notes)
46
+
47
+ ## What it does
48
+
49
+ - Sets foreground colors with `ForegroundColor` and background colors with `BackgroundColor`.
50
+ - Applies bold, faint, and italic text through `Fonts`.
51
+ - Adds underlines, double underlines, strike-through, and overlines with `Decorators`.
52
+ - Builds blinking, reverse-video, and hidden-text effects through `Effects`.
53
+ - Moves the cursor, changes its visibility, and navigates between terminal lines.
54
+ - Erases the screen, scrollback, or part of a line.
55
+ - Sends the cursor home and saves or restores its position with `Teleportation`.
56
+ - Combines integer styling codes and string actions through `Ansi.ansi()`.
57
+ - Accepts reusable lists and tuples, ignores `None`, and returns an empty string for empty input.
58
+ - Resets text styling when a block ends through `Ansi.reset`, and supplies `Ansi.clear` for screen erasure followed by cursor home.
59
+
60
+ ## Get started
61
+
62
+ > **NOTE**
63
+ > Ansirithm uses only Python's standard library. It generates standard ANSI escape sequences; the receiving terminal is responsible for understanding and displaying them.
64
+
65
+ Import the classes you need from the module. Replace `ansirithm` with your installation's module path if it differs.
66
+
67
+ ```python
68
+ from ansirithm import (
69
+ Ansi,
70
+ ForegroundColor,
71
+ BackgroundColor,
72
+ Fonts,
73
+ Decorators,
74
+ Effects,
75
+ Reset,
76
+ CursorMovement,
77
+ CursorVisibility,
78
+ LineNavigation,
79
+ Erasing,
80
+ Teleportation,
81
+ )
82
+ ```
83
+
84
+ The main interface is:
85
+
86
+ ```python
87
+ Ansi.ansi(*codes)
88
+ ```
89
+
90
+ It accepts any number of style codes or action strings and returns a string. Write that string to terminal output to apply it; constructing the string alone does not change the terminal.
91
+
92
+ ## A quick example
93
+
94
+ ```python
95
+ print(
96
+ Ansi.ansi(ForegroundColor.RED)
97
+ + "Hello"
98
+ + Ansi.ansi(Reset.RESET)
99
+ )
100
+ ```
101
+
102
+ You get red `Hello` text followed by a style reset. That final reset keeps the next line from accidentally joining the red-text club.
103
+
104
+ You can apply more than one style in the same call:
105
+
106
+ ```python
107
+ Ansi.ansi(
108
+ ForegroundColor.RED,
109
+ Fonts.BOLD
110
+ )
111
+ ```
112
+
113
+ This combines the red foreground and bold font style into one styling sequence.
114
+
115
+ ## How it fits together
116
+
117
+ ### Styling codes and terminal actions
118
+
119
+ Ansirithm separates codes by the work they do:
120
+
121
+ | Kind | Input | What the builder emits |
122
+ | --- | --- | --- |
123
+ | Text styling | Integer SGR values: foreground colors, background colors, fonts, decorators, effects, and resets. | One combined SGR escape sequence. |
124
+ | Terminal actions | Strings for cursor movement, visibility, line navigation, erasing, and positioning. | A separate escape sequence for each action. |
125
+
126
+ SGR means Select Graphic Rendition: the ANSI mechanism for changing text attributes. The action commands use CSI, the Control Sequence Introducer used by these terminal operations.
127
+
128
+ When a call mixes styling and actions, the combined styling sequence comes first, followed by the action sequences in their string order. Integer styling values are joined with semicolons inside the single SGR sequence.
129
+
130
+ > **TIP**
131
+ > Pass styling enum members directly to `Ansi.ansi()`. For terminal actions, pass the member's **`.value`**, as in `Ansi.ansi(CursorVisibility.SHOW.value)`. Ansirithm adds the escape prefix, so the action string contains the part after `ESC[`.
132
+
133
+ ### Combine styles in one sequence
134
+
135
+ Pass several integer codes together when you want a reusable style:
136
+
137
+ ```python
138
+ style = Ansi.ansi(
139
+ ForegroundColor.YELLOW,
140
+ BackgroundColor.BLUE,
141
+ Fonts.BOLD,
142
+ Decorators.UNDERLINE
143
+ )
144
+
145
+ print(
146
+ style
147
+ + "Important message"
148
+ + Ansi.ansi(Reset.RESET)
149
+ )
150
+ ```
151
+
152
+ All four values become one SGR sequence, conceptually:
153
+
154
+ ```text
155
+ ESC[33;44;1;4m
156
+ ```
157
+
158
+ The text follows that sequence, and the explicit reset ends the styling. You get yellow, bold, underlined text on a blue background without assembling the raw control string yourself.
159
+
160
+ ### Reuse lists and tuples
161
+
162
+ `Ansi.ansi()` accepts lists and tuples as well as individual codes:
163
+
164
+ ```python
165
+ styles = [
166
+ ForegroundColor.CYAN,
167
+ Fonts.BOLD,
168
+ Decorators.UNDERLINE
169
+ ]
170
+
171
+ print(
172
+ Ansi.ansi(styles)
173
+ + "Styled text"
174
+ + Ansi.ansi(Reset.RESET)
175
+ )
176
+ ```
177
+
178
+ You can also combine a collection with individual arguments:
179
+
180
+ ```python
181
+ styles = [
182
+ ForegroundColor.GREEN,
183
+ Fonts.BOLD
184
+ ]
185
+
186
+ Ansi.ansi(
187
+ styles,
188
+ Decorators.UNDERLINE
189
+ )
190
+ ```
191
+
192
+ Lists and tuples are flattened **one level** before processing. That lets you keep a shared collection of theme values and add an extra decoration at the call site; it is not recursive flattening of arbitrarily deep collections.
193
+
194
+ ### Leave optional styles as `None`
195
+
196
+ When a style is conditional, you can pass `None` for the unused part:
197
+
198
+ ```python
199
+ color = ForegroundColor.RED
200
+ optional_style = None
201
+
202
+ sequence = Ansi.ansi(
203
+ color,
204
+ optional_style,
205
+ Fonts.BOLD
206
+ )
207
+ ```
208
+
209
+ The builder omits `optional_style` and keeps the red foreground and bold font. You don't need a separate formatting branch for every combination of optional attributes.
210
+
211
+ ### Let empty input stay empty
212
+
213
+ Calling the builder without usable codes returns an empty string:
214
+
215
+ ```python
216
+ Ansi.ansi()
217
+ ```
218
+
219
+ Result:
220
+
221
+ ```text
222
+ ""
223
+ ```
224
+
225
+ Empty collections and `None` behave the same way:
226
+
227
+ ```python
228
+ Ansi.ansi(None, [], ())
229
+ ```
230
+
231
+ This also produces `""`, so an empty style can safely participate in string concatenation without special handling.
232
+
233
+ ### Reset styling when a block ends
234
+
235
+ The reset helper is exposed through:
236
+
237
+ ```python
238
+ Ansi.reset
239
+ ```
240
+
241
+ Use the context manager with the callable form shown here:
242
+
243
+ ```python
244
+ with Ansi.reset():
245
+ print("Styled output")
246
+ ```
247
+
248
+ Its `__enter__()` method returns `Ansi.ansi`, so you can bind the sequence builder to a local name:
249
+
250
+ ```python
251
+ with Ansi.reset() as ansi:
252
+ print(
253
+ ansi(
254
+ ForegroundColor.RED,
255
+ Fonts.BOLD
256
+ )
257
+ + "Temporary style"
258
+ )
259
+ ```
260
+
261
+ When the context exits, it prints the reset sequence automatically:
262
+
263
+ ```text
264
+ ESC[0m
265
+ ```
266
+
267
+ That restores the default text styling after temporary formatting. The plain `"Styled output"` example shows the context-manager structure; the second example actually applies a style inside it.
268
+
269
+ > **IMPORTANT**
270
+ > A text reset restores **text attributes**. It does not show a hidden cursor or restore its position. Pair cursor hiding with `CursorVisibility.SHOW.value` when you're finished; a `finally` block is useful when the intervening work can raise an exception.
271
+
272
+ ### Clear the screen and go home
273
+
274
+ Use the predefined clear sequence:
275
+
276
+ ```python
277
+ Ansi.clear
278
+ ```
279
+
280
+ Conceptually, it contains these two commands:
281
+
282
+ ```text
283
+ ESC[2J ESC[H
284
+ ```
285
+
286
+ Write it without adding a newline:
287
+
288
+ ```python
289
+ print(Ansi.clear, end="")
290
+ ```
291
+
292
+ This first erases the screen and then moves the cursor to the home position. In Python string notation, the combined sequence is `"\x1b[2J\x1b[H"`.
293
+
294
+ ## Reference
295
+
296
+ ### Foreground colors
297
+
298
+ `ForegroundColor` supplies the eight standard ANSI foreground colors. Pass these enum members directly to the builder.
299
+
300
+ | Color | ANSI Code |
301
+ |---|---:|
302
+ | `BLACK` | `30` |
303
+ | `RED` | `31` |
304
+ | `GREEN` | `32` |
305
+ | `YELLOW` | `33` |
306
+ | `BLUE` | `34` |
307
+ | `MAGENTA` | `35` |
308
+ | `CYAN` | `36` |
309
+ | `WHITE` | `37` |
310
+
311
+ For a red message:
312
+
313
+ ```python
314
+ print(
315
+ Ansi.ansi(ForegroundColor.RED)
316
+ + "Red text"
317
+ + Ansi.ansi(Reset.RESET)
318
+ )
319
+ ```
320
+
321
+ For bold green text:
322
+
323
+ ```python
324
+ print(
325
+ Ansi.ansi(
326
+ ForegroundColor.GREEN,
327
+ Fonts.BOLD
328
+ )
329
+ + "Bold green text"
330
+ + Ansi.ansi(Reset.RESET)
331
+ )
332
+ ```
333
+
334
+ The foreground color stays active until another style sequence changes it or a reset clears it. Terminals appreciate a clear ending.
335
+
336
+ ### Background colors
337
+
338
+ `BackgroundColor` supplies the corresponding eight background colors:
339
+
340
+ | Color | ANSI Code |
341
+ |---|---:|
342
+ | `BLACK` | `40` |
343
+ | `RED` | `41` |
344
+ | `GREEN` | `42` |
345
+ | `YELLOW` | `43` |
346
+ | `BLUE` | `44` |
347
+ | `MAGENTA` | `45` |
348
+ | `CYAN` | `46` |
349
+ | `WHITE` | `47` |
350
+
351
+ Set a blue background:
352
+
353
+ ```python
354
+ print(
355
+ Ansi.ansi(BackgroundColor.BLUE)
356
+ + "Blue background"
357
+ + Ansi.ansi(Reset.RESET)
358
+ )
359
+ ```
360
+
361
+ Or combine it with a white foreground:
362
+
363
+ ```python
364
+ print(
365
+ Ansi.ansi(
366
+ ForegroundColor.WHITE,
367
+ BackgroundColor.BLUE
368
+ )
369
+ + "White on blue"
370
+ + Ansi.ansi(Reset.RESET)
371
+ )
372
+ ```
373
+
374
+ ### Fonts
375
+
376
+ `Fonts` supplies common text-style attributes:
377
+
378
+ | Style | ANSI Code |
379
+ |---|---:|
380
+ | `BOLD` | `1` |
381
+ | `FAINT` | `2` |
382
+ | `ITALIC` | `3` |
383
+
384
+ Apply bold text:
385
+
386
+ ```python
387
+ print(
388
+ Ansi.ansi(Fonts.BOLD)
389
+ + "Bold text"
390
+ + Ansi.ansi(Reset.RESET)
391
+ )
392
+ ```
393
+
394
+ Or request several font attributes together:
395
+
396
+ ```python
397
+ Ansi.ansi(
398
+ Fonts.BOLD,
399
+ Fonts.ITALIC
400
+ )
401
+ ```
402
+
403
+ > **NOTE**
404
+ > Individual styles depend on the terminal emulator. Faint and italic text, in particular, may look different or be unsupported. ANSI has a standard; terminals still bring their own opinions.
405
+
406
+ ### Text decorators
407
+
408
+ `Decorators` covers these text decorations:
409
+
410
+ | Decorator | ANSI Code |
411
+ |---|---:|
412
+ | `UNDERLINE` | `4` |
413
+ | `DOUBLE_UNDERLINE` | `21` |
414
+ | `STRIKE` | `9` |
415
+ | `OVERLINE` | `53` |
416
+
417
+ Underline a message:
418
+
419
+ ```python
420
+ print(
421
+ Ansi.ansi(Decorators.UNDERLINE)
422
+ + "Underlined text"
423
+ + Ansi.ansi(Reset.RESET)
424
+ )
425
+ ```
426
+
427
+ Or combine a decorator with a color and font style:
428
+
429
+ ```python
430
+ print(
431
+ Ansi.ansi(
432
+ ForegroundColor.CYAN,
433
+ Fonts.BOLD,
434
+ Decorators.UNDERLINE
435
+ )
436
+ + "Styled text"
437
+ + Ansi.ansi(Reset.RESET)
438
+ )
439
+ ```
440
+
441
+ ### Terminal effects
442
+
443
+ `Effects` supplies blinking, reverse video, and hidden text:
444
+
445
+ | Effect | ANSI Code |
446
+ |---|---:|
447
+ | `BLINK` | `5` |
448
+ | `REVERSE` | `7` |
449
+ | `HIDDEN` | `8` |
450
+
451
+ For reverse video:
452
+
453
+ ```python
454
+ print(
455
+ Ansi.ansi(Effects.REVERSE)
456
+ + "Reverse video"
457
+ + Ansi.ansi(Reset.RESET)
458
+ )
459
+ ```
460
+
461
+ Blinking depends on terminal support. `HIDDEN` is commonly used to conceal terminal text, but the receiving terminal still decides how that effect behaves.
462
+
463
+ ### Reset
464
+
465
+ `Reset` currently has one member:
466
+
467
+ | Operation | ANSI Code |
468
+ |---|---:|
469
+ | `RESET` | `0` |
470
+
471
+ Use it to return text styling to its default state:
472
+
473
+ ```python
474
+ print(
475
+ Ansi.ansi(ForegroundColor.RED)
476
+ + "Red"
477
+ + Ansi.ansi(Reset.RESET)
478
+ + " Normal"
479
+ )
480
+ ```
481
+
482
+ The reset stops your styling from leaking into later output, which matters especially when your code is part of a reusable terminal application.
483
+
484
+ ### Cursor movement
485
+
486
+ `CursorMovement` provides directional CSI commands:
487
+
488
+ | Direction | ANSI Command |
489
+ |---|---|
490
+ | `UP` | `A` |
491
+ | `DOWN` | `B` |
492
+ | `RIGHT` | `C` |
493
+ | `LEFT` | `D` |
494
+
495
+ For example:
496
+
497
+ ```python
498
+ print(
499
+ Ansi.ansi(
500
+ CursorMovement.UP.value
501
+ )
502
+ )
503
+ ```
504
+
505
+ The enum value supplies the direction without a distance. When the numeric parameter is omitted, the terminal applies the ANSI default. You can build a parameterized action string, such as `f"2{CursorMovement.UP.value}"`, to request two rows explicitly.
506
+
507
+ ### Cursor visibility
508
+
509
+ `CursorVisibility` lets you hide or show the cursor:
510
+
511
+ | Operation | ANSI Sequence |
512
+ |---|---|
513
+ | `HIDE` | `?25l` |
514
+ | `SHOW` | `?25h` |
515
+
516
+ Hide it:
517
+
518
+ ```python
519
+ print(
520
+ Ansi.ansi(
521
+ CursorVisibility.HIDE.value
522
+ ),
523
+ end=""
524
+ )
525
+ ```
526
+
527
+ Show it again:
528
+
529
+ ```python
530
+ print(
531
+ Ansi.ansi(
532
+ CursorVisibility.SHOW.value
533
+ ),
534
+ end=""
535
+ )
536
+ ```
537
+
538
+ This is useful for terminal interfaces, animations, and progress displays where a blinking cursor would otherwise wander through the scenery.
539
+
540
+ ### Line navigation
541
+
542
+ `LineNavigation` provides commands for moving between terminal lines:
543
+
544
+ | Operation | ANSI Command |
545
+ |---|---|
546
+ | `NEXT` | `E` |
547
+ | `PREV` | `F` |
548
+
549
+ For example:
550
+
551
+ ```python
552
+ print(
553
+ Ansi.ansi(
554
+ LineNavigation.NEXT.value
555
+ )
556
+ )
557
+ ```
558
+
559
+ `Ansi.ansi()` emits these as CSI sequences. `NEXT` moves to the start of a following line and `PREV` to the start of a preceding line; a numeric prefix supplies the count.
560
+
561
+ ### Erasing
562
+
563
+ `Erasing` removes terminal content:
564
+
565
+ | Operation | ANSI Command |
566
+ |---|---|
567
+ | `SCREEN` | `2J` |
568
+ | `SCROLL` | `3J` |
569
+ | `LINE` | `K` |
570
+ | `TO_START` | `1K` |
571
+
572
+ | Member | Area affected |
573
+ | --- | --- |
574
+ | `SCREEN` | The screen. |
575
+ | `SCROLL` | Scrollback. |
576
+ | `LINE` | From the cursor to the end of the current line. |
577
+ | `TO_START` | From the start of the current line to the cursor. |
578
+
579
+ Clear the screen:
580
+
581
+ ```python
582
+ print(
583
+ Ansi.ansi(
584
+ Erasing.SCREEN.value
585
+ ),
586
+ end=""
587
+ )
588
+ ```
589
+
590
+ Clear the rest of the current line:
591
+
592
+ ```python
593
+ print(
594
+ Ansi.ansi(
595
+ Erasing.LINE.value
596
+ ),
597
+ end=""
598
+ )
599
+ ```
600
+
601
+ Clear back to the start of the line:
602
+
603
+ ```python
604
+ print(
605
+ Ansi.ansi(
606
+ Erasing.TO_START.value
607
+ ),
608
+ end=""
609
+ )
610
+ ```
611
+
612
+ These actions let you update visible output without treating every change as another printed line.
613
+
614
+ > **TIP**
615
+ > Erasing a line does not move the cursor to its beginning. Combine erasing with cursor movement when you need both. `Ansi.clear` requests screen erasure and home, while `Erasing.SCROLL` is a separate scrollback operation.
616
+
617
+ ### Teleportation
618
+
619
+ `Teleportation` groups cursor positioning and position-storage commands. No science-fiction equipment required.
620
+
621
+ | Operation | ANSI Command |
622
+ |---|---|
623
+ | `HOME` | `H` |
624
+ | `SAVE` | `s` |
625
+ | `RESTORE` | `u` |
626
+
627
+ Move to the terminal's home position:
628
+
629
+ ```python
630
+ print(
631
+ Ansi.ansi(
632
+ Teleportation.HOME.value
633
+ ),
634
+ end=""
635
+ )
636
+ ```
637
+
638
+ Save the current cursor position:
639
+
640
+ ```python
641
+ print(
642
+ Ansi.ansi(
643
+ Teleportation.SAVE.value
644
+ ),
645
+ end=""
646
+ )
647
+ ```
648
+
649
+ Restore the saved position:
650
+
651
+ ```python
652
+ print(
653
+ Ansi.ansi(
654
+ Teleportation.RESTORE.value
655
+ ),
656
+ end=""
657
+ )
658
+ ```
659
+
660
+ Saving and restoring is useful when you temporarily write somewhere else and then return to the previous cursor location. Support for position save/restore can vary between terminals.
661
+
662
+ ### API at a glance
663
+
664
+ The complete member list is below. For the action enums, use `.value` when passing a member to `Ansi.ansi()`.
665
+
666
+ #### Foreground Colors
667
+
668
+ ```python
669
+ ForegroundColor.BLACK
670
+ ForegroundColor.RED
671
+ ForegroundColor.GREEN
672
+ ForegroundColor.YELLOW
673
+ ForegroundColor.BLUE
674
+ ForegroundColor.MAGENTA
675
+ ForegroundColor.CYAN
676
+ ForegroundColor.WHITE
677
+ ```
678
+
679
+ #### Background Colors
680
+
681
+ ```python
682
+ BackgroundColor.BLACK
683
+ BackgroundColor.RED
684
+ BackgroundColor.GREEN
685
+ BackgroundColor.YELLOW
686
+ BackgroundColor.BLUE
687
+ BackgroundColor.MAGENTA
688
+ BackgroundColor.CYAN
689
+ BackgroundColor.WHITE
690
+ ```
691
+
692
+ #### Fonts
693
+
694
+ ```python
695
+ Fonts.BOLD
696
+ Fonts.FAINT
697
+ Fonts.ITALIC
698
+ ```
699
+
700
+ #### Decorators
701
+
702
+ ```python
703
+ Decorators.UNDERLINE
704
+ Decorators.DOUBLE_UNDERLINE
705
+ Decorators.STRIKE
706
+ Decorators.OVERLINE
707
+ ```
708
+
709
+ #### Effects
710
+
711
+ ```python
712
+ Effects.BLINK
713
+ Effects.REVERSE
714
+ Effects.HIDDEN
715
+ ```
716
+
717
+ #### Reset
718
+
719
+ ```python
720
+ Reset.RESET
721
+ ```
722
+
723
+ #### Cursor Movement
724
+
725
+ ```python
726
+ CursorMovement.UP
727
+ CursorMovement.DOWN
728
+ CursorMovement.RIGHT
729
+ CursorMovement.LEFT
730
+ ```
731
+
732
+ #### Cursor Visibility
733
+
734
+ ```python
735
+ CursorVisibility.HIDE
736
+ CursorVisibility.SHOW
737
+ ```
738
+
739
+ #### Line Navigation
740
+
741
+ ```python
742
+ LineNavigation.NEXT
743
+ LineNavigation.PREV
744
+ ```
745
+
746
+ #### Erasing
747
+
748
+ ```python
749
+ Erasing.SCREEN
750
+ Erasing.SCROLL
751
+ Erasing.LINE
752
+ Erasing.TO_START
753
+ ```
754
+
755
+ #### Teleportation
756
+
757
+ ```python
758
+ Teleportation.HOME
759
+ Teleportation.SAVE
760
+ Teleportation.RESTORE
761
+ ```
762
+
763
+ #### Main Interface
764
+
765
+ ```python
766
+ Ansi.ansi(*codes)
767
+ Ansi.reset
768
+ Ansi.clear
769
+ ```
770
+
771
+ ## Examples
772
+
773
+ ### Styled terminal output
774
+
775
+ This combines foreground colors, background colors, fonts, decorations, and explicit resets:
776
+
777
+ ```python
778
+ from ansirithm import (
779
+ Ansi,
780
+ ForegroundColor,
781
+ BackgroundColor,
782
+ Fonts,
783
+ Decorators,
784
+ Reset,
785
+ )
786
+
787
+ title = Ansi.ansi(
788
+ ForegroundColor.CYAN,
789
+ Fonts.BOLD,
790
+ Decorators.UNDERLINE
791
+ )
792
+
793
+ warning = Ansi.ansi(
794
+ ForegroundColor.YELLOW,
795
+ BackgroundColor.RED,
796
+ Fonts.BOLD
797
+ )
798
+
799
+ print(
800
+ title
801
+ + "Ansirithm"
802
+ + Ansi.ansi(Reset.RESET)
803
+ )
804
+
805
+ print(
806
+ warning
807
+ + "Warning"
808
+ + Ansi.ansi(Reset.RESET)
809
+ )
810
+
811
+ print("Normal terminal output.")
812
+ ```
813
+
814
+ The workflow is straightforward: construct a style, print the text, reset the style, and continue with normal output. The cursor-control example is separate below.
815
+
816
+ ### Cursor control
817
+
818
+ This example hides the cursor, erases the screen, moves home, prints a message, and restores visibility:
819
+
820
+ ```python
821
+ from ansirithm import (
822
+ Ansi,
823
+ CursorVisibility,
824
+ Erasing,
825
+ Teleportation,
826
+ )
827
+
828
+ # Hide the cursor
829
+
830
+ print(
831
+ Ansi.ansi(CursorVisibility.HIDE.value),
832
+ end=""
833
+ )
834
+
835
+ # Clear the screen
836
+
837
+ print(
838
+ Ansi.ansi(Erasing.SCREEN.value),
839
+ end=""
840
+ )
841
+
842
+ # Move to the home position
843
+
844
+ print(
845
+ Ansi.ansi(Teleportation.HOME.value),
846
+ end=""
847
+ )
848
+
849
+ print("Ansirithm terminal demo")
850
+
851
+ # Restore cursor visibility
852
+
853
+ print(
854
+ Ansi.ansi(CursorVisibility.SHOW.value),
855
+ end=""
856
+ )
857
+ ```
858
+
859
+ It shows the basic building blocks for a simple terminal interface or screen-based application. If you add work that can fail between `HIDE` and `SHOW`, put the visibility restoration in a `finally` block.
860
+
861
+ ### Dynamic styling and reusable themes
862
+
863
+ Collections and optional values let you assemble a style dynamically:
864
+
865
+ ```python
866
+ from ansirithm import (
867
+ Ansi,
868
+ ForegroundColor,
869
+ Fonts,
870
+ Decorators,
871
+ )
872
+
873
+ styles = [
874
+ ForegroundColor.MAGENTA,
875
+ Fonts.BOLD,
876
+ ]
877
+
878
+ underline = Decorators.UNDERLINE
879
+
880
+ sequence = Ansi.ansi(
881
+ styles,
882
+ underline
883
+ )
884
+
885
+ print(
886
+ sequence
887
+ + "Dynamic styling"
888
+ + Ansi.ansi(0)
889
+ )
890
+ ```
891
+
892
+ Here, `Ansi.ansi(0)` uses the numeric SGR reset value directly. `Ansi.ansi(Reset.RESET)` expresses the same reset with a readable enum name.
893
+
894
+ You can also build named styles once and reuse them throughout an application:
895
+
896
+ ```python
897
+ SUCCESS = Ansi.ansi(
898
+ ForegroundColor.GREEN,
899
+ Fonts.BOLD
900
+ )
901
+
902
+ ERROR = Ansi.ansi(
903
+ ForegroundColor.RED,
904
+ Fonts.BOLD
905
+ )
906
+
907
+ INFO = Ansi.ansi(
908
+ ForegroundColor.CYAN
909
+ )
910
+ ```
911
+
912
+ ### A compact greeting
913
+
914
+ For a small program, the same pattern fits comfortably in one place:
915
+
916
+ ```python
917
+ from ansirithm import (
918
+ Ansi,
919
+ ForegroundColor,
920
+ Fonts,
921
+ Decorators,
922
+ Reset,
923
+ )
924
+
925
+ style = Ansi.ansi(
926
+ ForegroundColor.CYAN,
927
+ Fonts.BOLD,
928
+ Decorators.UNDERLINE
929
+ )
930
+
931
+ print(
932
+ style
933
+ + "Hello from Ansirithm"
934
+ + Ansi.ansi(Reset.RESET)
935
+ )
936
+ ```
937
+
938
+ Visible text:
939
+
940
+ ```text
941
+ Hello from Ansirithm
942
+ ```
943
+
944
+ The terminal applies the cyan foreground, bold font, and underline from the emitted ANSI sequences. The plain-text output above shows the characters, not their visual formatting.
945
+
946
+ ## Good to know
947
+
948
+ > **IMPORTANT**
949
+ > Ansirithm generates sequences; it does not check the receiving terminal's capabilities or disable ANSI automatically. Redirected output still contains those sequences, so choose when to add styling if the same output also goes to a file.
950
+
951
+ The current implementation covers a subset of ANSI terminal functionality. It does not provide:
952
+
953
+ - 256-color support.
954
+ - True-color RGB sequences.
955
+ - A dedicated arbitrary row-and-column cursor-positioning interface.
956
+ - Terminal input handling.
957
+ - Keyboard event parsing.
958
+ - Terminal size detection.
959
+ - Platform-specific console APIs.
960
+ - Automatic terminal capability detection.
961
+ - Automatic ANSI disabling for unsupported terminals.
962
+ - Full ANSI/ECMA-48 sequence coverage.
963
+
964
+ Effect support varies between terminal emulators, especially for blinking, faint text, double underlines, overlines, and cursor-position save/restore. The library does not verify that a requested effect is supported.
965
+
966
+ ## Design notes
967
+
968
+ Ansirithm keeps terminal control explicit. Named enums make the codes readable, and `Ansi.ansi()` is the shared mechanism that turns those values into actual escape strings.
969
+
970
+ Each category has a specific job: `ForegroundColor` and `BackgroundColor` select colors; `Fonts`, `Decorators`, and `Effects` set text attributes; `Reset` ends those attributes; `CursorMovement`, `CursorVisibility`, and `LineNavigation` control the cursor; `Erasing` removes content; and `Teleportation` handles home, save, and restore operations.
971
+
972
+ The utility stays focused on that translation layer rather than implementing a terminal emulator. You retain the ANSI control system, with readable names attached to the machinery. A respectable improvement over treating `\033[36;1;4m` as a friendly user interface.
@@ -0,0 +1,7 @@
1
+ ansirithm/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ ansirithm/ansirithm.py,sha256=snoWc0vR9O7Ip767UWr4prDjVfacVU9BiIAJj19wu2Q,2049
3
+ yapping_ansirithm-0.1.0.dist-info/licenses/LICENSE,sha256=PRYv9Y8uqHFOEixDS2z_uFQtw1aVEE1mZX6fcvlVM7w,1090
4
+ yapping_ansirithm-0.1.0.dist-info/METADATA,sha256=OVEUS--JJSM4866tr9Knu-BfP3ejm2zqlzmkJkcvWLs,22446
5
+ yapping_ansirithm-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
6
+ yapping_ansirithm-0.1.0.dist-info/top_level.txt,sha256=_N8K0rfAES_ViupDeZFxH_o8wd637QOwSwfYOG72lcg,10
7
+ yapping_ansirithm-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ghetea-patrick
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ ansirithm