From 9f817ff112fc0a52b0be9bc00f013b730f3314ff Mon Sep 17 00:00:00 2001 From: filip Date: Tue, 9 Mar 2021 15:02:21 +0100 Subject: [PATCH] first commit --- ansi_escape.py | 63 +++++++++++++++++++++++++++++++++++++++++ examples/ansi_escape.py | 1 + examples/test.py | 9 ++++++ readme.md | 7 +++++ 4 files changed, 80 insertions(+) create mode 100644 ansi_escape.py create mode 120000 examples/ansi_escape.py create mode 100644 examples/test.py create mode 100644 readme.md diff --git a/ansi_escape.py b/ansi_escape.py new file mode 100644 index 0000000..1baa017 --- /dev/null +++ b/ansi_escape.py @@ -0,0 +1,63 @@ +def bell(): + print("\u0007") + +def color(mode, ground, *args): + return_string = "\u001b[" + if mode == "bright": + return_string += "1;" + + if ground == "fg": + return_string += "3" + elif ground == "bg": + return_string += "4" + + if mode == "256": + return_string += "8;5;" + return_string += args[0] + return_string += "m" + return return_string + + elif mode == "rgb": + return_string += "8;2;" + return_string = return_string + args[0] + ";" + args[1] + ";" +args[2] + return_string += "m" + return return_string + + elif mode == "normal": + color_chart = { + "black": "0", + "red": "1", + "green": "2", + "yellow": "3", + "blue": "4", + "magenta": "5", + "cyan": "6", + "white": "7" + } + a = color_chart[args[0]] + return_string += a + return_string += "m" + return return_string + +bell = "\u0007" +backspace = "\u0008" +escape = "\u001b" +csi = escape + "[" +reset = csi + "0m" +normal = reset +bold = csi + "1m" +underline = csi + "4m" +blink = csi + "5m" +invert = csi + "7m" +strike = csi + "9m" +normal_intensity = csi + "22m" +#no_italic = csi + "23m" #not vidley supported +no_blink = csi + "25m" +no_strike = csi + "29m" +reset_fg = csi + "39m" +reset_bg = csi + "49m" +overline = csi + "53m" +no_overline = csi + "55m" +frame = csi + "51m" +encircle = csi + "52m" +no_frame = csi + "54m" \ No newline at end of file diff --git a/examples/ansi_escape.py b/examples/ansi_escape.py new file mode 120000 index 0000000..95d8672 --- /dev/null +++ b/examples/ansi_escape.py @@ -0,0 +1 @@ +/home/filip/Documents/python3/ansi_escape/ansi_escape.py \ No newline at end of file diff --git a/examples/test.py b/examples/test.py new file mode 100644 index 0000000..70033dc --- /dev/null +++ b/examples/test.py @@ -0,0 +1,9 @@ +import ansi_escape +a = 0 +while a < 256: + b = str(a) + print(ansi_escape.color("256", "bg", b) + " " + b + " " + ansi_escape.reset, end='') + a += 1 + +print(ansi_escape.escape + "]0;Demo" + ansi_escape.escape + "\\") +input() \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..881d180 --- /dev/null +++ b/readme.md @@ -0,0 +1,7 @@ +# ansi_escape +## A pure python3 library for ansi VT-100 escape codes +Features: + SGR (Select Graphic Rendition) +SGR foreground and background color in 4-bit color, 8-bit color and 24-bit color +SGR text formating like; underline, overline and bold text +Easy way to use the bell character \ No newline at end of file