Interested in a library for terminal-style text?

I’m writing up a set of classes that create an in-sketch text box in the style of a monospaced terminal with color support. Would anyone be interested in this as a standalone Processing library?

Usage would look like this:

TermText tt = new TermText(x, y, width, height, fontsize);
tt.println("Hello, world!", color(255,255,255)); // full line
tt.print("Here's ", color(255,0,0)); // prints without newline
tt.print("some ", color(0,255,0)); 
tt.print("colors!", color(50,50,255));

It handles wrap-around in a simple way (no clever word wrap, just continue the next char on the next line), bumps old text off the top of the screen when the buffer’s full. The design would make it easy to add support for printing chars to specific locations in the grid, allowing for things like old-school-roguelike graphics via text. Might also add utility functions for some Caves of Qud style color gradients on strings, or billboarding (horizontal scrolling) a long string across a single row.

Anyway, I’m having fun with this, but turning it into an actual library has an extra layer of work (converting to Java, making a web page for it, all the config file stuff, etc) so if anyone’s interested then you’re welcome to ask/nag/encourage me here to get it done! :laughing:

3 Likes

You might be happy to know that the official library template automates a lot of it :smiley:

It was built by @claudine as part of Processing Foundation’s 2024 dev grant program (pr05)

(Raphaël)

1 Like

@joshg I’m a fan of your terminal text :slight_smile:

Just to add to what @sableraph already said, the example library in the library template started life as Processing classes written by @stixan , which were then converted to Java. So perhaps the example library can help ease the process. And, if anything is unclear or slightly troublesome, please let us know, as we want the process to be smooth.

2 Likes

Hello,
Have you already written it in Processing code (or even Java)?

I would like to see how you do it.
Indeed, I plan to make a widget at some point in order to be able to enter rich text.
:slight_smile:

It’s in Processing code right now; I think I’m convinced, I’ll try porting it to a full library and see how it goes.

@ericrogergarcia You probably wouldn’t want to use my code for a rich text widget, though; it’s built pretty heavily around a fixed-width, columns and rows assumption. I’ll let you know when it’s posted somewhere though!

3 Likes

Talking about rich text (and animated text), you might be interested in this recent contributed library by Barney Whiteman (aka barneycodes on YouTube) called Spicy Text!

spicyText

You can get it at the link below or from the Contribution Manager.

1 Like

That spicytext looks AMAZING !

Now, will I be tempted to be less coder-lazy and create in-string control codes for color, instead of just calling print() separately for every color change? …. :thinking: probably not but we’ll see :laughing:

To answer a little more clearly, Eric, I’ve got a TermChar class for each individual character (because, yes, I tend towards overengineered solutions), a TermRow for each line, and TermText handles the overall ‘console’ window and takes input from the outside world.

TermChar seemed reasonable so I can store a color with each character; it also means I’m using a separate text() call for each letter, so in performance-critical uses it’s possible my code is slow as hell, but for now it seems to do fine for small-to-average text areas (40x30 grids).

TermRow being its own thing makes it fairly easy to handle text scrolling up as you fill the box.

I also track a cursor position and give the option of having it be a blinky cursor. (aesthetics!)

Spacing between characters is calculated once at creation using the Processing functions for text width (of a letter ‘w’) and descending/ascending heights; then every letter can be drawn using a simple grid layout.

I have experienced similar performance concerns with G4P, canvasGUI and Turtle Graphics. My solution was to render he control’s appearance to an off-screen buffer then simply display the buffer every frame. I used a boolean flag to indicate whether the buffer is invalid due to some event and at the beginning of every frame I checked the flag and updated the buffer if required. It meant that multiple events between frames would only result in the buffer being rendered once.

2 Likes

Using the library template is going super smoothly, I’ve already got a local build of the library running and working as intended!

I’m probably going to come across things that need revising or that I want to improve as I write up example programs, so that’s my next step.

One small thing that I almost got hung up on - it wasn’t super obvious at first that I could store Processing ‘color’ variables as just an int in Java. I don’t know if that’s worth mentioning in any of the library docs but I’ll leave that up to you all.

Thanks for the encouragement! This is turning out to be a lot of fun.

1 Like

ps. if anyone’s curious: GitHub - joshgiesbrecht/TermText: Terminal-style monospaced text box for Processing. Supports color and simple line wrap.

1 Like