pypi PyTermGUI 6.0.0
v6.0.0: Layouts, inspection & highlighting!

latest releases: 7.8.1, 7.8.0, 7.7.4...
4 years ago

This version was originally meant to focus on the new layout system, but things got out of hand quickly. In the end, we have the aforementioned feature, alongside a completely reimagined & much more useful CLI, a regex-based syntax highlighting base, major performance improvements and some general QOL things. There unfortunately are some (relatively minor) API changes, which is why this version is 6.0.0 instead of 5.1.0.

Changelog

  • Remove Window.allow_fullscreen, Window.toggle_fullscreen (114da3a)

    These methods are no longer really relevant in the new layout-based system. They were also handled in a really odd way from the library's side, so it should be one less bug-prone area to figure out. You can now set windows fullscreen using the layout system:

     manager.layout.add_slot("Body")
     manager.add(window, assign="body")

    More on the layout API later.

Refactors

  • Add new, customizable window blur styles (114da3a)

    The old style was visually impressive, however also prone to causing bugs that could not be resolved with either stripping functionality or changing the library source. The new version follows traditional and modern TUIs more closely by only changing the color of borders, and is actually customizable. However, since there are new styles for both blurred and focused states for both the corner and border set of characters, a small helper was also added, Window.set_focus_styles.

  • Rename all builtin aliases to follow the domain.item naming scheme (3a416f5)

  • Improve animation stability (c806b97, 05b6126)

  • Start caching real_length, strip_markup & strip_ansi results (a07ce9f, 532e3cc)

    This was altogether a sub-10 line change, but it actually has huge performance implications. It will also be useful for the future, more advanced compositing running at an acceptable speed.

  • Refactor StyledText to only tokenize on-demand (b15eba8)

  • Rewrite the pattern used to match markup to improve how escapes are handled (d656b75, 5a37470)

  • Introduce new, layout based CLI with an RGB colorpicker & inspector (3143336)

    This started off as a way to showcase the new layouts, and wasn't even supposed to be a full rewrite. However, I eventually realized how ridiculously over-engineered the previous CLI was, so I decided to come up with a new system. There is a new app, Inspector, which basically runs the inspect function interactively, and can be called from the command line with no interaction. There is also now an RGB color picker, and some bindings to the new highlight_python function (more on that later).

    For some reason my favorite part of this new module is the output of -v:

    Screenshot 2022-05-12 at 23 37 24

Additions

  • Add Collapsible widget (114da3a)

  • Add new highlighters module with RegexHighlighter class (7e6cd02, 6bd3d4a)

    This class can be used to statically highlight any type of text, combining regex with TIM. Since it's fully based around regex it will never be a full highlighter, a'la Pygments, but I feel like that is outside of the scope of the library. See an example of this in the showcase section.

  • Add is_scroll, is_primary & is_secondary helpers to MouseEvent (522e4dd)

  • Add Terminal.no_record context (b7d4976)

  • Add WindowManager.alert and WindowManager.float methods (53e9b84)

    The alert function is pretty much the exact same in terms of functionality to the one that came before it, though it's been refactored a bit. The toast method however is completely new to the library, but it's goal and general look & feel come from the Android feature of the same name. I personally think it looks dope, and you catch a glance at it on ptg startup!

  • Add layout assign parameter to WindowManager.add (6c95ac0)

  • Add window manager Layout class (8250d6d)

    This really is the feature of this update. Essentially, layouts let you define sizes & positions for your windows, which is then continually applied whenever the terminal resizes or windows are removed/added. It also tries to be minimal but expressive in its syntax, and do as many dynamic things as possible.

    For example, take the following code:

     manager.layout = ptg.Layout()
     manager.layout.add_slot("Header", height=5)
     manager.layout.add_break()
     manager.layout.add_slot("Sidebar", width=0.2)
     manager.layout.add_slot("Body")
     manager.layout.add_break()
     manager.layout.add_slot("Footer", height=3)

    It creates a 3-row layout. The first row just contains a header with a height of 5, and spanning the entire terminal in its width. The second row contains a sidebar that is 20% of the terminal's width, and a body that fills whatever remaining space it has. Finally, we have a footer, that is 3 characters height and once again spans the entire terminal.

    You may have noticed that the second row had no height definitions whatsoever. This is because the layout can calculate the remaining height for the row based on the slots with static dimensions. In effect, this means that you only need to specify the 'defining dimension' for each slot, and the rest will be calculated by the library. This Dimension system may in the future be extended into the realm of widgets, and I have plans of first adding the ability to nest layouts, and maybe eventually adding a layout-based container widget.

    Screenshot 2022-05-12 at 23 49 27

Bugfixes

  • Fix overly greedy optimization in MarkupLanguage.parse getting rid of important unsetters (32e30b5)
  • Fix / not being handled properly in various places (2b15e51, e3e9e87)

Showcase

Screenshot 2022-05-12 at 23 02 27
Screenshot 2022-05-12 at 23 02 55
Screenshot 2022-05-12 at 23 04 02
Screenshot 2022-05-12 at 23 05 36

Closing thoughts

That's all for now. Next up should be either a full ScrollView widget that wraps around an inner Container, a more efficient compositing method, a universal & real-life user tested color palette or a combination of all. Since I'm currently quite busy with university I'm not sure when I'll get around to creating a new release, but it shouldn't be too far off.

As a final note, this release might be the one to push the library over 1000 stars. Thank you to everyone who has ever used PTG, raised an issue or even just checked it out or left a critical HackerNews comment for it. I never imagined my work to become this popular, and I can't wait to see where it ends up.

Ok, bye

🚀

Don't miss a new PyTermGUI release

NewReleases is sending notifications on new releases.