-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
RFC: Use real terminal size for show (fix #7295 and #4513) #7297
Conversation
@@ -596,6 +596,7 @@ function check_metadata() | |||
end | |||
|
|||
function warnbanner(msg...; label="[ WARNING ]", prefix="") | |||
cols = Base.tty_size()[1] | |||
warn(prefix="", Base.cpad(label,Base.tty_cols(),"=")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still using tty_cols. Is that intended?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, looks like I didn't finish making those changes. I'll fix.
The only way to get this info for Mintty is through SIGWICH, or by sending a VT100 sequence to poll for it (currently we just hardcode a size) |
AFAIK SIGWINCH only tells you that the terminal size has changed, not what it is. In any case, if |
Mintty isn't a tty, its a pipe. And the libuv folks have mostly ignored my PR so far |
Deprecation? These functions are definitely used by packages, and printing methods are typically not well tested. |
I realized that the REPL uses size without try, so if it might fail on a normal system would probably already know about it.
These were never exported, but there are a decent number of packages that use them.
Added deprecation warnings (not using |
This PR makes me so happy. |
FWIW, here's a place where you'd want to get just one dimension of the size: https://github.com/JuliaStats/DataFrames.jl/blob/master/src/dataframe/io.jl#L1079 |
I'm not entirely set on the API change, since I don't think performance matters here, but there is some logic to returning both the rows and the columns since that's what the syscall gives us. |
I'm not opposed to it. Just noting that there are cases where you only want 1 of the 2. Was originally thinking you'd support a |
We could do that too (or even keep |
function tty_rows() | ||
depwarn("tty_rows() is deprecated, use tty_size() instead", :tty_rows) | ||
tty_size()[1] | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't this be done with
@deprecate tty_rows() tty_size()[1]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was my first thought, but @deprecate
calls export tty_rows
, which seems undesirable since tty_rows
was not previously exported.
Ok ready to merge I think? |
Does this still allow you to override the TTY size using the |
Shouldn't ijulia be making it's own Terminal type? |
@vtjnash, I'm not sure exactly what you're proposing. The IJulia interface is not really a "terminal" in the usual sense, and the current Couldn't |
That would be fine with me. |
ah, yes. tty_size() = isdefined(Base, :active_repl) ? tty_size(REPL.outstream(Base.active_repl)) : tty_size(TextTerminals)
tty_size(os::Terminals.TTYTerminal) = size(os)
tty_size(::Any) = tty_size(TextTerminals)
tty_size(::Type{TextTerminals}) = (get(ENV, "LINES", 24), get(ENV, "COLUMNS", 80) |
Using the environment for that may not be the best approach in the longer term but for now that seems ok. I guess an advantage of using the environment is that it propagates to child processes. |
As discussed in #4117/#5709, what we really want is to find a way to get the terminal size to |
There might be an argument for passing |
Replaces
tty_rows()
/tty_cols()
withtty_size()
, which (through Terminals) callsuv_tty_get_winsize()
to get the terminal size.The reason for the change is that
uv_tty_get_winsize()
gives both the rows and columns, so if we wanted to keeptty_rows()
/tty_cols()
, we'd have to calluv_tty_get_winsize()
once for each, even though they are nearly always used together. AFAIK none of the methods whose signatures I've changed were ever exported, but this could still break some packages.I am assuming that calling
uv_tty_get_winsize()
is not expensive enough that it's worth registering a SIGWINCH handler and only updating the numbers on window resize, as readline used to do. My Linux system can do >10^6 calls totty_size()
per second, which seems plenty fast to me. Given how cheap the call is, it may not even be worth replacingtty_rows()
/tty_cols()
. Of course other platforms may be different.