Comments (17)
By OS X, I assume you mean Terminal.app? Wonder if it works on iTerm.
For reference, current code:
Lines 52 to 53 in 3dff027
Looks like other modern terminals supports both, so I guess we could just switch to 7/8?
@Qix- Thoughts?
from ansi-escapes.
Note that ESC
in this case doesn't have the trailing [
. I think the trailing [
technically makes it a CSI
character sequence. (My entire education on the topic comes from wikipedia, so take with a grain of salt).
from ansi-escapes.
Firstly, not entirely sure where See bottom for edit.7
and 8
come from; I don't see them documented anywhere on any of my go-to lists (at least, not clearly).
However, iTerm correctly performs the escape.
$ printf "first\n\x1b7second\n\x1b8third"
first
third
as does Terminal.app.
The escapes I've seen officially documented in lieu of 7
and 8
are s
and u
, respectively.
$ printf "first\n\x1b[ssecond\n\x1b[uthird"
first
third
However these do not work in Terminal.app. This is probably because (and I'm speculating here) Apple has hinted at being pretty starchy with their terminal additions and seem to try to keep things pretty aligned with the VT100, which IIRC doesn't support [s
and [u
.
@jamestalmage what version of OS X are you running?
Something that is worth mentioning is the dated-ness of ANSI escapes. Color stuff works fine because it is needed far more often in terminal output. It's solid and commonly accepted (though IMO weakly standardized) and color output is generated progressively, meaning there's no rewrites of existing buffers.
Cursor manipulation, as you can tell, is hairy and not at all implemented fairly across all terminals. Using cursor operations, in my humble opinion, should only ever consist of in-line modifications in practice. This is because cursor positions are absolute to the window and not to the buffer itself (I'm sure, though, there is an emulator out there somewhere that does otherwise. Poor standardization!).
This means if a window is resized or is much smaller (I commonly get some terminals down to 2 lines in a paned layout just to see the tail of logging, etc.) your out-of-line cursor manipulation escapes are going to cause undesirable effects the vast majority of the time (unless you're counting on process.stdout.rows
, which... don't
In the cases where you need to jump between lines, use a technology much better suited, such as the curses
or even better the ncurses
library. There are quite1high a2mid few3low libraries that help with such things, depending on how high/low level you want to go. However using the termcap library in some capacity is definitely the Right Way™ to do more robust cursor manipulation.
In the end, I'd be inclined to say something is up with your Terminal.app configuration or that these particular OOB escapes were added in a newer version of OS X (I'm currently at El Capitan and seeing them correctly).
Any more docs on them would be appreciated.
EDIT: Aha, that's why. They're individual escape values derived from the Termcap database for some particular TERM
. What's your TERM
environment variable set to?
Long explanation: Termcap databases were created for the
curses
library IIRC and basically define all of the capabilities of all of the possibleTERM
values. A lot of shells/emulators won't let you setTERM
to something not in the Termcap database for this reason.
Each entry in the database has a list of capabilities and, in the event the TERM is capable of doing something, the provides the associated escape codes for each capability.7
and8
seem to be the associated escapes for save/restore for at leastxterm-256color
. Speculation, but I would imagine a large percentage of users usexterm-256color
as a default, hence why this has gone unnoticed for as long as it has.
@sindresorhus while these might work for a lot of users, using hard-coded values derived from Termcap info is definitely not the Right Way™. Depending on how complete we want this to be, it might be time to start looking at Termcap parsing like we've entertained before.
Hopefully this sheds a little bit of light!
from ansi-escapes.
$ echo $TERM
xterm-256color
OSX Yosemite 10.10.5
from ansi-escapes.
OSX Yosemite
Must be an OS X version thing, then. That's the only explanation I can muster up.
Can you confirm the output of the following command, just to humor me? 🎉
$ printf "first\n\x1b7second\n\x1b8third\n"
from ansi-escapes.
first
second
third
from ansi-escapes.
Yeah, my guess is it's an OS X versioning thing. Let me dig really quick.
from ansi-escapes.
what does this output?
$ infocmp $TERM | grep -Eo '( sc=\\E..)|( rc=\\E..)'
from ansi-escapes.
rc=\E8,
sc=\E7,
from ansi-escapes.
Interesting. Your Terminfo is indicating it's correct, but Terminal.app doesn't seem to like it. Still pretty convinced this is an OS X versioning thing.
I don't know what else to suggest other than to not use Terminal.app if you absolutely need this functionality. Or, upgrade OS X :P
Sorry I'm not more helpful >.<
from ansi-escapes.
You said not to count on process.stdout.rows
. I'm assuming the same applies for columns?
Is there a better to reliably detect column width?
from ansi-escapes.
Eh, in my experience neither of them have been reliable. They're both obtained by the same mechanism, tput
(tput rows
and tput cols
), but for similar reasons as cursor positioning (age of terminal technology, etc.) I don't put a whole lot of trust into those values. I've had cases where they both return 0
. I know multiplexers such as tmux
have historically caused all sorts of trouble with positioning within TTY sessions.
However I don't know of any other way to get those values.
Side note: In all honesty I bet Windows has more reliable results simply because their ConsoleXXX
functions work directly with their proprietary command prompt. Again, purely speculation.
from ansi-escapes.
So the gist of this is that everything is broken, unreliable, and inconsistent...
Depending on how complete we want this to be, it might be time to start looking at Termcap parsing like we've entertained before.
I would really prefer not having to go down that route.
Your Terminfo is indicating it's correct, but Terminal.app doesn't seem to like it.
So much for depending on termcap :p
Could we just output both? (7
and s
) It seems terminals will pick either, not both.
Another solution would be to just use 7/8 when it's Terminal.app.
from ansi-escapes.
I would really prefer not having to go down that route.
Agreed. I mean yeah it would be 'complete' but I think one of the upper-hands we have with the Chalk family is that we're pretty dern lightweight. Termcap parsing would introduce a considerable overhead.
So much for depending on termcap
Termcap isn't wrong here; termcap goes off of whatever is in TERM
. It's Apple's fault they allow TERM
to be set to something they don't fully support.
At least it's been fixed, but I mean... Apple has had almost 40 years to figure this stuff out (Apple ][, looking at you. You could have fixed this. 👊)
Could we just output both?
I mean, I don't see anything wrong with it at face value but I'd put money on the probability of some wacky terminal treating it weird. Could be useful to investigate.
Another solution would be to just use 7/8 when it's Terminal.app.
That wouldn't make any difference in this particular case.
from ansi-escapes.
That wouldn't make any difference in this particular case.
Why not? According to James it works in Terminal.app. Or did I miss something in the discussion?
from ansi-escapes.
Actually I don't think @jamestalmage ever definitively specified if this was a Terminal.app problem. I assumed it was because you mentioned it.
from ansi-escapes.
Yep my problem was Terminal.app.
Based on your comments here, I've abandoned cursor positioning for what I was trying to do.
from ansi-escapes.
Related Issues (17)
- More escapes! fun! HOT 1
- checksum error at yarn install HOT 1
- Save/Restore cursor position not working on macOS Terminal.app
- link error HOT 1
- Support tmux passing escapes through tmux HOT 2
- `clearTerminal` not working on Windows 10 w/ GitBash HOT 2
- Get x, y from the result of cursorGetPosition HOT 7
- clearScreen performs a full reset on some terminals HOT 7
- V5 Update error HOT 1
- Named exports instead of default export? HOT 9
- Type-fest TS errors when updating to tsc 4.8 HOT 3
- require() of ES modules is not supported. HOT 1
- Escapes for entering/exiting alternate screen HOT 1
- Exports CJS
- Failing to compile correctly when built under Vite?
- Add ConEmu-specific escape codes HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ansi-escapes.