Page 2 of 3

Re: CoolTerm ... Pls support ESC CursorHome :)

Posted: Sun Sep 18, 2022 6:10 pm
by jmuhammad
roger wrote:I'm afraid CoolTerm will not be able to do exactly what you would like it to do. The plain text display is merely a container that displays the contents of the received buffer in human readable form. New data is always appended to the end of the receive buffer, after which the display is updated. This implementation doesn't lend itself to move the cursor around in the display and thereby changing the point where new data is inserted. The only way to get the cursor (and thus the point where new data is added) to the top left corner is to clear the buffer. In that regard it's very different from the display you would find in a proper terminal emulation application.
So, "clear screen" is something I was able to implement given these constraints. However, "goto 1,1" is not something I'm going to be able to do.
I have created an acceptable workaround where the uC ends its transmission to CT with a specific character or sequence of characters to the end of its report (for now it's the string "EORPT"). The GUI that requested the report then searches for that sequence in the CT text window and when it finds it (or timeout) it then sends CTRL+HOME to CT. It works exceedingly well! I will later experiment with using ASCII 3 as the CTRL-HOME trigger. I can now use this for any interface that can make CT active window and can sendkey.

Re: CoolTerm ... Pls support ESC CursorHome :)

Posted: Sun Sep 18, 2022 6:46 pm
by jmuhammad
I can now detect when CT has ASCII 3 on screen and send CTRL+HOME to CT where it scrolls to upper left corner. ASCII 3 I will probably never use / have used for any other purpose so safe choice.
Image
I'm happy! CoolTerm is really working out for me.

Now I just have to figure out how to get Windows to reliably/predictably release the serial port esp. when I switch between programmer app and monitoring app. May have to do with fact I am programming over Bluetooth COM (Standard Serial over Bluetooth link). Even my iPhone won't let go of my BT KVM unless I toggle BT off/on :x

Re: CoolTerm ... Pls support ESC CursorHome :)

Posted: Mon Sep 19, 2022 12:37 am
by jmuhammad
jmuhammad wrote:
roger wrote:New data is always appended to the end of the receive buffer, after which the display is updated. This implementation doesn't lend itself to move the cursor around in the display and thereby changing the point where new data is inserted.
Roger, I understand that. I also understand if offering this could lead to the impression that CT is not 'acting right'. What I was suggesting was that it be offered with the understanding that if you scroll to the top while data is still coming in that it could either overwrite what is there or, IIRC if I CTRL+HOME while data is coming in the screen would just jump back to the bottom where I issued it and finish displaying incoming data; for me it did not start typing at 1,1...somehow CT remembered where it left off (maybe my settings).

So previously what I did was, since I was sending a fixed length report...in my case I displayed the contents of a 1kb EEPROM so the report with its header could be 9 rows up to 212 rows on CT. When the report was sent the uC STOPPED sending anymore data until the user typed a 'continuation' key on CT terminal. I had a fixed 5 second wait before it issued CTRL+HOME because I had no way feedback from CT when the report had ended. I waited because I too knew if I CTRL+HOME too early then it would just falcon dive to the bottom, finish, then I'd have to manually scroll to the top. 5 seconds isn't too long but someday I will send much larger memory maps...so instead of a large one-size-fits-all buffer e.g. 20 seconds for a 16kb memory but same 20 seconds for a little 512b part :o , I wanted to precisely know when it was done and then CTRL-HOME. So yes, it would be up to the user to not use it if data is still incoming. But since they control what is sent nobody would not tell their transmitter to send 'ASCII 3' or 'ESC[1;1H' unless it was at the end of the transmission.

Now my GUI commands the uC via CT serial port to send EE report back to CT, the last character is ASCII 3, then wait in while(). The GUI then continually checks every 500mS (up to 10 seconds) for the ASCII 3 character; if it sees it then it knows that it is at the end of the report and no more data is coming so CTRL+HOME is OK. The result is I am at the top of the 213 line report and I can, at my leisure manually scroll down or up and review, print, copy, etc. the data. When I am done, I just press my 'continuation' key into CT which sends it to a waiting uC, who in turn starts sending new data (BTW, I clear screen just before this so it starts anew).

It works really well. Well, I have a path for CTRL home which I will use with every project where CT is monitoring. 'ASCII 3' or 'ESC[1;1H' could work natively for CT if, again CT states that this is not PAUSE (CTRL+SHIFT+A), this is CTRL+HOME. The method I now use, all I have to do is make sure the CT Receive Buffer Size is large enough for the report I am expecting (right now I have it set to 20000 because my 1kb report now is 18,832 characters); if not my report gets cutoff at the top :oops: .

Re: CoolTerm ... Pls support ESC CursorHome :)

Posted: Mon Sep 19, 2022 1:01 am
by roger
So, you're saying it would suffice if CoolTerm simply scrolled the contents in the plain text window all the way to the top upon receiving a 'ESC[1;1H' (or 'ESC[H' something like that)?

Re: CoolTerm ... Pls support ESC CursorHome :)

Posted: Mon Sep 19, 2022 5:42 am
by jmuhammad
roger wrote:So, you're saying it would suffice if CoolTerm simply scrolled the contents in the plain text window all the way to the top upon receiving a 'ESC[1;1H' (or 'ESC[H' something like that)?
Yes.

Because everyone doesn't know how to make their application search the CT display and then emulate a keyboard sending CTRL+HOME. But by simply checking a box, CT will do it automagically when it receives the sequence. A feature they did not know they'd appreciate!

An option just like any other option CT has in "Data Handling"; if someone misuses it oh well... but unlike backspaces :shock: , CTRL+HOME on CT in my experience does not goof the data up. Try it...when data is coming in give CT display area the focus then take the keyboard and press CTRL+HOME; it will go to 1,1 and stay until/unless new data comes in then it goes back to end.

I recommend 'ASCII 3' aka "ETX" or 'ESC[1;1H' for CTRL+HOME. "The End-of-Text character (ETX) (hex value of 0x03...) is an ASCII control character. Its function is to let the receiving computer know that the end of the data stream has been reached."

Keep 'ESC[;H' for "Clear on Display".

Re: CoolTerm ... Pls support ESC CursorHome :)

Posted: Mon Sep 19, 2022 10:56 am
by roger
Thanks.

I was actually thinking of replacing ESC[;H with ESC[2J to clear the display. I think that would conform with the standard a bit more. That would free up ESC[;H to home the screen. Intuitively, these would make more sense and do something somewhat related of what they are intended for in proper terminal emulations.

Along those lines, I wonder if perhaps ASCII 2 (Start of Text) would make more sense than ASCII 3 to home the screen?

Re: CoolTerm ... Pls support ESC CursorHome :)

Posted: Mon Sep 19, 2022 12:10 pm
by jmuhammad
roger wrote:Thanks.

I was actually thinking of replacing ESC[;H with ESC[2J to clear the display. I think that would conform with the standard a bit more. That would free up ESC[;H to home the screen. Intuitively, these would make more sense and do something somewhat related of what they are intended for in proper terminal emulations.
Oh sorry Roger, yes I agree. I never paid attention to the string sequence except with TeraTerm I think we had to use that...otherwise it is far easier to send Chr(12). But for the home we had to use ESC[1;1H (I just made a goto(x,y) macro to populate it)

vt100 Cursor Home: <ESC>[{ROW};{COLUMN}H
Sets the cursor position where subsequent text will begin. If no row/column parameters are provided (ie. <ESC>[H), the cursor will move to the home position, at the upper left of the screen.
roger wrote:Along those lines, I wonder if perhaps ASCII 2 (Start of Text) would make more sense than ASCII 3 to home the screen?
I see what you mean. But if I want text to appear at the top I have the uC send clear the screen (ASCII 12) then send the data. If I want to scroll to the top after I know the text is done so I won't get jerked back to the bottom of the screen, I place that indicator at the end of the text hence I think ETX (ASCII 3) is better choice. ATEOTD it doesn't matter what you pick, we'd use it :D I'd maybe use ASCII 2 maybe as a counter marker or something e.g. the app could count (or capture just the) characters between ASCII 2 and ASCII 3 markers.

Re: CoolTerm ... Pls support ESC CursorHome :)

Posted: Mon Sep 19, 2022 2:12 pm
by roger
I should be able to get a proof of concept up and running relatively quickly. I'll reach out via e-mail once I have something ready for testing.

Re: CoolTerm ... Pls support ESC CursorHome :)

Posted: Mon Sep 19, 2022 4:33 pm
by roger
roger wrote:I should be able to get a proof of concept up and running relatively quickly. I'll reach out via e-mail once I have something ready for testing.
I sent you an e-mail (to the address you used to create the forums account) with the link to a test build that supports display homing via ESC[;H or ASCII 3.

Re: CoolTerm ... Pls support ESC CursorHome :)

Posted: Sat Nov 08, 2025 6:07 am
by DRSDavidSoft
Hi Roger,

I'm running into more VT-100/ANSI escape code handling issues and inconsistencies; I was hoping that you could please help either resolve the issues, or explain why these problems are happening, so that I could modify/adjust my code on the other side.

I decided to post a reply on this thread instead of creating a new one, if this isn't the appropriate place to post, please let me know to move into the correct one.

It's amazing to see that CoolTerm handle the escape sequences for color codes, such as:

Code: Select all

1B 5B 39 32 6D (ESC [ 92 m)
-> Produces Green

(I know CoolTerm isn't a real VT-100 terminal emulator and it is only handling a subset of the escape codes, but the items mentioned below feel like need to be addressed as well, if possible.)

Please note that any sequence I mention below is valid, tested in all other terminals beside CoolTerm, and works correctly on them.

Here are the minor issues that I would like to point out:
  • Handling clear/reset code
    First, CoolTerm handles the reset/clear code ESC[0m correctly.

    However, there is an alternative sequence that might be receive: ESC[m which doesn't contain 0. My code is sending this, and CoolTerm doesn't appear to correctly support it.

    ChatGPT says the following:
    For the SGR (Select Graphic Rendition) control sequence, the parameter defaults to 0 if omitted per ECMA-48/ISO 6429. So ESC[m is equivalent to ESC[0m and resets all attributes in virtually all ANSI/VT-compatible terminals.

    Considering that the alternative sequence is also a valid, expected code that is sent to indicate the same thing, CoolTerm should handle it as well.

    So, ESC[m is equivalent to ESC[0m, and it is expected to clear the color as well as remove the bold, italic and underline effects.

    Bonus Tip: This is a bit opinionated, but I believe pressing the «× Clear Data» button (in the top toolbar) should also clear the VT-100 effects (such as the text color, and effects such as bold and italic, if supported).

    But the current approach, keeps the text color as whatever was set by the last escape code.

    If you agree with me, I think it would be better to remove the colors an effects, maybe at least if the connection is currently closed; if that makes sense.

    ----
  • Bold vs italic effect mismatch
    The ESC[1m sequence is supposed to make the part of the text bold, however it seems that when the unsupported codes are received, it somehow bugs the program, and the italics effect is triggered. I'm not sure exactly how to reproduce this, but it is getting triggered nonetheless.

    ----
  • Home Display sequence (alternative version)
    Again, it's great to see that the ESC[H ESC[2J sequence is being handled correctly – The options support the "Clear Display" on the ESC[2J code.

    However, I'm not sure if you are handling ESC[H the same way you do ESC[;H (notice the missing semicolon).

    Again, ChatGPT says the following:
    They’re equivalent.

    - ESC[H is CUP (Cursor Position) with both parameters omitted -> row=1, col=1.
    - ESC[;H is CUP with two empty parameters -> both default to 1 as well.
    - Therefore both move the cursor to home (1,1). They’re also equivalent to ESC[1;1H and ESC[f] (and ESC[;f)).


    This means that ESC[;H is actually a parametrized sequence code, the other side might supply the row number and column number (e.g. ESC[1;1H), don't supply the default values (e.g. ESC[;H, which is the handled case), or don't supply any values (e.g. ESC[H, which is actually the case in my code).

    ----
  • Clearing a character (backspace behavior)
    This one might be a little tricky, do to the way the terminal is emulated in CoolTerm, having looked at OpenSimpleTerm's code briefly.

    If so, I apologize beforehand for bothering you about it, and understand if it would not be feasible to implement it in CoolTerm.

    So, basically, if I press the <- Backspace key, a 0x08 byte is sent to the other side. My code responds like this:

    Code: Select all

    Sent: 08                            -> BS
    Recv: 1B 5B 44 1B 5B 4B             -> ESC[D ESC[K
    
    Here’s what those byte sequences mean in a typical terminal:

    Hex 08 = character BS (Backspace):
    Moves the cursor one position to the left (without deleting the character on screen in a raw capture). In many terminal contexts a BS followed by a new character is how programs “overwrite” previously printed output.

    ESC[D ESC[K:
    This is two ANSI/VT (CSI) control sequences back-to-back:

    ESC [ D
    - Name: CUB (Cursor Backward)
    - Meaning: Move cursor backward n columns; n defaults to 1 when omitted. So this moves the cursor left by 1.

    ESC [ K
    - Name: EL (Erase in Line)
    - Meaning: Erase part of the current line according to parameter n (which is omitted here, so n = 0 by default). n = 0 means erase from the cursor position to the end of the line (inclusive). It replaces those character cells with the terminal’s erase character (space), without moving the cursor.

    Putting them together:
    ESC[D moves cursor one column left.
    ESC[K then clears from that (now earlier) cursor position to end of line.

    ChatGPT says the following:

    Why a program might do this:
    Often used in dynamic terminal updates (progress bars, status lines) to revise previously printed text without issuing a full carriage return or clearing the whole line.

    Notes on defaults (per ECMA-48 / ISO 6429):
    - CSI D with no numeric parameter: n = 1.
    - CSI K with no numeric parameter: n = 0 (cursor to end of line).
    If parameters were present they’d appear as digits before the final letter, e.g. ESC [ 5 D (move left 5), ESC [ 2 K (erase entire line), ESC [ 1 K (erase from start up to cursor).


    In summary, when we press the backspace key in CoolTerm (and any other terminal I tested):
    Sent: 08 = Backspace.
    Received:
    ESC [ D = Cursor Backward 1.
    ESC [ K = Erase to end of line.
    Sequence's expected effect: Move cursor left one cell, then blank everything from there to the line’s end.

    However, this is not the case in CoolTerm. Can you please detect and handle both ESC[D ESC[K?

    For ESC[K, it's simple: Just delete everything from the current location, to the end of the line.
    For ESC[D, I'm not sure how CoolTerm handles the cursor location (if it does), so I'm not sure how trivial it would be to implement it.

    -----
  • Lastly, I'm making use of other valid VT-100 escape codes, such as ESC[s and ESC[u, which are used to save and restore the current position of the cursor in/from memory.

    Codes like this might need the "Disable RX" checkbox to be disabled, so you can keep track of the position of the cursor... I'm not sure, so it might be infeasible to implement such escape codes, although very useful!
Here are some screenshots of the problems I'm having:

Example in CoolTerm:

Image

Example in TeraTerm:

Image

Would you be able to implement any of these requests?

I appreciate reading through my long wall of text. Thank you for creating CoolTerm! <3