lxde / lxterminal

VTE terminal emulator written in GTK
GNU General Public License v2.0
159 stars 55 forks source link

save/load cursor ANSI sequence #112

Open RiccaDS opened 1 year ago

RiccaDS commented 1 year ago

I am programming in Python with outputs on LXTerminals. I am not very used to CLI output. I read that there should exist ANSI escape sequences such as "\033[s" for saving the cursor position and "\033[u" to reload the position. These two don't seem to work and I am testing some other escape sequences but I am having other problems. Is there a reference for supported sequences? or do you know something more about this?

FinboySlick commented 1 year ago

LXTerminal uses VTE so this is what should be parsing your escape sequences. Quick search for documentation on VTE escape sequences hasn't yielded much useful information however.

I have tested the ones you mentioned with bash like this and it seems to work, at least on a per-line basis:

printf "hello\033[s\ngood day\033[unight\n"
hello
good night

As you can see, it prints 'hello', saves the current position (6), then it prints 'good day', restores the position, and when it prints 'night' it overwrites 'day' since 'hello' was 5 characters long.

I do not know if that's the expected behaviour however.

RiccaDS commented 1 year ago

Yes you are right, it works on a per-line basis. I was working on multiline strings however (omitted this sorry). I am having a hard time ereasing multiline strings and rewriting on them. I seem to be able to use \033[A to jump up one line. However it sometimes seem to have a weird/inconsistent behavior. I don't know if this is due to some error in my code(very possible) or what. I wasn't able to debug however, it was getting too complicated so the save position escape sequence would have proved to be useful. But it doesn't work on multiline however. I don't know, I am now working with curses because I don't seem to be able to win over the CLI too easily unless I find something else. Despite curses has it's own difficulties.