Quick Byte: Colorful Terminal Output with ANSI Escape Sequences
Ken Gracey
Posts: 7,392
in Propeller 2
We're starting to venture into the capabilities of FlexProp, with this example.
https://www.parallax.com/colorful-terminal-output-with-ansi-escape-sequences
Ken Gracey
Comments
Fantastic!
Another great object by Jon
Thanks, Ray. It's an incredibly simple object, and I hope it inspires others to craft simple objects, too. An object doesn't have to be complicated to be useful.
Ken,
I noticed a couple of things when trying this out.
Ray,
I don't know why you had to change the baud for Tera Term -- it runs at 230400 for me. I also tested with PuTTY (for Windows) and the default terminal used by FlexProp.
With ANSI output I download to Flash using F11. If opening the terminal program doesn't reset the board, then I do a manual reset. I made a note of this in the demo code (top of listing).
I settled on 230_400 for the P2.
Long term, I am hoping that @"Jeff Martin" will update PST so that is accepts PST commands, or ANSI commands. Of course, I would like it to be cross-platform, too.
Jon,
Congratulations! Another fine example Jon.
I just use 115_200 as a default in everything I do for P1 and a lot of P2, and lately I've been switching to 2_000_000 for P2.
So I just thought 115_200 might be more common. As I said, I'm wasn't sure what your object's normally use, tho I now see you use 230_400 so that's fine.
OK, I see you're using Flash. I don't - never used it yet. It's much quicker to just download to ram which is one of the great benefits of P1, and hence P2. So now I understand the reset comment.
Yes, it would be great to see PST support a subset of ANSI.
Clear, home, goto(x,y) and fgnd(r,g,b) and bgnd(r,g,b) would be my first preference.
I am sure if Jeff released that section of the code someone would step up and add it in for him.
I'll probably add this subset to my LCD driver I released yesterday.
May I suggest you also add goto(x,y) which just calls crsr(x,y) ?
I'm curious that crsr_xy(x,y) does x+1 and y+1 whereas crsr_x(x) and crsr_y(y) does not - I haven't coded vt52/vt100 for 40 years.
BTW while looking at your jm_ansi.spin2 I noticed that you missed coding "pub bgnd_rgb(r, g, b)"
Ray
Whoops, meant to delete that -- I found it didn't always work and I don't want to be nagged for something that I have no control over.
Oh! Good to know.
So I was just adding home, cls, gotoxy and fgnd, bgnd to my LCD driver. So what do you recommend to set forgeround and background colors?
I have to do scroll and that's a PITA to do manually. It seems the scroll in the LCD chipset is broken - doesn't seem to work properly in landscape mode but fine in portrait. So I may have to keep my own text buffer I've done it but it's a PITA to need to redraw the whole screen when the chipset is supposed to do it.
The named and index colors work in the ANSI object with the three terminals I tested. I will re-test the RGB mechanism; maybe I made a mistake.
This is SPINning out of control.
For you C lovers out there, I matey, here is my spin on the subject.
ANSI.h
To use this include file:
Actually, no code was written to do any of this...
Mike
Quick Bytes is about helping new programmers get started. If you're going to chime in, why not translate the Spin demo so that new C programmers can compare and learn from the two languages?
FWIW, "ANSI.h" seems already to be defined in the C world, so maybe that's not a good name for the C header you suggest. I'm not much of a C programmer, but with a big cup of coffee and a couple of references on my desk, I managed to create a work-alike demo of my Spin program that is topic of this thread. I tested the code with FlexProp on Windows.
I hate to bare bad news, but... The ansi sample code is "just a little" off (so far, on macOS' Terminal) as it is not returning to column 0 on each line. Definitely using -T in flexprop's command options.
Used minicom (within the Terminal app) as well, and got the same results.
You might try changing LF to CR for the Mac. The code, as presented, works in PuTTY, Tera Term, and the PropTool terminal under Windows. In PuTTY and Tera Term I have it add CR to LF and vice-versa.
Yes, it's a function of interpretation of and . There if often a setting for these.
can be interpreted as just return to the beginning of the line, or return to beginning of line and advance the line.
can be interpreted as advance the line, while returning to the beginning of the line is again dependant/optional.
Then when you use you may get a double advance line leaving a blank line between.
And to even add to this, sometimes if you perform a the does a return and new line, and the software will skip the following . As an adjunct to this, if when writing characters to the screen, you overflow off toe right edge, then the next character will be in the leftmost position of the next line. Some terminals record this fact, and if a , or follows it will be ignored. Makes for some interesting coding. ANd we haven't resolved any of this in more than 40 years!!!