forked from extern/nushell
Merge pull request #211 from jonathandturner/more_textview
More textview
This commit is contained in:
commit
0bca7f8b11
@ -6,6 +6,7 @@ use nu::{
|
|||||||
Value,
|
Value,
|
||||||
};
|
};
|
||||||
use pretty_hex::*;
|
use pretty_hex::*;
|
||||||
|
use std::{thread, time::Duration};
|
||||||
|
|
||||||
struct BinaryView;
|
struct BinaryView;
|
||||||
|
|
||||||
@ -444,6 +445,9 @@ pub fn view_contents_interactive(
|
|||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
let screen = RawScreen::disable_raw_mode();
|
let screen = RawScreen::disable_raw_mode();
|
||||||
|
|
||||||
|
println!("");
|
||||||
|
thread::sleep(Duration::from_millis(50));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
#![feature(option_flattening)]
|
#![feature(option_flattening)]
|
||||||
|
|
||||||
use crossterm::{cursor, input, terminal, InputEvent, KeyEvent, RawScreen};
|
use crossterm::{cursor, terminal, RawScreen};
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use nu::{
|
use nu::{
|
||||||
serve_plugin, CallInfo, CommandConfig, Plugin, Primitive, ShellError, SourceMap, SpanSource,
|
serve_plugin, CallInfo, CommandConfig, Plugin, Primitive, ShellError, SourceMap, SpanSource,
|
||||||
Spanned, Value,
|
Spanned, Value,
|
||||||
};
|
};
|
||||||
|
use rawkey::RawKey;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
use std::{thread, time::Duration};
|
||||||
|
|
||||||
struct TextView;
|
struct TextView;
|
||||||
|
|
||||||
@ -35,22 +37,13 @@ impl Plugin for TextView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scroll_view_lines(lines: Vec<String>) {
|
fn paint_textview(lines: &Vec<String>, starting_row: usize) -> (u16, u16) {
|
||||||
let mut starting_row = 0;
|
|
||||||
|
|
||||||
let terminal = terminal();
|
let terminal = terminal();
|
||||||
|
|
||||||
if let Ok(_raw) = RawScreen::into_raw_mode() {
|
|
||||||
let input = input();
|
|
||||||
let cursor = cursor();
|
let cursor = cursor();
|
||||||
|
|
||||||
let _ = cursor.hide();
|
|
||||||
|
|
||||||
let mut sync_stdin = input.read_sync();
|
|
||||||
|
|
||||||
loop {
|
|
||||||
let size = terminal.terminal_size();
|
|
||||||
let _ = terminal.clear(crossterm::ClearType::All);
|
let _ = terminal.clear(crossterm::ClearType::All);
|
||||||
|
|
||||||
|
let size = terminal.terminal_size();
|
||||||
let _ = cursor.goto(0, 0);
|
let _ = cursor.goto(0, 0);
|
||||||
|
|
||||||
let mut total_max_num_lines = 0;
|
let mut total_max_num_lines = 0;
|
||||||
@ -79,55 +72,56 @@ fn scroll_view_lines(lines: Vec<String>) {
|
|||||||
"{}",
|
"{}",
|
||||||
ansi_term::Colour::Blue.paint("[ESC to quit, arrow keys to move]")
|
ansi_term::Colour::Blue.paint("[ESC to quit, arrow keys to move]")
|
||||||
);
|
);
|
||||||
|
print!("{}", crossterm::Attribute::Reset);
|
||||||
|
|
||||||
let _ = std::io::stdout().flush();
|
let _ = std::io::stdout().flush();
|
||||||
|
|
||||||
let event = sync_stdin.next();
|
size
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(key_event) = event {
|
fn scroll_view_lines(lines: Vec<String>) {
|
||||||
match key_event {
|
let mut starting_row = 0;
|
||||||
InputEvent::Keyboard(k) => match k {
|
let rawkey = RawKey::new();
|
||||||
KeyEvent::Esc => {
|
|
||||||
|
if let Ok(_raw) = RawScreen::into_raw_mode() {
|
||||||
|
let cursor = cursor();
|
||||||
|
let _ = cursor.hide();
|
||||||
|
|
||||||
|
let input = crossterm::input();
|
||||||
|
let _ = input.read_async();
|
||||||
|
|
||||||
|
let mut size = paint_textview(&lines, starting_row);
|
||||||
|
loop {
|
||||||
|
if rawkey.is_pressed(rawkey::KeyCode::Escape) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
KeyEvent::Up => {
|
if rawkey.is_pressed(rawkey::KeyCode::UpArrow) {
|
||||||
if starting_row > 0 {
|
if starting_row > 0 {
|
||||||
starting_row -= 1;
|
starting_row -= 1;
|
||||||
|
size = paint_textview(&lines, starting_row);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
KeyEvent::Down => {
|
if rawkey.is_pressed(rawkey::KeyCode::DownArrow) {
|
||||||
if starting_row
|
if starting_row < (std::cmp::max(size.1 as usize, lines.len()) - size.1 as usize) {
|
||||||
< (std::cmp::max(size.1 as usize, lines.len()) - size.1 as usize)
|
|
||||||
{
|
|
||||||
starting_row += 1;
|
starting_row += 1;
|
||||||
|
size = paint_textview(&lines, starting_row);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
KeyEvent::PageUp => {
|
|
||||||
starting_row -= std::cmp::min(starting_row, size.1 as usize);
|
|
||||||
}
|
|
||||||
KeyEvent::Char(c) if c == ' ' => {
|
|
||||||
if starting_row
|
|
||||||
< (std::cmp::max(size.1 as usize, lines.len()) - size.1 as usize)
|
|
||||||
{
|
|
||||||
starting_row += size.1 as usize;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
KeyEvent::PageDown => {
|
|
||||||
if starting_row
|
|
||||||
< (std::cmp::max(size.1 as usize, lines.len()) - size.1 as usize)
|
|
||||||
{
|
|
||||||
starting_row += size.1 as usize;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
},
|
|
||||||
|
|
||||||
_ => {}
|
thread::sleep(Duration::from_millis(50));
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = cursor.show();
|
let _ = cursor.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let cursor = cursor();
|
||||||
|
let _ = cursor.show();
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
|
let screen = RawScreen::disable_raw_mode();
|
||||||
|
|
||||||
|
println!("");
|
||||||
|
thread::sleep(Duration::from_millis(50));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scroll_view(s: &str) {
|
fn scroll_view(s: &str) {
|
||||||
|
Loading…
Reference in New Issue
Block a user