-
Notifications
You must be signed in to change notification settings - Fork 8
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
Terminal size issues #2
Comments
The only real downside to this is you have to have a dependency on windows-sys (i think that's the crate terminal-size uses). But if you were including terminal-size, you'd have that dependency anyway. But if you decide to forward, I'd do something similar to what the term-size crate does, but in terminal-size syntax. This is the term-size syntax. It should be easy-ish to retrofit for terminal-size I think. if unsafe { GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &mut console_data) } != 0 ||
unsafe { GetConsoleScreenBufferInfo(GetStdHandle(STD_INPUT_HANDLE), &mut console_data) } != 0 ||
unsafe { GetConsoleScreenBufferInfo(GetStdHandle(STD_ERROR_HANDLE), &mut console_data) } != 0 {
Some(((console_data.srWindow.Right - console_data.srWindow.Left + 1) as usize,
(console_data.srWindow.Bottom - console_data.srWindow.Top + 1) as usize))
} else {
None
} |
I just fought this issue with my nu_plugin_dbg and came up with this solution. #[cfg(not(windows))]
fn termsize() -> usize {
use std::os::fd::AsRawFd;
// because STDOUT is redirected we need to use STDERR descriptor
let (cols, _) = match terminal_size::terminal_size_using_fd(std::io::stderr().as_raw_fd()) {
Some((w, h)) => (w.0, h.0),
None => (0, 0),
};
cols as usize
}
#[cfg(windows)]
fn termsize() -> usize {
use std::os::windows::io::RawHandle;
use windows_sys::Win32::System::Console::{GetStdHandle, STD_ERROR_HANDLE};
let stderr = unsafe { GetStdHandle(STD_ERROR_HANDLE) } as RawHandle;
// because STDOUT is redirected we need to use STDERR descriptor
let (cols, _) = match terminal_size::terminal_size_using_handle(stderr) {
Some((w, h)) => (w.0, h.0),
None => (0, 0),
};
cols as usize
} |
As
nu_plugin
is communicating over the stdout, theterminal_size
crate doesn't work in its current implementation. It's ideal to use this crate as it's actively supported, and what the rest of nushell uses.@fdncred has suggested this from discord:
Or something similar. To think about!
The text was updated successfully, but these errors were encountered: