114 points · by bczsalba · 4y ago · 19 comments
The markup language is another great feature of the library, and is used by practically all elements of it. It is based on Rich's implementation, but uses a more concise and easier to humanly parse syntax, while being over 10 times faster at parsing due to a long list of optimizations.
There is a full Window Manager API included as well, allowing the user to move, resize and otherwise manipulate windows and inner contents using either their mouse of keyboard.
All of the "guts" of the library are also exposed and usable from the outside within the `ansi_interface` submodule.
Thank you for your time, and I hope the library may be of some use!
Most TUI apps I use do no involve space consuming borders, buttons, interactive dragging/resizing etc. That's also precisely why I prefer TUIs for some apps, to not be dependent on those features and navigate by shortcut keys instead.
Fair question though! WindowManager honestly started off as a joke with my friend, and just so happened to end up being the main "entry point" to the library. In the future pre-defined (or even dynamic) layouts should allow the above mentioned to happen when needed, but also keep all the optional mouse input shenanigans working as intended.
Edit: One thing that I think can showcase some of the upsides an architecture like this has is an ongoing project of mine based on PTG, https://github.com/bczsalba/Pagoda. It is primarily a frontend for a WIP messaging protocol me an my friend are creating, but the main idea behind it is the chat functionality is all confined within an "application", and that the user can write and install their own applications to be run from within Pagoda. This kind of makes the system feel like a proper desktop WM, and I think is a really cool idea. As the project is still very early the only available app is the messaging one, but I do have high hopes for it, if nothing else as a tech-demo for what PTG can do.
The resizing bit was a bit of a mess to implement properly, but the current system does things like calculate the predicted minimum width of a window and not letting you minimize further, among other things.
Thank you so much for checking it out!
I’ve been using Rich and Im about to try Textual for the gui of some scripts.
In PyTermGUI there is a large focus on the underlying terminal APIs and their implementations. This is because there are no external libraries to help us with them, so everything is hand-coded, and as an extension available to anyone from the outside. While the flashy part of PTG is the WindowManager class, the library is just as well suited for minimal applications such as converting your scripts' boring output to colored text or a nice looking Container. This is not advertised as much as it doesn't look that cool compared to everything else, but there is real value in it.
There is also some conceptual differences: Rich and Textual are very web-based in how they work and their syntacies, while PTG is very much not. This doesn't show up in many places, but for example in Rich, expressing an xterm-256 color would be like:
[color(141)]This is lavender
While PTG lets you just use [141]This is lavender
...or with RGB: [rgb(111, 222, 333)]I have no idea what this color is
vs: [111;222;333]I have no idea what this color is
I suppose the biggest difference is that Textual is async-based and PTG is synchronous. Both can be run from the other paradigm, but converting async-sync or vice-versa in a decent sized project is pretty difficult.Other than that it's a lot of minor things. Most ideas can be created with either, though depending on your needs one might be more suitable than the other. For example, Textual does not support windowing in any way, while PyTermGUI does support full-screening, so if you want to create a modal popup on top of a larger background screen my version should be a bit easier to achieve it with.
Also, PTG code tends to be a bit shorter and usually easier to read, and IMO our markup syntax is much nicer (and as a fact, our parser significantly faster) and our Widget system is a bit easier to manage and extend.
Any idea why the getch demo does not report the Escape key?
IIRC it used to work just fine, but it hasn't for a minute. There is some weird handling with ESC, as most of the time it is the start of a longer sequence, so I probably just messed something up in that while refactoring.
Will look into it when I have the time, thank you!
EDIT: GUIs had tradition of having mnemonics in menus and sometimes even on buttons. That is until smart people started removing it in the name of the design.
EDIT: Still, will check it out, though I will try to hack my way into adding mnemonics to buttons. Because arrow/tab navigation is f-ing stupid.
About "wasting pixels"... What if I (and many others) like the aesthetic and simplicity? There is a sort of magic in never having to leave your terminal emulator. Most frameworks are still keyboard-centered, as many of them don't even have mouse support to replace it with.
Edit: Thank you for your interest though! If you have a syntactically neat way to do the things you talked about feel free to raise an issue and I'll get to it as it comes up.
So something like
ptg.KeyboardButton("Help")
or ptg.KeyboardButton("Action", binding=ptg.keys.CTRL_B)
These would create a button with a label such as "[H]elp" and "[B] Action", and pressing `CTRL_` + their button would activate them. If idea is fine implementation should really not take much time.