This repository was archived by the owner on Sep 10, 2026. It is now read-only.
Repository navigation
v0.3.0: The Mark(up) of the Snake!
Overview
This release focuses on the parser submodule, rebuilding it from the ground up and adding some much needed features & performance in the process.
-
New support for differing line-lengths in
Splitter -
Rewrite
pytermgui.parser:- The module is now instance based, allowing for isolated macro & tag definitions
- Much more robust markup parsing
- Up to 60% speed improvement compared to
0.2.1 - Better
macrosyntax:[!align]30:center text->[!align(30,center)]text - Introduce cache system for
MarkupLanguage.parse - Note: The
WindowManagerdoesn't play too nicely with this system. This will be fixed next patch.
-
Improve terminal size handling:
- Add new
pytermgui.ansi_interface.terminalobject - This object is used for getting
size,width&heightof the current terminal - Support subscribing to
SIGWINCHevent to gracefully handle resize events
- Add new
-
Remove
Widgetfocus system- This was introduced specifically for
InputField, which no longer uses it Widget.selected_indexshould be used instead
- This was introduced specifically for
Details
parser.py & MarkupLanguage
- The module provides a
MarkupLanguageinstance under the namemarkup, which is instantiated at import-time, which should be used for all global language settings & definitions - Additional instances may be created to host potentially unsafe macros or non-global aliases
- Under the hood, there is a much more robust & performant set of tokenizer methods
- Name changes:
define_tag()->MarkupLanguage.alias()define_macro()->MarkupLanguage.define()markup()->MarkupLanguage.get_markup()ansi()->MarkupLanguage.parse()tokenize_markup()->MarkupLanguage.tokenize_markup()tokenize_ansi()->MarkupLanguage.tokenize_ansi()
End result
parser.py
The speed difference can be showcased using a simple script to render a MarkupApplication window:
import time
import pytermgui
from pytermgui.cmd import MarkupApplication
formatter = pytermgui.MarkupFormatter("[60 bold]{item}")
for obj in [pytermgui.Window, pytermgui.Container]:
obj.set_style("border", formatter)
obj.set_style("corner", formatter)
manager = pytermgui.WindowManager()
app = MarkupApplication(manager)
window = app.construct_window()
lines = window.get_lines()
for _ in range(2):
nums = []
for i in range(100):
start = time.time()
window.get_lines()
took = time.time() - start
nums.append(took)
print("avg:", sum(nums) / len(nums))
print("max:", max(nums))
print("min:", min(nums))If you do the math, 0.00418 / 0.00970 comes up to 43%, meaning the improvement in this scenario is around 55%. This can be even larger in more complex applications.
Funnily enough, the aforementioned issue with WindowManager is that it cannot handle this speed. It gets greedy with frame-rendering, and overloads what my old MacBook can handle.
ok, bye 🚀

