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

(post deleted by author)

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.