Move binaryview to a sub-crate

This commit is contained in:
Jonathan Turner 2019-12-05 06:51:20 +13:00
parent e9ee7bda46
commit a4bb5d4ff5
5 changed files with 61 additions and 27 deletions

22
Cargo.lock generated
View file

@ -1911,14 +1911,12 @@ dependencies = [
"glob",
"heim",
"hex 0.4.0",
"image",
"indexmap",
"itertools 0.8.2",
"language-reporting",
"log",
"mime",
"natural",
"neso",
"nom 5.0.1",
"nom-tracable",
"nom_locate",
@ -1927,6 +1925,7 @@ dependencies = [
"nu-parser",
"nu-protocol",
"nu-source",
"nu_plugin_binaryview",
"nu_plugin_textview",
"num-bigint",
"num-traits 0.2.10",
@ -1939,7 +1938,6 @@ dependencies = [
"prettytable-rs",
"ptree",
"query_interface",
"rawkey",
"regex",
"roxmltree",
"rusqlite",
@ -2079,6 +2077,24 @@ dependencies = [
"termcolor",
]
[[package]]
name = "nu_plugin_binaryview"
version = "0.1.0"
dependencies = [
"ansi_term 0.12.1",
"crossterm",
"image",
"neso",
"nu-build",
"nu-errors",
"nu-protocol",
"nu-source",
"pretty-hex",
"rawkey",
"syntect",
"url",
]
[[package]]
name = "nu_plugin_textview"
version = "0.1.0"

View file

@ -13,7 +13,15 @@ documentation = "https://book.nushell.sh"
[workspace]
members = ["crates/nu-errors", "crates/nu-source", "crates/nu_plugin_textview", "crates/nu-protocol", "crates/nu-parser", "crates/nu-build"]
members = [
"crates/nu-errors",
"crates/nu-source",
"crates/nu_plugin_textview",
"crates/nu_plugin_binaryview",
"crates/nu-protocol",
"crates/nu-parser",
"crates/nu-build"
]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -23,6 +31,7 @@ nu-protocol = { version = "0.1.0", path = "./crates/nu-protocol" }
nu-errors = { version = "0.1.0", path = "./crates/nu-errors" }
nu-parser = { version = "0.1.0", path = "./crates/nu-parser" }
nu_plugin_textview = {version = "0.1.0", path = "./crates/nu_plugin_textview", optional=true}
nu_plugin_binaryview = {version = "0.1.0", path = "./crates/nu_plugin_binaryview", optional=true}
query_interface = "0.3.5"
typetag = "0.1.4"
@ -96,26 +105,22 @@ pretty = "0.5.2"
termcolor = "1.0.5"
console = "0.9.1"
neso = { version = "0.5.0", optional = true }
crossterm = { version = "0.10.2", optional = true }
syntect = {version = "3.2.0", optional = true }
onig_sys = {version = "=69.1.0", optional = true }
heim = {version = "0.0.8", optional = true }
battery = {version = "0.7.4", optional = true }
rawkey = {version = "0.1.2", optional = true }
clipboard = {version = "0.5", optional = true }
ptree = {version = "0.2" }
image = { version = "0.22.2", default_features = false, features = ["png_codec", "jpeg"], optional = true }
starship = { version = "0.26.4", optional = true}
[features]
default = ["sys", "ps"]
raw-key = ["rawkey", "neso"]
binaryview = ["image", "crossterm"]
sys = ["heim", "battery"]
ps = ["heim"]
starship-prompt = ["starship"]
textview = ["nu_plugin_textview"]
binaryview = ["nu_plugin_binaryview"]
#trace = ["nu-parser/trace"]
[dependencies.rusqlite]
@ -193,11 +198,6 @@ name = "nu_plugin_tree"
path = "src/plugins/tree.rs"
required-features = ["tree"]
[[bin]]
name = "nu_plugin_binaryview"
path = "src/plugins/binaryview.rs"
required-features = ["binaryview"]
[[bin]]
name = "nu_plugin_docker"
path = "src/plugins/docker.rs"

View file

@ -0,0 +1,23 @@
[package]
name = "nu_plugin_binaryview"
version = "0.1.0"
authors = ["Yehuda Katz <wycats@gmail.com>", "Jonathan Turner <jonathan.d.turner@gmail.com>", "Andrés N. Robalino <andres@androbtech.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
syntect = { version = "3.2.0" }
ansi_term = "0.12.1"
crossterm = { version = "0.10.2" }
nu-protocol = { path = "../nu-protocol" }
nu-source = { path = "../nu-source" }
nu-errors = { path = "../nu-errors" }
url = "2.1.0"
pretty-hex = "0.1.1"
image = { version = "0.22.2", default_features = false, features = ["png_codec", "jpeg"] }
rawkey = "0.1.2"
neso = "0.5.0"
[build-dependencies]
nu-build = { version = "0.1.0", path = "../nu-build" }

View file

@ -0,0 +1,3 @@
fn main() -> Result<(), Box<dyn std::error::Error>> {
nu_build::build()
}

View file

@ -1,7 +1,8 @@
use crossterm::{cursor, terminal, Attribute, RawScreen};
use nu::{serve_plugin, Plugin};
use nu_errors::ShellError;
use nu_protocol::{outln, CallInfo, Primitive, Signature, UntaggedValue, Value};
use nu_protocol::{
outln, serve_plugin, CallInfo, Plugin, Primitive, Signature, UntaggedValue, Value,
};
use nu_source::AnchorLocation;
use pretty_hex::*;
@ -41,17 +42,9 @@ fn view_binary(
if b.len() > 3 {
match (b[0], b[1], b[2]) {
(0x4e, 0x45, 0x53) => {
#[cfg(feature = "rawkey")]
{
view_contents_interactive(b, source, lores_mode)?;
return Ok(());
}
#[cfg(not(feature = "rawkey"))]
{
outln!("Interactive binary viewing currently requires the 'rawkey' feature");
return Ok(());
}
}
_ => {}
}
}
@ -338,7 +331,6 @@ pub fn view_contents(
Ok(())
}
#[cfg(feature = "rawkey")]
pub fn view_contents_interactive(
buffer: &[u8],
source: Option<&AnchorLocation>,