Can ANSI escape sequences be used in keystroke aliases?

Apr 13, 2010
318
7
62
The Hague
I was thinking of using them to move the cursor back to a previous insertion point in the output of a keystroke alias.

Regards, DJ.
 
Dec 7, 2009
238
2
Left Coast, USA
I've never used those escape sequences in aliases, but for whatever it's worth (possibly nothing :-) I can pass this along — it's marginally related, maybe...

I wanted an alias that would enable me to "pushd" to some new directory and keep the cursor on the same line rather than have it advance down the screen. This proved harder than I thought. I made I-don't-know-how-many attempts and then finally succeeded with an alias I call "Sameline":

sameline c:\batch

... switches to the c:\batch directory and keeps the cursor on the same line. I had to ensure that the command line is erased. Most attempts left "ghost" characters on-screen following the directory change. That bit was harder to solve than I'd thought it would be. The "Sameline" alias uses the older style "%+" way of chaining commands together — I know I should change those to "&":

pushd %1 %+ screen -1 0 %+ drawhline %_row 0 80 0 %_bg on %_bg %+ screen -1 0

The need for that final "screen -1 0" command surprised me. But I guess "drawhline" must cause the cursor to advance downward by one screen line.
 
May 20, 2008
12,171
133
Syracuse, NY, USA
You can, though it might be simpler to use the TCC internal variables & functions.
I played with saving/restoring the cursor position in an alias. It basically worked, but I ran into trouble when the console window scrolled. Is the remembered position in screen buffer coordinates or window coordinates?
 

rconn

Administrator
Staff member
May 14, 2008
12,557
167
I played with saving/restoring the cursor position in an alias. It basically worked, but I ran into trouble when the console window scrolled. Is the remembered position in screen buffer coordinates or window coordinates?

Window coordinates. Not sure that it makes much difference, as the screen buffer can scroll too.
 
Apr 13, 2010
318
7
62
The Hague
Can you do <cursor left> and <cursor right> in a keystroke alias? I always thought that to be impossible. That's why the latest ANSI sequences caught my attention - as a way to cursor back over the output of the keystroke alias to an insertion point where the variable part should be.
 
May 20, 2008
12,171
133
Syracuse, NY, USA
Can you do <cursor left> and <cursor right> in a keystroke alias? I always thought that to be impossible. That's why the latest ANSI sequences caught my attention - as a way to cursor back over the output of the keystroke alias to an insertion point where the variable part should be.
I (sort of) understand (I think). What you put in a keystroke alias is (literally) inserted into the command line. And an <Esc> on a command line erases the command line. So you get the likes of this. The regular alias is OK; the keystroke alias not OK.
Code:
v:\> alias ctrlq `echo abc^e[Ddef`

v:\> ctrlq
abdef

v:\> alias @@Ctrl-q `echo abc^e[1Ddef`

v:\> (Ctrl-q pressed)
TCC: Unknown command "[1Ddef"
 
Apr 13, 2010
318
7
62
The Hague
Thank you, Vince.
You gave me food for thought.

Code:
echo x^e[Dy
y

... is about as far as I got. It means that the 'x' os overwritten, as expected.
Similar attempts with Alias @key produced results which lead me to believe that the ANSI interpretation is left "out of the loop" when key-strike aliases send characters to the command line buffer. That would mean that ANSI cursor movements are not possible.

Even when Esc is made a normalkey.

I'm moving on. It was fun, though.

Thanks again, DJ.
 
Last edited:
Jul 29, 2016
60
1
The keystroke alias will work if you do this:

alias @@Ctrl-q `echo abc^^^^e[1Ddef`

The ^^^^e will turn into ^^e in the alias definition. Upon executing the alias, the second ^ will be treated as-is and not cause the ^e to act as the <ESC> key and clearing the command line. The remaining ^e will now be treated just as if you had typed it manually on the command line, and cause the ANSI command to work as expected.
 

Similar threads