You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/blog/posts/release1.0.0.md
+17-9Lines changed: 17 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ draft: true
3
3
date: 2024-12-05
4
4
categories:
5
5
- Release
6
-
title: "Three algorithms for high performance terminal apps"
6
+
title: "Algorithms for high performance terminal apps"
7
7
authors:
8
8
- willmcgugan
9
9
---
@@ -20,9 +20,11 @@ I've had the fortune of being able to work fulltime on a FOSS project for the la
20
20
Textual has been a constant source of programming challenges.
21
21
Often frustrating but never boring, the challenges arise because the terminal "specification" says nothing about how to build a modern User Interface.
22
22
The building blocks are there: after some effort you can move the cursor, write colored text, read keys and mouse movements, but that's about it.
23
-
Everything else we had to build from scratch, from the most basic [button](https://textual.textualize.io/widget_gallery/#button) to a syntax highlighted [TextArea](https://textual.textualize.io/widget_gallery/#textarea), and everything along the way.
23
+
Everything else we had to build from scratch. From the most basic [button](https://textual.textualize.io/widget_gallery/#button) to a syntax highlighted [TextArea](https://textual.textualize.io/widget_gallery/#textarea), and everything along the way.
24
24
25
-
I wanted to write-up some of the more interesting solutions we came up with, and the 1.0 milestone we just passed makes this a perfect time.
25
+
I wanted to write-up some of the solutions we came up with, and the 1.0 milestone we just passed makes this a perfect time.
26
+
27
+
<!-- more -->
26
28
27
29
If you haven't followed along with Textual's development, here is a demo of what it can do.
28
30
This is a Textual app, running remotely, served by your browser:
The first component of Textual I want to cover is the *compositor*.
45
-
The job of the compositor is to combine widgets in to a single view.
46
+
The first component of Textual I want to cover is the [compositor](https://github.com/Textualize/textual/blob/main/src/textual/_compositor.py).
47
+
The job of the compositor is to combine content from multiple sources into a single view.
46
48
47
49
We do this because the terminal itself has no notion of overlapping windows in the way a desktop does.
48
-
If an app wants to display overlapping components we must first combine (or compose) them into a single update.
49
50
50
51
Here's a video I generated over a year ago, demonstrating the compositor:
51
52
@@ -64,12 +65,11 @@ Some characters such as those in Asian languages and many emoji are double the w
64
65
65
66
Textual's way of handling this is inherited from [Rich](https://github.com/Textualize/rich).
66
67
Anything you print in Rich, first generates a list of [Segments](https://github.com/Textualize/rich/blob/master/rich/segment.py) which consist of a string and associated style.
67
-
These Segments are only converted into text with [ansi escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) at the very last moment.
68
+
These Segments are only converted into text with [ansi escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) at the very end of the process.
68
69
69
70
70
-
Textual builds its output from the same Segment object.
71
71
The compositor takes lists of segments generated by widgets and further processes them, by dividing and combining, to produce the final output.
72
-
In fact almost everything Textual does involves processing these segments in one way or another,.
72
+
In fact almost everything Textual does involves processing these segments in one way or another.
73
73
74
74
!!! tip "Switch the Primitive"
75
75
@@ -263,6 +263,14 @@ The useful property of this algorithm is that as the number of widgets increases
263
263
264
264
The code for our `SpatialMap` isn't part of the public API and therefore not in the docs, but if you are interested you can check it out here: [_spacial_map.py](https://github.com/Textualize/textual/blob/main/src/textual/_spatial_map.py).
265
265
266
+
## Wrapping up
267
+
268
+
If any of the code discussed here interests you, you have my blessing to [steal the code](./steal-this-code.md)!
269
+
270
+
As always, if you want to discuss this or Textual in general, we can be found on our [Discord server](https://discord.gg/Enf6Z3qhVr).
271
+
272
+
273
+
266
274
[^1]: A term I coined for the structure in Textual. There may be other unconnected things known as spatial maps.
267
275
[^2]: The [grid](https://www.youtube.com/watch?v=lILHEnz8fTk&ab_channel=DaftPunk-Topic).
268
276
[^3]: If you scroll the screen up, it moves *down* relative to the widgets.
0 commit comments