Termix is a small library that uses ANSI Escape Codes to control your texts in the Console.
Firstly, configure the library by manually setting it up (Search it up).
INSTRUCTION:
- Download the package
- If you are using a virtual enviroment; extract and move termix folder inside lib/python../site-packages/
- If not, find the python folder and the library folder; move it there
Now the few uses of Termix; Classes and their corresponding methods:
1. Using the Ansi Class to design a text:
Ansi Methods:
- reset()
Returns: ESC[0m, Reset all modes (styles and colors), put at the end of the string/text to avoid leaks.
- textColor(RGB Value)
Returns: ESC[38;2;{r};{g};{b}m
- bgColor(RGB Value)
Returns: ESC[48;2;{r};{g};{b}m
- graphicMode(Graphical Rendition Mode)
Returns: working Graphical Rendition Modes.
Code Example:
import termix
# Using Ansi Class to Design
txt_color = termix.Ansi.textColor((12, 245, 0))
# bg_color = termix.Ansi.bgColor() <- Defaults to black (0, 0, 0)
mode = termix.Ansi.graphicMode(("underline", "italic"))
reset = termix.Ansi.reset()
# Sequence: AnsiCodes-Text-Reset
print(txt_color+mode+"Ansi"+reset)
# print(txt_color, mode, "Hello", reset) <- Also possible but will add a space " Hello"
-------- console --------
Hello
-------------------------
# Using Cursor to set cursor position and print
cursor = Cursor(3, 4)
txt_color = Ansi.textColor((182, 0, 192))
mode = Ansi.graphicMode(("bold", "underline"))
reset = Ansi.reset()
# Sequence: Cursor+AnsiCodes-Text-Reset
cursor.go() <- Sets cursor to position
print(txt_color+mode+"Hello"+reset)
# print(cursor.getAnsi()+txt_color+mode+"Ansi"+reset)
-------- console --------
0123...
1
2
3
4 Hello
-------------------------
2. Using the Text Object to design a text: Text Methods:
- Initialization
text = termix.Text(Text, X, Y, Graphical Modes, Text Color, Background Color)
- remove()
Removes that Text from the Console.
- getPos()
Returns: (X, Y), the position of the Text.
- str()
Returns: the text with the added ANSI Esc Codes.
- write()
Writes the Text with the added ANSI Esc Codes to the Console.
Code Example:
import termix
# Using the Text-Object to Design
text = Text("Text", x=1, y=2, graphicModes=("underline", "italic"), textColor=(12, 245, 0))
print(text.str())
# text.write() <- same result; will print without using print function
- Setting cursor position with the Cursor class:
Cursor Methods:
- Initialization
(Optional) cursor = termix.Cursor(X, Y)
- go()
Sets cursor position to given position.
- getAnsi()
Returns: Esc[{Y};{X}f the position as Ansi Esc Code.
- showCursor(Boolean)
(Static Method) Make cursor invisible or visible.
Code Example:
import termix
# Initializing
cursor = termix.Cursor(2, 2)
cursor.go()
# .getAnsi() was used at Ansi Class part to set a position and print, check for example.
# On the spot
termix.Cursor(2, 2).go()
termix.showCursor(False)
- Clearing the Console or Lines with the Terminal Class:
Terminal Methods:
- clearScr()
(Static Method) Clears entire Console.
- lclear()
(Static Method) Clears left side till the cursor.
- rclear()
(Static Method) Clears right side from the cursor.
Code Example:
import termix
# Clearing the entire console
termix.Terminal.clearScr()
# Clearing the left-side to till your cursor
print("hello world")
Cursor(1, 7).go()
termix.Terminal.lclear()
-------- console --------
hello world
^ (cursor here)
world
-------------------------
# Clearing the right-side from your cursor
print("hello world")
Cursor(1, 7).go()
termix.Terminal.lclear()
-------- console --------
hello world
^ (cursor here)
world
-------------------------