mirror of
https://github.com/nushell/nushell.git
synced 2024-11-25 18:03:51 +01:00
Merge pull request #225 from nushell/revert-223-term_size
Revert "Switch way of doing terminal size calculation"
This commit is contained in:
commit
d126ba3296
12
Cargo.lock
generated
12
Cargo.lock
generated
@ -1867,7 +1867,6 @@ dependencies = [
|
||||
"sysinfo 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"term 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"term_size 1.0.0-beta1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"toml 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"toml-query 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -3036,16 +3035,6 @@ dependencies = [
|
||||
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "term_size"
|
||||
version = "1.0.0-beta1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termcolor"
|
||||
version = "1.0.5"
|
||||
@ -3931,7 +3920,6 @@ dependencies = [
|
||||
"checksum sysinfo 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c3e2cab189e59f72710e3dd5e1e0d5be0f6c5c999c326f2fdcdf3bf4483ec9fd"
|
||||
"checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9"
|
||||
"checksum term 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "edd106a334b7657c10b7c540a0106114feadeb4dc314513e97df481d5d966f42"
|
||||
"checksum term_size 1.0.0-beta1 (registry+https://github.com/rust-lang/crates.io-index)" = "a8a17d8699e154863becdf18e4fd28bd0be27ca72856f54daf75c00f2566898f"
|
||||
"checksum termcolor 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "96d6098003bde162e4277c70665bd87c326f5a0c3f3fbfb285787fa482d54e6e"
|
||||
"checksum termion 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6a8fb22f7cde82c8220e5aeacb3258ed7ce996142c77cba193f203515e26c330"
|
||||
"checksum termios 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "72b620c5ea021d75a735c943269bb07d30c9b77d6ac6b236bc8b5c496ef05625"
|
||||
|
@ -80,7 +80,6 @@ uuid = {version = "0.7.4", features = [ "v4", "serde" ]}
|
||||
syntect = "3.2.0"
|
||||
strip-ansi-escapes = "0.1.0"
|
||||
heim = "0.0.5"
|
||||
term_size = "1.0.0-beta1"
|
||||
|
||||
[dev-dependencies]
|
||||
pretty_assertions = "0.6.1"
|
||||
|
@ -1,5 +1,5 @@
|
||||
#![feature(option_flattening)]
|
||||
use crossterm::{cursor, Attribute, RawScreen};
|
||||
use crossterm::{cursor, terminal, Attribute, RawScreen};
|
||||
use indexmap::IndexMap;
|
||||
use nu::{
|
||||
serve_plugin, CallInfo, CommandConfig, NamedType, Plugin, ShellError, SpanSource, Spanned,
|
||||
@ -82,7 +82,7 @@ impl RenderContext {
|
||||
}
|
||||
}
|
||||
pub fn clear(&mut self) {
|
||||
self.frame_buffer = vec![(0, 0, 0); self.width * self.height];
|
||||
self.frame_buffer = vec![(0, 0, 0); self.width * self.height as usize];
|
||||
}
|
||||
|
||||
fn render_to_screen_lores(&mut self) -> Result<(), Box<dyn std::error::Error>> {
|
||||
@ -134,7 +134,6 @@ impl RenderContext {
|
||||
let fb_len = self.frame_buffer.len();
|
||||
|
||||
let cursor = cursor();
|
||||
|
||||
cursor.goto(0, 0)?;
|
||||
|
||||
while pos < (fb_len - self.width) {
|
||||
@ -191,17 +190,18 @@ impl RenderContext {
|
||||
}
|
||||
}
|
||||
pub fn update(&mut self) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let (width, height) = term_size::dimensions().unwrap();
|
||||
let terminal = terminal();
|
||||
let terminal_size = terminal.terminal_size();
|
||||
|
||||
if (self.width != width) || (self.height != height) {
|
||||
if (self.width != terminal_size.0 as usize) || (self.height != terminal_size.1 as usize) {
|
||||
let cursor = cursor();
|
||||
cursor.hide()?;
|
||||
|
||||
self.width = width + 1;
|
||||
self.width = terminal_size.0 as usize + 1;
|
||||
self.height = if self.lores_mode {
|
||||
height
|
||||
terminal_size.1 as usize
|
||||
} else {
|
||||
height * 2
|
||||
terminal_size.1 as usize * 2
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -50,17 +50,17 @@ fn paint_textview(
|
||||
starting_row: usize,
|
||||
use_color_buffer: bool,
|
||||
) -> usize {
|
||||
let terminal = terminal();
|
||||
let cursor = cursor();
|
||||
|
||||
let (width, height) = term_size::dimensions().unwrap();
|
||||
let size = terminal.terminal_size();
|
||||
|
||||
// render
|
||||
let mut pos = 0;
|
||||
// account for the off-by-one
|
||||
let width = width + 1;
|
||||
let width = size.0 as usize + 1;
|
||||
let height = size.1 as usize;
|
||||
let mut frame_buffer = vec![]; //(' ', 0, 0, 0); max_pos];
|
||||
|
||||
// TODO: Cache the full buffer and only recreate it if the terminal size changes
|
||||
for command in draw_commands {
|
||||
match command {
|
||||
DrawCommand::DrawString(style, string) => {
|
||||
@ -112,7 +112,7 @@ fn paint_textview(
|
||||
}
|
||||
|
||||
if buffer_needs_scrolling {
|
||||
let _ = cursor.goto(0, height as u16);
|
||||
let _ = cursor.goto(0, size.1);
|
||||
print!(
|
||||
"{}",
|
||||
ansi_term::Colour::Blue.paint("[ESC to quit, arrow keys to move]")
|
||||
@ -136,11 +136,11 @@ fn scroll_view_lines_if_needed(draw_commands: Vec<DrawCommand>, use_color_buffer
|
||||
let _ = input.read_async();
|
||||
|
||||
let terminal = terminal();
|
||||
let (mut width, mut height) = term_size::dimensions().unwrap();
|
||||
let mut size = terminal.terminal_size();
|
||||
let mut max_bottom_line = paint_textview(&draw_commands, starting_row, use_color_buffer);
|
||||
|
||||
// Only scroll if needed
|
||||
if max_bottom_line > height {
|
||||
if max_bottom_line > size.1 as usize {
|
||||
loop {
|
||||
if rawkey.is_pressed(rawkey::KeyCode::Escape) {
|
||||
break;
|
||||
@ -153,23 +153,23 @@ fn scroll_view_lines_if_needed(draw_commands: Vec<DrawCommand>, use_color_buffer
|
||||
}
|
||||
}
|
||||
if rawkey.is_pressed(rawkey::KeyCode::DownArrow) {
|
||||
if starting_row < (max_bottom_line - height) {
|
||||
if starting_row < (max_bottom_line - size.1 as usize) {
|
||||
starting_row += 1;
|
||||
}
|
||||
max_bottom_line =
|
||||
paint_textview(&draw_commands, starting_row, use_color_buffer);
|
||||
}
|
||||
if rawkey.is_pressed(rawkey::KeyCode::PageUp) {
|
||||
starting_row -= std::cmp::min(height, starting_row);
|
||||
starting_row -= std::cmp::min(size.1 as usize, starting_row);
|
||||
max_bottom_line =
|
||||
paint_textview(&draw_commands, starting_row, use_color_buffer);
|
||||
}
|
||||
if rawkey.is_pressed(rawkey::KeyCode::PageDown) {
|
||||
if starting_row < (max_bottom_line - height) {
|
||||
starting_row += height;
|
||||
if starting_row < (max_bottom_line - size.1 as usize) {
|
||||
starting_row += size.1 as usize;
|
||||
|
||||
if starting_row > (max_bottom_line - height) {
|
||||
starting_row = max_bottom_line - height;
|
||||
if starting_row > (max_bottom_line - size.1 as usize) {
|
||||
starting_row = max_bottom_line - size.1 as usize;
|
||||
}
|
||||
}
|
||||
max_bottom_line =
|
||||
@ -178,11 +178,9 @@ fn scroll_view_lines_if_needed(draw_commands: Vec<DrawCommand>, use_color_buffer
|
||||
|
||||
thread::sleep(Duration::from_millis(50));
|
||||
|
||||
let new_size = term_size::dimensions().unwrap();
|
||||
if width != new_size.0 || height != new_size.1 {
|
||||
width = new_size.0;
|
||||
height = new_size.1;
|
||||
|
||||
let new_size = terminal.terminal_size();
|
||||
if size != new_size {
|
||||
size = new_size;
|
||||
let _ = terminal.clear(crossterm::ClearType::All);
|
||||
max_bottom_line =
|
||||
paint_textview(&draw_commands, starting_row, use_color_buffer);
|
||||
|
Loading…
Reference in New Issue
Block a user