Shop OBEX P1 Docs P2 Docs Learn Events
Escape Codes — Parallax Forums

Escape Codes

This is somewhat embarrassing. I can't make escape codes work in Terra Term. I am posting here instead on a Terra Term forum because I am trying to use Tachyon syntax to send the codes. I thought I had figured out what to do but I was mistaken.
: CSRUP 27 EMIT 91 EMIT 65 EMIT ;

: CSRUP3 27 EMIT 91 EMIT 3 EMIT 65 EMIT ;

: CSHOME 27 EMIT 91 EMIT 49 EMIT 126 EMIT ;

: CSLF 27 EMIT 91 EMIT 68 EMIT ;

: CSRDN3 27 EMIT 91 EMIT 51 EMIT 66 EMIT ;
Of these only CRSUP behaves as expected. Can anyone tell me why?

Note: in CSRUP3 the parameter is sent as the ASCII code for "3" where as in CSRDN3 it is sent as the character itself. And I tried a lot more variations. A lot more.

In the terminal setup New-line Receive is set as AUTO and Transmit as CR.

What am I missing? (he is tempted to shout)

Comments

  • artkennedy wrote: »
    This is somewhat embarrassing. I can't make escape codes work in Terra Term. I am posting here instead on a Terra Term forum because I am trying to use Tachyon syntax to send the codes. I thought I had figured out what to do but I was mistaken.

    I don't know if the Tachyon syntax is correct, however:
    : CSRUP3 27 EMIT 91 EMIT 3 EMIT 65 EMIT ;
    

    The number of positions should be a number and not the ASCII code, so 51 instead of 3.
    : CSHOME 27 EMIT 91 EMIT 49 EMIT 126 EMIT ;
    

    This is a bit unclear, you want to clear the screen or move the cursor to home ? In either case, the last character 126 (tilde) is not correct. Home is ESC[H while clear screen is ESC[2J (which should not move the cursor as per specification, altough some implementations move the cursor, usually it should be followed by ESC[H).
    : CSLF 27 EMIT 91 EMIT 68 EMIT ;
    : CSRDN3 27 EMIT 91 EMIT 51 EMIT 66 EMIT ;
    

    These looks correct to me.

    Have you tried to send the codes with spin (or something else) just to make sure they are correct and the terminal accepts them ?

    Also, since you are using relative cursor movements, make sure the cursor is positioned so they have some effects, for example the cursor up sequence won't work if the cursor is already at the topmost position. Try sending something like ESC[10;10H at the beginning to position the cursor at 10,10.

    For reference, just in case:
    http://ascii-table.com/ansi-escape-sequences-vt-100.php
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2020-05-14 13:05
    Tachyon already has ANSI code support and if it detects an ANSI compatible terminal on reset, it will enable ANSI sequences.
    That's why you will see "neon" colors in TeraTerm.
    Have you had a look at how it is done in EXTEND? Here are the relevant parts:
    --- *** ANSI TERMINAL SUPPORT ***
    PUBLIC
    --- ANSI color values ---
    0	:= black
    1	:= red
    2	:= green
    3	:= yellow
    4	:= blue
    5	:= magenta
    6	:= cyan
    7	:= white
    
    PRIVATE
    long _ansi
    pri ANSI?			uemit W@ 0= _ansi @ 0<> AND ;
    pri AEMIT			ANSI? IF EMIT ELSE DROP THEN ;
    pub ESC ( ch -- )		$1B AEMIT AEMIT ;
    
    pub HOME			'H'
    pri ESCB ( ch -- )		'[' ESC AEMIT ;
    
    pub PEN ( col -- )		7 AND '3'
    pri COL ( col fg/bg -- )	ESCB '0' + AEMIT 'm' AEMIT ;
    pub PAPER ( col -- )		'4' COL ;
    
    pri CUR ( cmd n -- )		'[' ESC SWAP
    pri .PAR			SWAP ANSI? IF .AS" ##~#" ELSE DROP THEN AEMIT ;
    pub XY ( x y -- )		';' SWAP CUR 'H' .PAR ;
    
    pub CLS 			$0C EMIT ;
    --- Erase the screen from the current location
    pub ERSCN			'2' ESCB 'J' AEMIT ;
    --- Erase the current line
    pub ERLINE			'2' ESCB 'K' AEMIT ;
    
    pub CURSOR ( on/off -- )	'?' ESCB 25 .
    pri asw				IF 'h' ELSE 'l' THEN AEMIT ;
    
    pub PLAIN			'0'
    pri ATR ( ch -- )		ESCB 'm' AEMIT ;
    pub REVERSE			'7' ATR ;
    pub BOLD			'1' ATR ;
    
    pub WRAP ( on/off -- )		'?' ESCB '7' AEMIT asw ;
    pub MARGINS ( top bottom -- )	'[' ESC SWAP ':' .PAR 'r' .PAR ;
    
    --- res = 1B5B.306E
    pub ?ANSI 			 _ansi ~~ '5' ESCB 'n' EMIT 100 ms 0 4 FOR 8<< KEY OR NEXT _ansi ! ;
    
    1076 x 774 - 100K
  • Tachyon already has ANSI code support and if it detects an ANSI compatible terminal on reset, it will enable ANSI sequences.
    That's why you will see "neon" colors in TeraTerm.
    Have you had a look at how it is done in EXTEND? Here are the relevant parts:

    Lord, lord. Yes I had been there several times and because CLS and ERLINE didn't seem to do anything when
    entered from the command line I got frustrated and started trying to send via EMIT. So today I actually
    paid attention and I get it now. Thank you for your patience. You to macca.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2020-05-17 03:50
    @artkennedy - If it helps, just force it to use ANSI by setting the flag variable to non-zero. So even a "_ansi ~~" will work for instance.
    long _ansi
    pri ANSI?			uemit W@ 0= _ansi @ 0<> AND ;
    

    BTW, _ansi is a long because it stored the terminal response as a reference as well as a flag. No response from the terminal would shift in 4 null keys to make it a false flag.
Sign In or Register to comment.