Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 16:51 09 May 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : "option escape" and the local console

Author Message
dddns
Senior Member

Joined: 20/09/2024
Location: Germany
Posts: 259
Posted: 09:20pm 24 Mar 2025
Copy link to clipboard 
Print this post

Hello!

I would like to print simultaneously on the local and the serial console.
The output should look identical.

Using "option escape" allows, to use some possible ANSI/VT-100 escape sequences within a string having the backslash as escape character(manual page 23)
It is also possible to send individual values.

All the listed escape codes on manual page 23/24 work and get executed on both console. Individual codes like using fore/background colors work as well on the serial (VT-100)console. But on the local console, unlisted codes won't be suppressed but get printed out in clear text. But I must admit, that I might not understand the manual correctly regarding usage.

My only idea how to get around this is to disable the local console output and print with the "text" command to it while printing to serial with "print @(x,y)".
But that would of cause have the disadvantage of processing it twice.

I would very much appreciate some suggestions!
Edited 2025-03-25 07:23 by dddns
 
dddns
Senior Member

Joined: 20/09/2024
Location: Germany
Posts: 259
Posted: 05:40pm 25 Mar 2025
Copy link to clipboard 
Print this post

No answer is still an answer. Will use occam's razor to analyze but fear bad..
Edited 2025-03-26 03:41 by dddns
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4249
Posted: 06:09pm 25 Mar 2025
Copy link to clipboard 
Print this post

Printing to the display (what you call the local console) can't handle ANSI escape codes, just the handful of escape characters mentioned p23-24 of the manual, and as a result such ANSI escapes just get printed as plain text.

  @dddns said  My only idea how to get around this is to disable the local console output and print with the "text" command to it while printing to serial with "print @(x,y)".
But that would of cause have the disadvantage of processing it twice.


I believe that is what you will have to do, it's certainly what I did:

https://github.com/thwill1000/mmbasic-sptools/blob/master/src/splib/examples/txtwm.bas
https://github.com/thwill1000/mmbasic-sptools/blob/master/src/splib/txtwm.inc

But now I fear you will have follow up questions .

Best wishes,

Tom
Edited 2025-03-26 04:29 by thwill
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4249
Posted: 06:13pm 25 Mar 2025
Copy link to clipboard 
Print this post

For a fully fledged example, see the program 'kingdom/kingdom.bas' in:
https://github.com/thwill1000/mmb4l/releases/download/v0.7-alpha.1/gamepack-1.0.0.tgz

Tom
Edited 2025-03-26 04:14 by thwill
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10062
Posted: 06:36pm 25 Mar 2025
Copy link to clipboard 
Print this post

In the CMM2 firmware the editor and file manager work on both an external serial console and the screen. The way it works is that the firmware builds the screen image using VT100 escape codes mixed with the text and when applicable a single function is called that outputs the codes on the serial port and interprets the codes to output to the display. For text only information this approach works well.
In this code DisplayPutC is effectively the same as TEXT MM.HPOS,MM.VPOS,A$  where A$ is a single character. It automatically wraps if it gets to the end of a line and also interprets CR and LF.
Changing gui_fcolour and gui_bcolour is the same as the COLOUR forground,background command.
gui_font_width is the same as MM.FONTWIDTH
MX470Cursor(0,0) is the equivalent of TEXT 0,0,""

This concept is how I would do it if trying to display text only information in colour on both outputs



void parseanddisplay(char *p, int len){
int i=0,j;
char seq[12];
while(i<len){
while(p[i]!='\033'){
DisplayPutC(p[i]);
i++;
}
i++;
if(p[i]=='['){ //escape sequence found
mymemset(seq,0,12);
j=0;
seq[j++]=p[i];
do {
i++;
seq[j++]=p[i];
} while (!(IsAlpha(p[i])));
if(seq[strlen(seq)-1]=='H'){
if(strlen(seq)==2){
MX470Cursor(0,0);
}
else {
int rows,cols;
sscanf(&seq[1], "%d;%d", &cols, &rows);
MX470Cursor((rows-1)*gui_font_width,(cols-1)*gui_font_height);
}
}
else if(strncmp(seq,"[K",2)==0){ // erase to end of line
int i=E.screencols-(CurrentX/gui_font_width);
while(i--)DisplayPutC(' ');
}
else if(strncmp(seq,"[?25l",5)==0)ShowCursor(false);
else if(strncmp(seq,"[?25h",5)==0)ShowCursor(true);
else if(strncmp(seq,"[36m",4)==0){gui_fcolour=CYAN;gui_bcolour=BLACK;}
else if(strncmp(seq,"[37m",4)==0){gui_fcolour=WHITE;gui_bcolour=BLACK;}
else if(strncmp(seq,"[32m",4)==0){gui_fcolour=GREEN;gui_bcolour=BLACK;}
else if(strncmp(seq,"[39m",4)==0){gui_fcolour=WHITE;gui_bcolour=BLACK;}
else if(strncmp(seq,"[35m",4)==0){gui_fcolour=MAGENTA;gui_bcolour=BLACK;}
else if(strncmp(seq,"[31m",4)==0){gui_fcolour=RED;gui_bcolour=BLACK;}
else if(strncmp(seq,"[34m",4)==0)gui_bcolour=BLUE;
else if(strncmp(seq,"[33m",4)==0){gui_fcolour=YELLOW;gui_bcolour=BLACK;}
else if(strncmp(seq,"[m",2)==0){
gui_fcolour=WHITE;
gui_bcolour=BLACK;
}
else if(strncmp(seq,"[7m",3)==0){
int i=gui_fcolour;
gui_fcolour=gui_bcolour;
gui_bcolour=i;
}
i++;
}
}
}

Edited 2025-03-26 04:42 by matherp
 
dddns
Senior Member

Joined: 20/09/2024
Location: Germany
Posts: 259
Posted: 07:57pm 25 Mar 2025
Copy link to clipboard 
Print this post

Many Thanks, I think I understood and giving a direction is more than useful!
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025