#336: Terminal magic with Rich and Textual Transcript
00:00 Have you heard of the package rich?
00:01 This library allows you to create, well, rich terminal-based UIs in Python.
00:06 When you think of what you can typically build with basic print statements,
00:09 they may seem quite limited.
00:11 But with rich, imagine justified tables, progress bars, rendering of markdown, and way more.
00:17 This is one of the fastest-growing projects in the Python space these days,
00:21 and the creator, Will McGoogan, is here to give us the whole history and even a peek at the future of rich and a follow-on library called Textual.
00:29 This is Talk Python to Me, episode 336, recorded October 13th, 2021.
00:34 Welcome to Talk Python to Me, a weekly podcast on Python.
00:50 This is your host, Michael Kennedy.
00:52 Follow me on Twitter, where I'm @mkennedy, and keep up with the show and listen to past episodes at talkpython.fm.
00:58 And follow the show on Twitter via at Talk Python.
01:01 We've started streaming most of our episodes live on YouTube.
01:05 Subscribe to our YouTube channel over at talkpython.fm/youtube to get notified about upcoming shows and be part of that episode.
01:12 This episode is brought to you by Shortcut, formerly known as clubhouse.io,
01:17 and us over at Talk Python Training.
01:19 And the transcripts are brought to you by Assembly AI.
01:24 Will, welcome to Talk Python to Me.
01:25 Thank you.
01:26 It's fantastic to finally have you on the show.
01:28 I feel like we've talked a lot about the work that you've been doing many times.
01:32 Not so much on Talk Python because we're more focused on a single topic.
01:36 But even so, I believe, you know, at the end, I always ask for some project that needs attention,
01:41 needs some sort of shout out.
01:43 And, you know, I believe Rich has come up more than once.
01:45 I think Textual has come up at least once there.
01:48 So the prior guests of the show have been fans.
01:51 And I know the audience is a big fan.
01:53 So, yeah, congrats on all the progress there.
01:56 Great. Thanks.
01:57 Yeah, I really appreciate the coverage.
01:58 You probably increased my star count by a few thousand.
02:02 Well, I do want to talk about that because this project is super popular.
02:06 And as we get into it, I think it's going to be fun to explore some of the things that you felt were key to that.
02:12 And if this is the first time people are hearing about Rich, you definitely want to check out some of the screenshots.
02:18 Maybe I'll do something fun, like make part of the show, have the show notes or the podcast player have some screenshots from the various sections.
02:26 Like as I said, I'll see if I can make that happen.
02:28 But before we get to all that, before we dive into Rich and Textual and all the other things, let's talk about you.
02:33 How did you get into programming and how did you find yourself doing all this open source Python?
02:37 How did I get into programming?
02:39 Oh, OK.
02:39 So as a kid in the 80s, I guess, I had a Spectrum 48K computer.
02:44 It was a little plastic thing you plugged into your TV and you could create very simple animations and little games.
02:51 And I think from there I was hooked.
02:52 Oh, fantastic.
02:53 That's just something about me that connected with programming, I guess.
02:57 What's interesting is those games were so basic, right?
03:00 They weren't like 3D, VR, oh my gosh, I'm there.
03:03 Or some of the flashy, even the flashy mobile apps, mobile games these days.
03:08 But something about those early, early games really captured the imagination, didn't they?
03:13 Yeah.
03:14 And the fact that they were so limiting had to make you a little bit creative.
03:18 So it encouraged creativity because you couldn't do much of anything.
03:21 So you had to make the best of what you got.
03:24 So it encouraged you to experiment.
03:26 And I think it was a great way to get people into programming again, I think.
03:29 Yeah.
03:30 Until recently, we haven't had that.
03:32 And I think the Raspberry Pi does that to some extent, which is a great thing.
03:35 Yeah.
03:35 It sort of reaches out to the real world in a more simplistic way, kind of repeating that cycle, right?
03:41 Yeah.
03:41 Yeah.
03:42 And it just allows people access to programming in a very kind of accessible form for children, I guess.
03:48 So I think the next generation in 20 years will be citing Raspberry Pi as how they got into programming.
03:55 Interesting.
03:55 Yeah.
03:56 I built a robot the first time around or something like that, right?
03:59 Yeah.
03:59 Instead of wanting to play a game or script a game out or something like that.
04:04 Interesting.
04:04 And, you know, a lot of times I ask people, okay, well, what are you doing now?
04:08 They're like, oh, I'm, you know, head of data science at a company such and such.
04:13 You've taken a very interesting, and I suspect a lot of people will be quite jealous of what you're up to these days, right?
04:20 What are you doing now?
04:21 Yeah.
04:21 So up until recently, I was contracting.
04:24 But I ended my contract.
04:26 I'm going to take a year out.
04:28 Well, possibly a year.
04:30 It depends how much.
04:31 It depends how things go.
04:32 But the idea is to work on open source, specifically rich and textual.
04:38 There are other projects that take my fancy as well.
04:40 Anything that I can contribute to might try my hand at it.
04:44 It's not entirely selfless because I do think there might be commercial applications for textual down the line.
04:51 But certainly for this first six months, it'll be just focusing on just making it the best thing you can.
04:57 Making it a super solid foundation.
04:59 Yeah, absolutely.
05:00 Well, I don't think it's going to take that much to get some things in place to make this long term for you.
05:07 You know, people can go, if their company or individually they're finding huge value, they could go to GitHub and sponsor you.
05:14 There's enterprise stuff that can be set up.
05:16 We'll dive a little bit into that more possibly later as well.
05:19 But I wish you a lot of luck.
05:21 But I think with the traction that you're getting and the new things like I really find GitHub's sponsor feature to be something of a game changer.
05:30 Yeah.
05:31 I remember looking back, you'd see, oh, here's a popular project.
05:34 Maybe it's not even an open source library, but it's like an app.
05:37 And it's like, click here to thank the developer on PayPal.
05:40 Right.
05:40 And just.
05:41 There was a little bit of a barrier to entry.
05:43 Yeah.
05:44 And maybe you do it once.
05:45 Right.
05:45 But with GitHub, you can say, I just kind of want to say, I want this to keep going.
05:49 So here's two dollars a month.
05:51 And if, you know, not that many people who find it valuable send in a couple of bucks a month, all of a sudden it starts to be a foundation that you can really build from.
05:58 Yeah.
05:58 It could build up and be something which is sustainable and sustain open source because so many people benefit from open source, including big companies, big corporations.
06:08 But a lot of these developers are doing it in their spare time for the love of it.
06:13 And they haven't asked for funding before, but a lot of them deserve funding.
06:18 Certainly lots of projects which could really use funding to make sure they keep going, to make sure that the software that we all use is still available in a year, two years and five years down the line.
06:30 Yeah.
06:30 Otherwise, we're going to end up in a place with like open SSL where there's one person who maintains it and a quarter of the world seems to be built directly upon it.
06:39 Right.
06:39 Remember that?
06:39 Yeah.
06:39 It was a huge problem.
06:41 Heartbleed, was it called?
06:42 Which is a Heartbleed?
06:44 Yeah.
06:44 Heartbleed, that's right.
06:45 Yeah.
06:46 Which is a great name for a bug.
06:47 It really is.
06:49 Why wasn't this fixed?
06:50 Well, there's one person who does it in their spare time, but everything depends on it.
06:54 Yeah, but there's still one person who does it in their spare time.
06:57 Yeah.
06:57 And yeah, it's just really hard to put that kind of energy and responsiveness into it.
07:01 All right.
07:02 Fantastic.
07:02 So let's start with textual, which I had on the screen, but let's start with rich.
07:07 Rich is where things got started amongst rich and textual, right?
07:11 If I remember the history.
07:12 Yeah.
07:13 Rich was first.
07:14 That's about two years ago that I started that.
07:16 Yeah.
07:16 Cool.
07:17 So tell people, you know, a lot of people have heard of rich, but maybe tell folks out there,
07:22 how would you describe it?
07:23 You know, it's, we've had ways to sort of print stuff nicer.
07:27 We've got pretty print Python.
07:29 We've got colorama where you can put color into your, your terminal, but this takes it
07:33 to an absolutely new level.
07:35 So tell us, tell us about rich.
07:36 Yeah.
07:37 that makes it difficult to describe sometimes when people ask me what it does, because it
07:40 does quite a lot of things.
07:42 but it's all under the umbrella of writing more sophisticated outputs to the terminal.
07:47 At the basic level is you can set colors and you can set styles like bold and italic.
07:53 the next level up, it'll do word wrap and it'll also word wrap the, the style.
07:58 So you can apply bold and then, then word wrap it.
08:00 And then we have things like tables.
08:03 There's quite sophisticated table support, which are quite close to HTML tables.
08:08 You can, you know, put things in cells.
08:10 You've got a header row, you've got a little divider, and then you've got the data.
08:13 Yeah.
08:14 Yeah.
08:14 And then you can draw lines around it and change the styles.
08:17 And, it's, it's all, you even have like alternating rows, right?
08:22 So it kind of helps you line across, which is pretty neat.
08:25 Exactly.
08:25 Yeah.
08:26 So it's, it's quite sophisticated.
08:27 It's all composable.
08:29 So if I've got a table, I can obviously put text inside it, but I can put another
08:33 table inside it, or I could put a progress bar inside it or syntax highlighting inside
08:37 it.
08:38 So the idea is that, rather than like lots of separate libraries, which don't work
08:41 well together, which I think was a situation that we had previously.
08:45 Now they all work together.
08:46 They fit inside each other and they integrate quite well.
08:49 Right.
08:50 So you could take your formatting and put it in your word wrap and put it inside of a
08:53 table cell or something like that.
08:54 Exactly.
08:54 Yeah.
08:55 Yeah.
08:55 Yeah.
08:56 Yeah.
08:56 Yeah.
08:56 So one of the things that struck me, well, there's a couple of things, but one of them
09:00 is just how popular Rich is.
09:03 Right.
09:03 It's almost 30,000 GitHub stars.
09:05 That's, that's close to FastAPI level of popularity and not that far behind Flask and
09:11 Django.
09:11 That's a really, really popular.
09:13 When did you create this?
09:14 Two years ago.
09:15 Yeah.
09:16 Yeah.
09:16 So I guess on the timeline, similar age to FastAPI, but much younger than Flask and Django,
09:24 if I'm comparing them to those.
09:25 And over here, it says on your page, you have 2 million downloads a month.
09:30 That's pretty incredible.
09:31 Yeah.
09:31 That's, that's, that's pretty crazy.
09:33 I think quite a few of those are automated.
09:35 They're from CI systems.
09:37 Yeah.
09:37 Yeah.
09:37 But I do see that, that rising quite, quite steadily.
09:41 Yeah.
09:41 I wonder how many of the CI systems just in general out there do caching at some level where it
09:47 wouldn't register.
09:48 Right.
09:48 you know, I pip install a thing I've already installed and it's a certain version.
09:52 And it'll just say using cached version.
09:53 Mm-hmm.
09:54 Mm-hmm.
09:54 Right.
09:55 Right.
09:55 versus if you create a brand new Docker image and then the next thing you do is install
10:00 your, you know, pip install your dependencies inside of your Docker.
10:03 That's a true download, right?
10:04 Because that machine is totally fresh.
10:05 Yeah.
10:06 Yeah.
10:07 So it's, it's hard to tell.
10:08 Yeah.
10:08 I don't know.
10:09 Do you have any feel for what that breakdown is?
10:11 To be honest, I'm not sure.
10:12 That site doesn't give you the breakdown.
10:15 To be honest, what I would be interested in is how many developers typed pip install rich
10:20 in that month.
10:22 You know, how many human beings played with it.
10:24 That would interest me more.
10:26 But suffice to say, quite a lot of people have used it.
10:29 It is quite a lot.
10:30 Downloading it.
10:30 Yeah.
10:31 Yeah.
10:31 I'm sure it's changed the way that you think about working on the library and whatnot.
10:35 Right.
10:36 You know, it's, oh, maybe this might, might destable it.
10:39 This might cause a problem or this might cause confusion.
10:41 It's one thing to do that for a thousand people.
10:43 It's another to do that for two million.
10:45 That's right.
10:47 Right.
10:47 It's, I am.
10:48 You're going to hear about it, I bet.
10:49 Absolutely.
10:50 I didn't follow Semver very strictly originally.
10:54 I always plan to use Semver and people are starting to use it.
10:58 And I made, I made a breaking change.
11:00 And I didn't think anyone was using this particular feature.
11:03 So I didn't increase the major version number.
11:06 And then a couple of days later, I got an issue, someone telling me off.
11:10 Quite rightly so.
11:12 Oh man.
11:13 For not warning them about a breaking feature.
11:15 So since then, I've been very, very strict.
11:17 It's a version 10.
11:19 And that's because I've made 10 changes, breaking changes to the API.
11:24 They're actually quite small.
11:25 You know, it might just be one signature and one method, but that requires a major version
11:30 change.
11:31 Right.
11:31 But at that scale, obviously, that's still going to affect it.
11:34 That people, you're going to hear about it and whatnot, right?
11:37 Exactly.
11:37 I don't want to break anyone's code.
11:39 I don't want to give them a bad day.
11:40 So I'm very strict about that kind of thing.
11:42 Yeah.
11:43 Fantastic.
11:43 And also people should pin their versions, right?
11:46 So on the flip side, they can also make sure that what they're working on is nice and stable,
11:53 right?
11:54 Yeah.
11:54 A lot of people don't.
11:55 I do search GitHub sometimes for rich and I look at their PyTummel.
11:59 What is it?
12:00 PyProjectTummel.
12:01 Yeah.
12:02 PyProjectTummel.
12:02 Yeah.
12:03 And a lot of people don't pin their rich version.
12:06 They'll just be rich and it shouldn't break too much.
12:10 And often it's a hobby project, so it's not the biggest deal.
12:13 Right.
12:13 It really depends.
12:14 Like it's one of the things I struggle with.
12:16 So I do a lot of course development, right?
12:18 And I don't necessarily want to pin people to the oldest version.
12:23 I'd rather let them have the newest stuff so it exactly matches the documentation.
12:27 If they go check it these days and stuff, if they go back, you know, six months and watch
12:30 the video or check out the demo app.
12:33 But at the same time, there's a chance of that instability.
12:35 There's always this tension, right?
12:37 And I guess it depends on what the use case of that app or that library is.
12:41 Yeah.
12:41 Yeah.
12:42 It's tricky to say.
12:43 The less critical it is for your business or your project, the more you can relax.
12:48 If it's a tutorial, maybe it doesn't matter quite so much.
12:51 But if it's critical infrastructure, then you want to pin.
12:55 Yeah.
12:57 Yeah.
12:58 For my web apps, versions are pinned.
13:00 Super strict.
13:01 Even the dependencies of the dependencies, like the transitive closure of the dependencies
13:05 are all pinned.
13:05 Yeah.
13:06 On like little demo apps and stuff.
13:07 Like it's just wide open.
13:09 So I think it depends.
13:10 All right.
13:11 So out in the audience, we have Hybotics says, Will, this looks really good to me.
13:15 I'm looking at repo now.
13:16 So not everyone has previously heard of Rich, which is awesome.
13:19 Oh, it's good to know there's a few people left.
13:25 That's right.
13:25 Yeah.
13:25 I suspect there's actually a lot of people.
13:28 So who haven't heard it before.
13:30 Again, check out the screenshots because if you think, oh, here's something that sort of
13:36 enhances terminal output that completely undersells the level of what you've pulled off here.
13:41 And that's only before we even talk about textual, right?
13:44 Let's talk about compatibility because one of the things I find with these sort of nicer
13:50 terminal output things is like, this works fantastic on POSIX systems.
13:54 Oh, but you better not be on Windows.
13:55 Or if you're a data scientist, you like Jupyter Notebooks, you can forget about it.
14:00 But if you really want to run this thing, like, so what's the story?
14:02 Like, where can I use this?
14:03 Just about everywhere.
14:04 Linux, OSX, Windows, and Jupyter.
14:07 It started out, it was Linux OSX because that is the easiest platform to develop this kind
14:13 of stuff for.
14:13 Windows is a bit of a black sheep.
14:15 It didn't quite work as is.
14:18 Windows is getting better though, right?
14:20 I mean, when it was cmd.exe, it was like, oh boy, this is really different.
14:24 But the new Windows terminal, I'm really digging it.
14:27 You know, the new PowerShell, the things like, oh, my Posh extensions.
14:30 I can feel much more at home on Windows on the terminal than I used to.
14:34 Yeah, yeah.
14:34 So the new Windows terminal is much better.
14:36 Rich doesn't have to do quite so many, doesn't have to jump so many hoops to get Windows support.
14:43 In fact, it just runs kind of as is.
14:46 It still supports the older Windows terminal, which does have a few issues.
14:51 It doesn't, it has very limited colors.
14:53 That's brave.
14:54 Yeah.
14:54 But I guess maybe you want to, right?
14:56 If you're going to give the app to somebody, you can't really package up the terminal they're going to run it in.
15:01 So you probably want to have your best possible experience on.
15:04 To be honest, most people are still going to be running cmd.exe, even if they shouldn't.
15:08 Yeah, exactly.
15:09 Yeah.
15:09 I mean, I could just tell them to install Windows terminal, but that kind of goes against the ethos of this library.
15:15 I just want it to work so that people don't have to think about what it runs on.
15:19 Yeah.
15:19 Put a lot of work initially into.
15:21 Yeah, so Linux, macOS, and Windows with good support for the new Windows terminal, very limited support for the old command prompt.
15:30 That's still pretty good.
15:31 That's still pretty good.
15:32 I think it's fantastic, actually.
15:34 If people are really passionate about their terminal and they're on Windows, they probably know about Windows terminal anyway.
15:39 So they're probably good.
15:40 That's true.
15:40 Yeah.
15:41 The one that I thought was interesting and nice is Jupyter Notebooks.
15:44 What's the support there?
15:46 So it works quite, quite well.
15:49 So I wasn't a big Jupyter user at the time.
15:52 I was obviously aware of it, but I didn't use it myself.
15:55 And people asked me for Jupyter support.
15:58 And I thought, it doesn't do that.
16:00 It just works in the terminal.
16:00 But then I looked into it.
16:01 And it wasn't too bad because I already had functionality to export terminal content to HTML.
16:08 So I could put a little wrapper around that, export it to HTML, and then insert it into Jupyter.
16:14 They've got an API which allows you to write content into a notebook.
16:18 And so I got Jupyter support up quite quickly, quite easily.
16:22 And it works quite nicely, which people appreciate.
16:25 It means that you can write code which writes to terminal mostly.
16:29 But if you do happen to run it in a Jupyter notebook, then it'll write the same thing there as well.
16:34 It just knows, it detects that it's running in the Jupyter environment.
16:38 And then it just, all right, output is not print.
16:40 Output is generate HTML.
16:41 Exactly, yeah.
16:42 And Jupyter does have support for that.
16:45 It will capture standard output and it will convert the colors and everything.
16:49 But the problem is it wrapped the lines.
16:52 So if you expanded the window, it would break any kind of neat formatting.
16:56 If you've got like a grid or a table, it would break that.
16:59 So I had to do the HTML export within Rich as well.
17:03 Yeah.
17:04 Basically, most anywhere people do Python with a UI of some sort, this works is the takeaway.
17:11 Yeah.
17:11 This portion of Talk Python to Me is brought to you by Shortcut, formerly known as Clubhouse.io.
17:18 Happy with your project management tool?
17:20 Most tools are either too simple for a growing engineering team to manage everything,
17:24 or way too complex for anyone to want to use them without constant prodding.
17:29 Shortcut is different though, because it's worse.
17:31 No, wait, no, I mean it's better.
17:33 Shortcut is project management built specifically for software teams.
17:37 It's fast, intuitive, flexible, powerful, and many other nice, positive adjectives.
17:41 Key features include team-based workflows.
17:44 Individual teams can use default workflows or customize them to match the
17:48 the way they work.
17:49 Org-wide goals and roadmaps.
17:51 The work in these workflows is automatically tied into larger company goals.
17:55 It takes one click to move from a roadmap to a team's work to individual updates and back.
18:01 Tight version control integration.
18:03 Whether you use GitHub, GitLab, or Bitbucket, Clubhouse ties directly into them,
18:07 so you can update progress from the command line.
18:10 Keyboard-friendly interface.
18:11 The rest of Shortcut is just as friendly as their power bar, allowing you to do virtually
18:16 anything without touching your mouse.
18:18 Throw that thing in the trash.
18:20 Iteration planning.
18:21 Set weekly priorities and let Shortcut run the schedule for you with accompanying burndown
18:26 charts and other reporting.
18:27 Give it a try over at talkpython.fm/shortcut.
18:32 Again, that's talkpython.fm/shortcut.
18:36 Choose shortcut because you shouldn't have to project manage your project management.
18:42 Just going back to the pip-pinning version stuff, Wayland on the livestream says pip-compile.
18:47 Pip-tools is a game changer for pin dependencies and pip-compile specifically for managing pin
18:52 dependencies.
18:53 That's what I've switched to as well.
18:54 So I just run a script, checks for all the new versions, regenerates all the pip-compiled
18:59 stuff.
18:59 And I'm really enjoying that.
19:01 I think that's fantastic.
19:01 Okay.
19:02 I've not used pip-compile.
19:03 I'll have to check that out.
19:03 All right.
19:04 You basically define a requirements file that has what you actually would have pip-typed,
19:11 pip install, and then it will generate a requirements.txt that is the transitive closure of all of
19:17 those dependencies, which are pinned.
19:18 And then you can ask any time for it to update the versions, the pinned versions of that.
19:22 Okay.
19:22 Is that like Poetry's log files?
19:25 I think it's similar.
19:27 Yeah.
19:27 I'm not 100% sure, but I think so.
19:29 All right.
19:29 So let's talk about various features here.
19:32 I think just going through, I mean, we touched on them, but let's dive into it a little bit,
19:36 maybe talk a little bit about the code you write.
19:38 Sure.
19:38 So Kim Van Wake is here to kick us off on the first one.
19:41 Try something as simple as from rich import print in your next project, and you will be
19:46 amazed.
19:46 So Will, tell us why we'll be amazed.
19:50 Like what's this alternate print?
19:52 When I first wrote this as a console class, you have to construct a class and that's got
19:57 a print method.
19:59 But I figured I could just overwrite the existing, the built-in print because it's a, it's a function
20:04 in Python three.
20:05 I can just replace it with my own version.
20:07 So that's what I've done here.
20:09 I'll give, there's a version of print that you can import from rich, which has the same
20:13 signature as a built-in print, but it supports the console markup.
20:18 So you can insert these little square brackets with a style like, here we've got bold magenta
20:24 and it'll do emojis, colon, vampire, colon.
20:28 And these styles, like the square bracket, bold magenta slash bold magenta, this is specific
20:34 to rich.
20:35 This is something that you came up with.
20:37 Yeah, that's right.
20:38 It's called, I call it console markup and the syntax is very BB code like.
20:42 I don't know if you ever used BB code.
20:44 Yeah.
20:45 It's quite simple.
20:46 It's just like a markup where the tags have square brackets.
20:50 Yeah.
20:51 I like this a lot because one of the things that I'll use a lot still is, which maybe I
20:56 need to start switching to what you're doing here, is Colorama.
20:58 But for Colorama, you'll do things like you'll import the foreground settings or styles and then
21:06 you can say foreground dot green plus the text.
21:10 Yeah.
21:11 Foreground reset to go back to normal, but you don't have the bold.
21:15 And then all of that stuff has to happen in code, right?
21:18 If I wanted to say import some text and then show it on the screen, that text could have
21:22 these styles in it, right?
21:24 That's right.
21:24 Yeah.
21:25 So you can embed it in code easier or read it from a file, et cetera.
21:29 I think it's a bit easier to read rather than doing lots of string concatenations.
21:34 And also the benefit over the Colorama approach.
21:36 Colorama is a very good bit of software.
21:38 I've relied on it for years.
21:40 But the problem is when you concatenate strings like that, you insert these ANSI codes.
21:45 Once you've built that string, you can't do anything with it really.
21:47 You can't word wrap it.
21:49 You can't format it.
21:50 So with console markup, you can do.
21:52 You can markup bits of text with color and style, et cetera.
21:55 And then you can further do operations on them like word wrap and centering text and putting
22:02 it inside the table, et cetera.
22:03 Right.
22:03 Two other things that jump out here that are interesting is you have emoji support.
22:07 So you can say colon vampire colon, which is pretty awesome.
22:12 You can technically, if the file format supports it, you could actually put a vampire emoji
22:19 in the string.
22:19 Yeah.
22:20 But it's still kind of nice that you have this sort of emoji lookup, right?
22:23 Exactly.
22:24 Because if you want to insert the Unicode character, you'd have to go and find it and then cut and
22:28 paste it.
22:29 Yeah.
22:29 You can just do colon.
22:30 You can set that into console markup, just colon vampire colon or colon smiley colon.
22:36 I think there's a couple of thousand emojis you can use there now.
22:38 Fantastic.
22:39 Then another thing that jumps out is you're printing hello, bold magenta world.
22:45 So that's the word world, bold and magenta.
22:48 And then the vampire.
22:49 But then you're also printing out a dictionary.
22:51 And the dictionary is like pretty printed, but also syntax highlighted.
22:57 So if you print a container, like a dictionary, a list, or like an atomic Python type, it'll
23:04 run the pretty printer over it.
23:05 So it will format it in kind of the style that people like.
23:09 In code, you'd probably format.
23:11 This is how black would format it.
23:13 So it looks much the same.
23:15 Then it runs the syntax highlighting over it.
23:18 There's a few regular expressions.
23:19 So in which you can say anything between two quotes is a string and therefore it's green.
23:25 Anything in angle of brackets is a tag-like thing.
23:29 So I'll bold the brackets and change the tag name to bright red or whatever it is.
23:35 And so that the output you get is quite readable and looks like something that came out of VS Code or your editor.
23:42 Yeah.
23:43 The more I look at this, the more I think maybe just every project, I'm going to follow Kim's advice and just from rich import print.
23:49 Because why not?
23:50 This looks, it has all this cool auto formatting.
23:53 Does it look actually at the type that it's printing to make any determination?
23:58 Or does it just look and see if it's source code and then try to format it?
24:01 It looks at the type.
24:03 Like if it gets a dictionary or it gets an object versus getting it like a true string.
24:07 It'll do both.
24:08 It'll syntax highlight a string.
24:10 But if it's a container, if it knows that the type, it'll do some syntax highlighting there.
24:15 There's also a simple protocol you can add to your own objects if you want them pretty printed and formatted.
24:23 Oh, okay.
24:23 But not dunder stir, dunder repper, but something else.
24:27 Dunder rich.
24:28 It is dunder rich repper.
24:30 Right.
24:30 You can specify the arguments and parameters and the indentation.
24:36 It'll render something that's very much like a pretty printed dict.
24:39 That sounds like something that would be fantastic to add to some intermediate library that people use.
24:44 So I, sure, I could create a class and add it to mine.
24:47 But so often what I want to do is print out a Mongo Engine model or a SQLAlchemy model or a Pydantic model.
24:53 Yeah.
24:53 Pydantic could add that.
24:54 Or, you know what I mean?
24:55 Like these like intermediate SQLAlchemy could add something like that.
24:58 Oh, this is how you describe.
25:00 Like this one has an index and whatnot.
25:02 I think that'd be fantastic.
25:03 Yeah.
25:03 So I've added to Atters.
25:05 So it'll pretty print objects from the Atters library.
25:08 I have a PR for Pydantic as well.
25:11 So hopefully in the future, you print a Pydantic object and it will format it quite similar to the built-in data structures.
25:18 Yeah.
25:18 Okay.
25:19 Fantastic.
25:19 I love it.
25:20 Before we move on to this, I do want to talk about some other things because we're just scratching the surface here.
25:25 But one of the things that I think has both impressed me and, you know, Brian and I over on Python Bytes on our podcast we do there,
25:31 we've been continuously impressed at how fast you're adding new features and still kind of keeping the ethos of this library together.
25:40 So how, maybe give people a little hint on just the velocity here.
25:44 Like how's that work?
25:44 Well, I'm not convinced that it's been that fast.
25:47 I mean, bear in mind Rich is...
25:49 It felt like a lot of work.
25:50 It didn't feel that fast.
25:51 When I add new stuff to Rich, I'm not starting from scratch.
25:55 There's several layers which are already built and well tested.
26:00 The bit that I add might not be as large as it, maybe it looks.
26:04 I see.
26:05 So you've already got a lot of structure and architecture that makes adding a new feature...
26:09 Yeah.
26:10 ...from scratch sort of thing, right?
26:11 So a good design basically.
26:12 I hope so, yeah.
26:13 And it seems to be working quite well because, you know, I did build a core feature set and then I added some things to it.
26:20 And admittedly, those things came quite fast because it wasn't that hard to implement.
26:24 And I've got to a point now where Rich is quite large.
26:29 I'd be resistant to adding any more stuff to it unless it is very useful for like a broad selection of users.
26:36 Sure.
26:36 Do you have a sense of how many lines of code it is?
26:38 I know you don't mean large in that sense.
26:40 You mean large in sort of feature set.
26:41 But do you have a sense of how many lines of code?
26:43 You know what?
26:43 I've never checked.
26:44 I couldn't guess.
26:46 By the time we're done with this recording, someone out in the audience will have like already downloaded and checked for us.
26:52 Who knows?
26:53 Probably.
26:53 All right.
26:53 So the next thing let's talk about is the REPL.
26:56 So I can create a REPL redevelop print loop by typing the word Python on the terminal.
27:02 And that opens it up.
27:04 But it looks just...
27:05 It's probably the least possibly good experiences you can have in Python, right?
27:09 There's no color.
27:11 There's no feedback on sort of what's happening, right?
27:14 But then I can say from rich import pretty, pretty.install.
27:18 And then all of a sudden, basically the output of the REPL, like if I'd set a variable name, it'll print it out.
27:26 Like that becomes rich printed, right?
27:28 That's right.
27:30 Yeah.
27:30 Yeah.
27:30 So yeah, you call pretty.install.
27:33 And then everything you put into the...
27:36 After the prompt will be pretty printed.
27:38 So previously, if you print a dict without rich, it'll just smash it onto a few lines.
27:45 It's quite hard to visually parse.
27:47 It's all one line except for the word wrapping, which doesn't even break on words.
27:51 And there's zero color, right?
27:53 Yeah.
27:54 Exactly.
27:55 So it's quite difficult to read.
27:57 I'm quite a visual person, so I always had difficulty with this.
28:00 If it was more than two lines, it'd be quite difficult for me to figure out where the keys and the values are.
28:05 But if you do it with rich, it'll pretty print it onto lines and it'll indent it like you would code and then it'll highlight it.
28:12 So it makes things just much more readable.
28:14 Yeah.
28:14 A lot of people will put it in their startup file, so they just get this ripple by default.
28:18 Oh, interesting.
28:19 Yeah, that's a good idea.
28:20 Have you tried this on the more advanced repls like PT Python or BT Python or those where you kind of get an Emacs E or Vim experience?
28:31 I haven't.
28:31 No, I've tried it on IPython and it works quite nicely on IPython, but I haven't tried it on other repls.
28:37 Yeah, it probably works on PT Python, but I haven't tried it.
28:40 Cool.
28:40 All right.
28:41 Now, another thing that you can do a lot with is sort of taking it up to the next level is the console.
28:47 Tell us about this.
28:48 Yeah, so the console class gives you more kind of advanced features.
28:53 There's more options, more things to specify.
28:56 Typically, you'd have a single console per project.
28:59 You'd keep it in your top level object or as a global.
29:03 It has a print method and there's also some other methods like there's a log method and there's a whole bunch of features you can do when you construct the console.
29:12 Things like exporting the output to HTML.
29:16 Okay.
29:16 Nice.
29:17 That's fantastic.
29:18 Yeah.
29:18 So one of the things you can do with the console, for example, is you can set a style on console.print and set some styles.
29:25 And then it'll come out in that style as opposed to embedding this console markup into the text itself, right?
29:31 Yeah.
29:32 So sometimes you might not want the console markup, especially if there's going to be square brackets in the output.
29:39 You don't want them to be confused with.
29:40 Right.
29:41 Or even if you're receiving a string and you just need to put it on the screen, but you haven't generated the string or it was generated by some other part of the app.
29:51 Like here's a message I need to log this that I got.
29:53 Exactly.
29:53 You don't want to parse the string to try to put text into it or more text, right?
29:57 Yeah.
29:57 Exactly.
29:58 So you can disable the highlighting and you can still set a style globally for that string if you want it in red or cyan, whatever.
30:05 You can still get that, but you can disable the console markup.
30:09 Nice.
30:09 And then we have the inspect, rich inspect.
30:13 What is this one?
30:14 This is my favorite function in rich and it came quite late.
30:19 But what it does is you call it with any object and it'll inspect the object and it'll pull out doc strings and it'll pull out methods.
30:30 And then it'll render it in quite a nice little table that's quite easy to read.
30:35 And I find this terrific for exploring APIs.
30:39 Sometimes it's better than documentation.
30:42 You know, if you get an object back from an API, you don't quite know what methods it supports.
30:46 You just call rich.inspect.
30:48 I could have typed something like dir, my, you know, print dir, my object.
30:53 And I get a list of dictionary objects which are representing, you know, fields and methods and whatnot.
31:01 Exactly.
31:01 But they're all jammed together.
31:02 There's no like help.
31:04 This is fantastic.
31:05 So it's like almost a table version of that with one line of help next to it, right?
31:11 Yeah.
31:11 So it does the same kind of thing as dir or help.
31:14 But way, way nicer, yeah.
31:16 It makes it easier, easier to read.
31:17 There's also two things.
31:18 I see there's a block of stuff that has, it's like a list of, I guess those are field names.
31:24 And then it has the methods.
31:26 It's sort of called out separately as well.
31:28 So you're like, these are the fields or properties or these are the fields.
31:31 And then here's the probably methods and properties, right?
31:33 That's right.
31:33 Yeah.
31:34 So it basically shows you the signature of all the methods and the first line of the doc string.
31:40 There's an option to show you the full details.
31:42 But I find just that abbreviated information is generally as much as I need.
31:47 Oh, this is fantastic.
31:48 So it says things like copy equals def, copy, bracket, bracket.
31:52 Would it say async def if it was an async method?
31:55 Or what's the alternative of def there?
31:58 Is it just to show it's a method?
31:59 That's just to show it's a method.
32:01 That's a good point about async.
32:02 I don't think it does do async def.
32:04 And that's a good idea.
32:06 It'd be pretty dope to throw in an async def or maybe a property if it's a getter method, right?
32:11 You're right.
32:11 Yeah.
32:12 I think they probably should do that.
32:13 They should inspect the method and see whether it's async and then emphasize that.
32:17 Yeah.
32:18 It's a good idea.
32:18 Yeah, sure.
32:19 We'll open a PR on that podcast here.
32:21 No problem.
32:22 All right.
32:23 So those are ones that you've got like graphics calling them out as some of the really main
32:28 things.
32:28 There's so much happening here.
32:30 That's that's amazing.
32:31 But like Waylon out in the live stream points out like mention rich tracebacks.
32:36 They're so good.
32:37 I have my ipython automatically start up with that.
32:40 And yeah, you've got a whole section down here under the library of things like logging,
32:45 log handlers, progress bars, status, tree views, like crazy.
32:50 You have tree views in the terminal that can expand and collapse with the mouse.
32:54 You know, there's there's more going on here than just the stuff we've touched on.
32:57 Right.
32:57 There's a bunch of cool features.
32:58 There's a lot going on.
32:59 Yeah.
33:00 Well, Rich will render the tree view.
33:02 It's textual, which provides the collapsing and navigation features.
33:06 Yeah.
33:07 Ah, got it.
33:07 Got it.
33:08 Got it.
33:08 Okay.
33:08 So we'll get to the interactive bits.
33:10 But yeah, so I can still draw a tree view even with like little your example here.
33:14 You've got emoji icons for say folders and files.
33:17 And then even in the file, you've got an embedded syntax highlighted bit of code that comes out
33:22 of one of the files and a markdown with some of the markdown rendered as a rich markdown.
33:27 Yeah.
33:27 Just a markdown.
33:28 Like not, not rich the library, but like just colorized and formatted.
33:31 Yeah.
33:32 So it goes back to the composability of rich, rich objects.
33:36 I call them renderables, but you can use them in various contexts.
33:40 So in here, you can set a renderable per node on the tree.
33:43 So you can like do what we've done here, add a table next to a tree item or some syntax highlighting
33:50 or render some markdown.
33:51 It doesn't really matter to rich what you ask it to render.
33:55 You can just do it in various contexts.
33:58 Yeah.
33:58 Very cool.
33:58 Okay.
33:59 So we've got the tree, which is amazing.
34:00 Let's, you know, since Waylon mentioned it, let's talk tracebacks real quick.
34:03 I mean, one of the things that really is tricky with the tracebacks is, you know, a lot of
34:10 times you've got to go to like one end of them to see sort of the error.
34:13 And then like, there's no color.
34:15 There's just a lot of stuff dropping in there.
34:18 Maybe sometimes it'll show the variable values, but they're not really got to kind of pull
34:22 them out.
34:23 Right.
34:23 Things like that.
34:24 And what you get here is, is ridiculous.
34:27 First of all, what do I do to make this happen with the beautiful tracebacks?
34:30 You can do from rich import traceback, traceback.install.
34:34 Oh, good.
34:34 Yeah.
34:35 From then on, if you don't, if you don't handle an exception, it'll be printed with rich
34:39 or you can explicitly.
34:40 All right.
34:41 There's the second thing I got.
34:42 I just put on all my apps.
34:43 Yeah.
34:44 It's a piece of cake to add.
34:46 So yeah, it's easy to do.
34:47 Yeah.
34:47 So tell me what people who are not seeing this necessarily on the screen, like what is this
34:51 alternative traceback style look like here?
34:54 Okay.
34:54 So it actually follows much the same format as a regular Python traceback.
34:59 It's just underneath the file, you'll see some syntax highlighted code showing you that
35:05 the line where the exception happened for each frame and underneath each block of code,
35:11 it'll show you the locals at that point in the frame.
35:14 So you can see the local variables.
35:16 Right.
35:16 And these are called out in a nice table with a nice formatting that we've already talked
35:20 about.
35:20 So kind of as if you had done print, you know, from rich import print and then printed out
35:25 the locals into a table.
35:26 Yeah.
35:26 And it's all, it's all pretty printed.
35:28 So it's quite easy to read.
35:29 I find with regular Python tracebacks is it, it takes quite a bit of skill to read them.
35:35 Yeah.
35:36 Particularly for beginners and even for intermediates.
35:38 You've got to sit down and analyze the tracebacks, but I'm hoping, but this, this just kind of
35:44 presents the information in a more readable way and you can like get more of the context
35:48 of the error.
35:49 Yeah.
35:49 I think this is fantastic.
35:50 This definitely super interesting.
35:52 I guess one more thing here to really dive into, maybe two, two.
35:57 I think the log handler is really nice.
35:59 People should check that out, but maybe tables.
36:01 I know it's, it doesn't sound as appealing and amazing as necessarily as what we've been
36:06 talking about.
36:07 But if I want to have a nice formatted table in a text output, I basically just don't do
36:13 that.
36:13 I'm like, that is way too much work.
36:15 Yeah.
36:15 Yeah.
36:16 to worry about this.
36:17 Right.
36:18 But with using rich here, you can have almost HTML level formatting styles, you know, borders
36:25 on border off, just header content divider, like alternating rows.
36:29 Like I said, a right align, left align.
36:31 There's all sorts of amazing stuff here.
36:33 Tell us about the tables.
36:34 I didn't realize how hard tables would be to implement when I started it or I might
36:38 not have.
36:39 You might not have done it, huh?
36:41 Tables are quite complicated because you've got to calculate optimal column widths and that
36:47 gets really complicated when you've got text, which can, can wrap and other like renderables
36:53 that can go in those cells.
36:54 It does work quite nicely now and it can handle just about anything you can throw at it and
37:00 it will scale the table nicely and elegantly if, if it doesn't fit into the, you know,
37:06 the width of the terminal.
37:07 And it's also quite a good layout tool.
37:09 You can switch the borders off entirely and then use it to lay out other things.
37:15 You know, one thing that comes to mind right away is I think of some of the nice progress
37:19 bar type things for the terminal, like TQDM and stuff.
37:22 And they're great, but I'm always like the stuff on the right, it'll have like what it's
37:26 doing and then it'll have a progress bar and then it'll have maybe, you know, how fast
37:30 is it operating or how much time has it got to go or something.
37:32 And those are always kind of like doing like a little pulsing, like, cause the thing on
37:35 the right is always changing and they don't never quite line up.
37:38 You could just, you could do that here, but have a table and put the progress bar and one
37:42 of the center fill bits, right?
37:44 Yeah.
37:44 So you can do lots of things regarding alignment to fit everything together.
37:48 And like you said, stop that effect where bits of content will flicker because they're
37:53 using less characters because it goes from a hundred and into 99 and then.
37:56 Yeah, exactly.
37:56 Yeah.
37:57 Yeah.
37:57 It's a very good layout tool and also just a good way of presenting tabular information,
38:02 which is kind of what it was designed for.
38:04 Yeah.
38:04 It is a table, right?
38:05 All right.
38:07 So last one, I've got some content and probably a most common way that it's in a lightweight
38:14 format, but you want to turn it into something full featured in terms of text is Markdown,
38:19 right?
38:19 So for example, the Python bytes website is almost like entire, like the vast majority
38:23 of the content there is Markdown, talk by on training, like all the stuff we've got, the
38:27 CMS we built in the back end, it's all Markdown.
38:29 Rich has Markdown support too, right?
38:31 That's right.
38:31 Yeah.
38:31 There's a Markdown class.
38:33 And basically I took common Mark library, which parses the Markdown.
38:37 Okay.
38:37 I substituted the bits which were generating HTML with something which generates rich output.
38:43 And it turns out there's a reasonable job of things like headers and does the style just
38:49 fine.
38:49 And there's also syntax highlighting.
38:51 It'll actually call out to the syntax highlighting code.
38:54 So if you've got a Python code block, it'll actually highlight that Python code block.
39:00 Yeah.
39:00 You have support for inline code with the backtick thing, backtick.
39:03 Yeah.
39:03 And the blocks of code, which are the triple backslashes or triple backticks or four spaces
39:09 or whatever.
39:10 Yeah.
39:10 So it supports much of the basic common Mark syntax and does a reasonable job of rendering.
39:16 It won't look quite as good as a web browser, but I find it quite readable.
39:20 But it's in the terminal and I didn't have to do anything to get it there, right?
39:24 So that's pretty fantastic.
39:26 Yeah.
39:27 Really, really nice.
39:28 All right.
39:29 So I think this is probably as much of the details of rich we want to dive into in terms
39:35 of like the feature set and stuff, but there's still more to go.
39:38 There's a lot to love out of this library, which is great.
39:41 Maybe just give us a sense of the internals.
39:44 Like, how did you make this happen?
39:45 How do you make it work?
39:46 Is this curses to the nth degree or what's happening?
39:50 There's no curses.
39:51 There's a layer, which what makes most of it work, where I render everything into, and that's
39:57 a list of what I call segments.
39:59 The segment consists of a bit of text plus a style.
40:02 And the thing about having that intermediate layer before you actually render it to the
40:06 terminal is you can manipulate it afterwards.
40:10 So I can apply color and style and then do word wrapping and then I can render it onto the terminal.
40:17 So everything is built on that and a protocol.
40:22 So objects can add a couple of methods.
40:24 They can add a Dunder rich or a Dunder rich console method.
40:28 Then they can themselves be renderable.
40:31 So you can print your own custom objects and that will use that intermediate layer of segments
40:35 to render everything onto the terminal.
40:38 Nice.
40:38 Okay.
40:38 Yeah.
40:39 It sounds like a really good separation.
40:40 And you could probably also, if you need to do something specific for one platform versus
40:44 another, that layer, you can make a decision on how to do that without.
40:48 That's exactly it.
40:49 Yeah.
40:49 Having to put it all over the place, right?
40:52 Yeah.
40:52 So I render onto the segments and that's platform independent.
40:55 But there's another bit of code which will convert those segments onto the appropriate format
41:01 of the platform.
41:02 And the platform might be the number of colors that's supported by terminals because some will
41:07 support 16.7 million colors.
41:09 Some will support 256 and then some will support 16.
41:13 Yeah.
41:13 But because of that intermediate layer, I can make sure that no matter what you write, we'll
41:18 work on the terminal on the given platform.
41:21 Yeah.
41:21 Fantastic.
41:22 One of the things I do want to circle back to is this idea of you're taking a year off
41:27 to continue to work on this project, to grow it even further and already has and also do
41:32 other things in this general realm.
41:34 And so there's a couple of ways which people can support you, right?
41:38 If you're a large bank that depends on this kind of stuff, one of the good options is Tidelift,
41:44 right?
41:45 People can get a Tidelift subscription for Rich and that gives, what do they get with that?
41:49 So I don't think you get a subscription for Rich per se, but you can get a Tidelift subscription.
41:54 I see.
41:54 And that means that that money is divided amongst all the open source projects that you use that
42:00 are signed up to Tidelift.
42:02 In return, you get more responsive developers and developers which will handle security issues,
42:10 et cetera.
42:11 It takes the risk of open source code for big organizations because there is a little bit of
42:16 risk in that if you're relying on someone's hobby project, are they going to be around in
42:21 six months to your time?
42:22 Yeah.
42:23 So Tidelift ensures that developers will be around in the future to support your code
42:29 going forward.
42:30 Absolutely.
42:30 The other one is right up at the top here.
42:33 I could click sponsor and then come over here.
42:36 Also, that pulls up a link to the external funding for Tidelift.
42:39 But I could hit sponsor.
42:41 Do you have like plans or anything like that?
42:43 I know some projects have, you know, there's like a gold sponsor and here's just a sort
42:49 of keep it going sponsor.
42:50 Yeah.
42:51 Do you have anything like that or is it just, you know, what people want?
42:53 GitHub sponsors supports tiers.
42:55 So depending on how much you want to sponsor, I will help you with your projects.
43:00 I'm always happy to help people actually open source projects.
43:03 Always happy to do that.
43:05 But for the larger tiers, I will do code reviews or I will help you with your project on a more
43:12 more formal basis.
43:13 I might even write code for you.
43:15 It's up to what you want to sponsor.
43:17 If you just want to say thanks, that's very much appreciated.
43:19 You know, if I've solved, if I fixed a bug for you and just want to say thanks, then that's
43:24 fantastic.
43:24 But if you're a company which is benefiting from the work that I do or the work that other
43:29 open source developers do, you can sponsor a bit more to ensure that it keeps the work
43:34 going.
43:34 Right on.
43:35 Yeah.
43:35 And I encourage people if they're depending heavily upon this, you know, help you keep going
43:39 strong, especially as you're transitioning to just working on this.
43:43 So yeah.
43:44 Also, notice someone's forked it since we even pulled it up here.
43:47 How cool.
43:48 So the other, the next step that maybe you would, would take this, you talked about not
43:54 wanting to add too many insane features to rich to keep growing that, right?
43:58 Keep it focused on target is you also have this project called textual.
44:03 Textual is a TUI.
44:04 We've all heard of a GUI, but a TUI is a text user interface instead of a graphical user
44:10 interface, right?
44:10 Yeah.
44:10 I think it's a bit of a misnomer.
44:12 I mean, because the interface is constructed with text, granted, but it's still a graphical
44:16 thing you're looking at.
44:17 Yeah.
44:17 Yeah.
44:17 I think of it as a GUI, but with kind of like a fairly retro aesthetic.
44:22 Yeah.
44:22 It does have a bit of a retro aesthetic.
44:25 I would say maybe if you built something with like Colorama or something, that would be maybe
44:28 more TUI-esque, right?
44:30 Where there's, where you look at what you build with textual, it's got scroll bars, it's got
44:35 banners, it's got icons.
44:37 It's, it's closer by far.
44:41 Looks a bit more, a bit more graphical.
44:43 Yeah.
44:43 Yeah.
44:44 So tell us about textual and why not just more features on Rich.
44:47 Rich has some kind of dynamic features.
44:50 There are progress bars and they're updating live dashboards.
44:55 And I've been asked quite, quite a lot if I could add keyboard support and mouse support.
45:01 And I've resisted for quite a while because I want to keep the focus of Rich onto just generating
45:08 mostly static output.
45:09 But then, then I saw a project called GH top, which is kind of like H top, but it would take
45:16 information from the GitHub API and it would show you like real-time events.
45:21 And they used, oh, there we go.
45:23 And they used Rich for that.
45:25 And when I saw that, I realized, oh, I've got to do this.
45:28 There's a lot of potential there.
45:30 And I put it off a little bit, but then, then I started on it and I kind of realized that,
45:36 yeah, there's quite a lot you can do with a terminal these days.
45:39 This is one of the things that blew my mind.
45:40 Maybe, you know, give us a sense of, I'm trying to pull a particular picture.
45:45 Maybe this is just one I could sort of leave on the screen.
45:47 But one of the things I remember from my early days of GUI type development is how do you
45:54 resize stuff on the screen, right?
45:55 So I want to put something where like the main window is here, but then I want the status
46:00 bar thing, but I want it to stick to the bottom.
46:03 And then I want some other stuff on the left.
46:04 And it sounds like that would be pretty tricky to just dynamically try to generate with Rich.
46:08 But with Textual, you can say like this thing docks to the left and this docks to the bottom.
46:13 And here, this fills the main content.
46:14 And then those bits in the middle, are those basically rendered either more of these containers
46:19 and these widgets?
46:20 Or is that Rich directly?
46:22 Or give people a sense of like what they build with this.
46:25 So Rich does the rendering, which is responsible for getting stuff onto the screen, but Textual
46:31 handles the dynamic stuff.
46:33 At the most atomic layer, there's something called a widget.
46:37 And a widget is almost like a software component in itself.
46:41 It's built on AsyncIO.
46:43 So each widget has its own AsyncIO task and it's constantly processing events.
46:48 And Textual will change the size of that and change the layout in response to resizing the terminal.
46:55 And you can tell it how the widgets fit together within the given dimensions of the terminal.
47:02 Right.
47:03 So you've got like the layout elements that handle docking and whatnot.
47:07 Yeah.
47:08 Yeah.
47:08 Yeah.
47:08 Very cool.
47:09 So one of the examples you have on the Textual readme is building one of these widgets.
47:14 So you just create a class that drives from widget.
47:16 Here you have a hover example and it has a way to render itself.
47:21 And then it very much like traditional, you know, I'm thinking of building like VB6 apps
47:27 or Windows Forms apps, like these traditional ones where you have drag and drop widgets.
47:31 They have these events, right?
47:32 And one of the events here, you wouldn't think of this as a terminal thing.
47:37 You've got like, you know, on mouse, you know, on enter, on leave and, you know, mouse over
47:43 and things like that.
47:45 Right.
47:45 Like those are regular UI types of interactions that you would not expect to see in a text-based
47:52 app.
47:53 Right.
47:53 Yeah.
47:53 That's fantastic.
47:54 It's based partially on my knowledge of writing desktop applications, which is quite old now.
48:00 Oh yeah.
48:00 What did you write them in?
48:01 WX widgets mostly.
48:03 Yeah.
48:03 It's a C++ framework.
48:05 I think it's got a Python layer.
48:07 Yeah.
48:08 Yeah.
48:08 Yeah.
48:08 There's WX Python.
48:09 I think that might be the next, the Python wrapper.
48:13 That's right.
48:13 Yeah.
48:13 But in the last 10 years, I haven't done any desktop applications.
48:16 I've been working mostly in the web.
48:18 So it's mostly influenced by web development with modern frameworks, particularly Vue, which
48:24 I've used a few times.
48:25 Vue's nice.
48:26 Yeah.
48:26 Vue's very nice.
48:27 So I'm trying to replicate some of the best features, I think, of you into the terminal.
48:32 I'm surprised how well some of these features translate.
48:35 Yeah.
48:36 This is incredible.
48:37 It really does build these interactive things.
48:39 Now, another thing to talk about is how do you control the look and feel, right?
48:43 Like the way you might do it in Rich is you might have one of these console markups or markdown,
48:48 or you could use a console and set a style.
48:50 But if you're inspired by the web, you know, like dot main container hash thing I want to
48:58 style, right?
48:59 Like it's some sort of CSS selector, right?
49:01 Yeah.
49:01 So you've read my mind.
49:02 I've been last few days working on CSS.
49:06 Okay.
49:06 It's going to work very much like...
49:09 Is it actual CSS or CSS-like stuff?
49:11 Like what do you have in mind here?
49:12 It's probably not actual CSS.
49:14 A lot of the stuff just wouldn't apply to terminal.
49:16 Yeah, it makes sense.
49:17 Sure.
49:17 But essentially, it's the selectors.
49:19 So I will have selectors where you can select an ID and then a child with a class name,
49:26 et cetera.
49:26 I mean, that's basically what I was thinking when I was saying real CSS, right?
49:29 Like is it...
49:30 Right.
49:30 Or will I say like hash container dot children type and I would write that or is it like...
49:37 It's exactly like that, but it's...
49:38 Exactly like that.
49:39 Yeah.
49:39 Oh, beautiful.
49:39 And the only thing that differs is the...
49:41 I don't know what you call them.
49:42 The bit that goes inside the curly brackets, the actual rules, they will be different.
49:46 Sure.
49:46 Yeah, yeah.
49:47 Yeah.
49:47 They render different things, but very much like CSS.
49:51 If you come from the web, you see this, you'd be very much at home.
49:54 Nice.
49:54 I could probably even use less and transpile that down to CSS and put the odds...
50:00 Yeah, maybe.
50:00 Who knows?
50:01 Yeah, maybe.
50:02 I was thinking, should I just do CSS, which is hard enough in itself?
50:06 Or should I try to implement less or SAS or one of these things?
50:10 Well, I'm going to try CSS first of all.
50:13 If you get it working with CSS, then you probably can get the less compiler to generate the right CSS out of it somehow.
50:19 Yeah, maybe.
50:20 But actually, one of the worst things I think of JavaScript and web app development is all those pre-processors.
50:26 I know.
50:27 I'm 100% with you.
50:29 Yeah.
50:29 When you've got to run all these tasks and all these CLI things just to get it so you can start using your app, it's like, there's something kind of broken about this.
50:38 Can I just include a file here and go?
50:41 It's gotten so complicated that JavaScript is one of the more complicated ways to write code rather than one of the simplest, I think.
50:47 Exactly.
50:48 Yeah.
50:49 There was a time where front-end development was seen as kind of like the baby brother of real development.
50:56 You and your QJ query.
50:58 That's not true anymore.
51:00 I don't think it's been true for a while.
51:02 I think front-end development requires just the same type of thinking as back-ends.
51:08 You've got to organize all these different processes together and mental models.
51:13 And it's actually more complicated because there's so much going on.
51:17 There's so many little things you've got to remember.
51:19 Yeah.
51:20 You're taking so much of modern software development and squishing it down to this narrow little bit that is like run it in JavaScript on the browser.
51:28 Yeah.
51:29 It's kind of got to fit into this historically what used to be like a narrow-focused environment, and now it's definitely not.
51:34 Yeah.
51:35 So I'm trying to take what I think are the good things about front-end development and apply them to the terminal and hopefully leave out the things which I don't like so much.
51:46 Yeah.
51:46 That sounds great.
51:48 So maybe for this one, I think what people should probably do is they should check out the examples, right?
51:54 The examples from Textual.
51:55 They can clone the repo and just run these, and it's super easy.
51:59 There's also a way to see them, I guess, on the developer video log here.
52:02 Are these you doing these videos here?
52:04 That's me, yeah.
52:05 It's just using a short demo of each.
52:08 Nice.
52:08 This is my ad apparently I'm getting.
52:10 No.
52:10 All right.
52:11 We'll not play that.
52:12 Go YouTube.
52:15 All right.
52:15 So, yeah, but people can go and check these out because I think seeing it in action is really what you need to appreciate Textual.
52:22 And it can demonstrate the features which Textual can do, which I don't see in other 2E frameworks.
52:31 I'm thinking particularly of animation.
52:33 Yeah.
52:33 I was just thinking like the CSS easing functions and those types of animations.
52:37 Yeah.
52:38 Yeah.
52:38 I was surprised how well that worked.
52:41 I was animating things at 60 frames a second, and it can go up to 120 frames per second.
52:46 Terminals these days, they're built on the same technology as video games.
52:50 They use hardware accelerated graphics under the hood, so they can actually render terminal updates very, very quickly.
52:56 I don't think people have taken advantage of that.
52:59 How long until someone re-implements Doom on Rich or on Textual?
53:04 I'm sure it's possible.
53:05 You could render it and then, you know, render it onto text.
53:08 I don't know how you do it, but various ways of rendering images.
53:11 So, in theory, you could put Doom in the middle of a Textual application.
53:15 I would say start with really, really small fonts in a big terminal window so you get higher resolution.
53:20 Yeah.
53:20 Yeah.
53:21 But, yeah, you've got the color.
53:22 You've got the emojis.
53:23 I bet you could make it happen.
53:24 Awesome.
53:25 All right.
53:25 Well, we're getting pretty short on time here, Will.
53:28 Anything else you want to sort of throw in about Textual or even Rich before we wrap it up?
53:34 Just to say that I like getting feedback and input.
53:38 So, if you have any suggestions, jump onto Textual discussion board.
53:42 Or if you find any bugs, let me know.
53:44 Or connect with me on Twitter and I'm happy to talk about these things.
53:48 Yeah.
53:48 Fantastic.
53:49 Also, I want to give a shout out to one of your other projects real quick.
53:52 Great.
53:53 Yeah.
53:53 So, this is PAL file system.
53:55 I've been working on that for well over 10 years now.
53:57 I've handed it over to some very talented developers.
54:00 But, essentially, the idea is that there's an abstraction there for file systems.
54:05 So, the same code can write to your disk drive or an FTP server or a zip file.
54:13 And it just all works exactly the same way.
54:15 Nice.
54:15 Do you have, like, cloud format support, like S3 and things like that?
54:19 Yeah.
54:19 Exactly.
54:19 Yeah.
54:20 So, there's an S3 version and there's a Google Cloud version and there's dozens of other implementations.
54:26 Any database stuff?
54:28 Can I, like, treat a table as a directory or something like that?
54:31 I wouldn't be surprised if there is.
54:33 I don't know of any off the top of my head.
54:35 But some people have done some quite creative things where they've made something which is not a file system look like a file system.
54:42 Oh, look at this.
54:42 Dropbox FS.
54:44 Dropbox as a file system.
54:46 Okay.
54:47 That's pretty amazing.
54:49 Okay.
54:49 Here's the index of file systems.
54:50 Let's see.
54:51 We've got application data, FTP in memory.
54:54 Oh, that's pretty slick.
54:55 So, you can read and write files, like, say, for tests and not care.
54:58 Or temp files, maybe.
54:59 Tem files would be fantastic, right?
55:01 Yeah.
55:01 So, you can use temp files and, like you said, for testing.
55:04 So, you can write it into memory without bothering to write it onto your hard drive.
55:08 Okay.
55:08 The multi-file system.
55:10 So, you could multiplex reads and writes.
55:12 That's pretty killer.
55:13 Yeah.
55:13 That's more, I remember correctly, you can layer several file systems.
55:18 So, you could have one to write and then several to read.
55:22 And depending on where the file is, it'll just make it appear like a single file system.
55:26 Yeah.
55:27 A lot of neat stuff here.
55:27 So, you know, people, they got a lot of file reading and writing to do.
55:30 They can check that out.
55:31 Also, I want to give a quick shout out.
55:33 I saw Paul Everett on the live stream out there.
55:35 So, Paul and you dove inside in a more visual way into textual, right?
55:41 So, I'll link to a live stream you all did over there together.
55:44 Great.
55:44 Cool.
55:44 Yeah, that was fun.
55:45 Yeah.
55:46 Awesome.
55:47 All right.
55:47 Well, I think that pretty much wraps it up.
55:50 So, I'll give you the final two questions before we get out of here, though.
55:54 So, Will, if you're going to write some Python code, what editor do you use these days?
55:59 I use VS Code.
56:00 I've used that for quite a while.
56:02 Quite happy with it.
56:03 But I do try other editors from time to time.
56:06 Nice.
56:06 And then, in addition to pip install rich and pip install textual, any other packages out
56:12 there you want to give a shout out to that you think you use some eyeballs and some attention?
56:15 Anything that's impressed you lately?
56:16 I'm drawing a blank.
56:17 There's so many.
56:18 It is hard to choose, isn't it?
56:20 There's a project I saw.
56:21 Can I mention one that uses rich?
56:23 It was quite cool.
56:23 Of course.
56:24 Yeah, absolutely.
56:24 It's called Object Explorer.
56:27 It's a terminal user interface, but it's not.
56:29 I think it's OBJ Explorer, which is quite nice.
56:33 You could create an, you explore a Python object and you can navigate into it in a visual way
56:39 and it will show you the attributes, et cetera.
56:41 Oh, fantastic.
56:42 Yeah, that sounds really fun.
56:43 Is this for like in-memory Python objects or database objects or what is it?
56:47 Oh, in-memory Python objects.
56:49 So, I think it's like a debugging tool.
56:51 It's kind of like, it's a bit like rich.inspect, but it's more visual.
56:54 Okay.
56:55 Yeah, fantastic.
56:56 We'll have to link to that one.
56:57 All right, Will.
56:58 So, thank you for being here.
57:00 This has been really great.
57:01 Congratulations on both of these projects and all the momentum you've gotten.
57:07 Thank you.
57:07 Final call to action.
57:08 People want to check out Rich or Textual.
57:11 Maybe want to support you.
57:12 Whatever else you want to give a final shout out for or call to action before we call it a show.
57:17 Just connect with me on Twitter.
57:19 My handle is at Will McGuggan.
57:21 Say hi.
57:22 I'm happy to talk on Twitter.
57:24 Right on.
57:25 Be sure to put the link in the show notes.
57:27 Thanks for being here, Will.
57:28 Thank you.
57:28 It's been great.
57:29 Bye.
57:29 Bye-bye.
57:30 This has been another episode of Talk Python to Me.
57:33 Our guest on this episode was Will McGuggan.
57:36 It's been brought to you by Shortcut.
57:38 And us over at Talk Python Training.
57:40 And the transcripts are brought to you by Assembly AI.
57:42 Choose Shortcut, formerly Clubhouse.io, for tracking all of your project's work.
57:47 Because you shouldn't have to project manage your project management.
57:50 Visit talkpython.fm/shortcut.
57:53 Do you need a great automatic speech-to-text API?
57:56 Get human-level accuracy in just a few lines of code.
57:58 Visit talkpython.fm/assembly AI.
58:02 Want to level up your Python?
58:03 We have one of the largest catalogs of Python video courses over at Talk Python.
58:07 Our content ranges from true beginners to deeply advanced topics like memory and async.
58:12 And best of all, there's not a subscription in sight.
58:15 Check it out for yourself at training.talkpython.fm.
58:18 Be sure to subscribe to the show.
58:20 Open your favorite podcast app and search for Python.
58:22 We should be right at the top.
58:24 You can also find the iTunes feed at /itunes, the Google Play feed at /play,
58:29 and the direct RSS feed at /rss on talkpython.fm.
58:33 We're live streaming most of our recordings these days.
58:37 If you want to be part of the show and have your comments featured on the air,
58:40 be sure to subscribe to our YouTube channel at talkpython.fm/youtube.
58:45 This is your host, Michael Kennedy.
58:46 Thanks so much for listening.
58:47 I really appreciate it.
58:49 Now get out there and write some Python code.
58:51 I'll see you next time.