-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide DEC sequences for save & restore cursor position operations #226
Comments
What's your use case exactly ? It's a bad idea to depend on those cursor movements if the terminal can not use it and Jansi is somewhat limited when it comes to mimic ansi sequences. The original goal is to allow rendering colors and strip them on unsupported terminal and emulate on windows. |
The project is here, but in a nutshell the use case is a text-mode "spinner" for long-running command line processes, which involves these steps:
This is done in a loop that spins through the frames in the caller's chosen spinner animation. From a quick evaluation it appears that JLine3 is unsuitable for my use case given that:
And just to be crystal clear, I'm not asking for termcap/terminfo capabilities. I personally think that's well beyond the scope of |
Here's my workaround, which I've tested in various terminal emulators on both macOS and Linux. As previously mentioned, it would be ideal if |
@gnodet I believe it would - that's the approach I took in my own code. However there may be folks who need finer-grained control over which sequences(s) are sent, so I'd probably suggest splitting this into multiple methods, perhaps something like: public Ansi saveCursorPosition() {
saveCursorPositionSCO();
return saveCursorPositionDEC();
}
// SCO command
public Ansi saveCursorPositionSCO() {
return appendEscapeSequence('s');
}
// DEC command
public Ansi saveCursorPositionDEC {
builder.append(FIRST_ESC_CHAR);
builder.append('7');
return this;
}
public Ansi restoreCursorPosition() {
restoreCursorPositionSCO();
return restoreCursorPositionDEC();
}
// SCO command
public Ansi restoreCursorPositionSCO() {
return appendEscapeSequence('u');
}
// DEC command
public Ansi restoreCursorPositionDEC() {
builder.append(FIRST_ESC_CHAR);
builder.append('8');
return this;
} |
Background
The escape sequences for "save cursor position" and "restore cursor position" were never standardised as part of the ANSI (or subsequent) specs, resulting in two different sequences known in some circles as "DEC" and "SCO":
ESC7
(save) andESC8
(restore)ESC[s
(save) andESC[u
(restore)Different terminals (and OSes) support different combinations of these sequences (one, the other, neither or both); for example the iTerm2 terminal on macOS supports both, while the built-in macOS Terminal.app only supports the DEC sequences.
Problem
From the source I see that
jansi
'ssaveCursorPosition
andrestoreCursorPosition
methods use the SCO sequences for these operations, meaning that they won't work by default on some terminals (including, notably, macOS' built-in Terminal.app).Proposed Solution
Add support for both variants, so that
jansi
consumers can determine the correct one to use (itself a thorny problem, but one that feels appropriate to punt out of the library).The text was updated successfully, but these errors were encountered: