mirror of
https://github.com/nushell/nushell.git
synced 2024-11-24 17:34:00 +01:00
Merge branch 'master' of https://github.com/nushell/nushell
This commit is contained in:
commit
c69bf9f46f
5
Cargo.lock
generated
5
Cargo.lock
generated
@ -1911,7 +1911,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "nu"
|
||||
version = "0.7.1"
|
||||
version = "0.7.2"
|
||||
dependencies = [
|
||||
"ansi_term 0.12.1",
|
||||
"app_dirs",
|
||||
@ -2973,8 +2973,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "rustyline"
|
||||
version = "5.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3ae156e2a68be20a3ae95574089b65c188d86291cd5421cc647222b8d1864ffb"
|
||||
source = "git+https://github.com/kkawakam/rustyline.git#55dcab54fbab0ba0610799291276785e5b31199c"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"dirs 2.0.2",
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "nu"
|
||||
version = "0.7.1"
|
||||
version = "0.7.2"
|
||||
authors = ["Yehuda Katz <wycats@gmail.com>", "Jonathan Turner <jonathan.d.turner@gmail.com>", "Andrés N. Robalino <andres@androbtech.com>"]
|
||||
description = "A shell for the GitHub era"
|
||||
license = "MIT"
|
||||
@ -60,7 +60,7 @@ nu-macros = { version = "0.7.0", path = "./crates/nu-macros" }
|
||||
|
||||
query_interface = "0.3.5"
|
||||
typetag = "0.1.4"
|
||||
rustyline = "5.0.4"
|
||||
rustyline = { git = "https://github.com/kkawakam/rustyline.git" }
|
||||
chrono = { version = "0.4.10", features = ["serde"] }
|
||||
derive-new = "0.5.8"
|
||||
prettytable-rs = "0.8.0"
|
||||
|
@ -113,7 +113,7 @@ pub fn format_primitive(primitive: &Primitive, field_name: Option<&String>) -> S
|
||||
}
|
||||
Primitive::Duration(sec) => format_duration(*sec),
|
||||
Primitive::Int(i) => i.to_string(),
|
||||
Primitive::Decimal(decimal) => decimal.to_string(),
|
||||
Primitive::Decimal(decimal) => format!("{:.4}", decimal),
|
||||
Primitive::Range(range) => format!(
|
||||
"{}..{}",
|
||||
format_primitive(&range.from.0.item, None),
|
||||
|
@ -3,7 +3,7 @@ use futures::executor::block_on;
|
||||
|
||||
use futures_util::{StreamExt, TryStreamExt};
|
||||
use heim::process::{self as process, Process, ProcessResult};
|
||||
use heim::units::{ratio, Ratio};
|
||||
use heim::units::{information, ratio, Ratio};
|
||||
use std::usize;
|
||||
|
||||
use nu_errors::ShellError;
|
||||
@ -22,12 +22,14 @@ impl Ps {
|
||||
}
|
||||
}
|
||||
|
||||
async fn usage(process: Process) -> ProcessResult<(process::Process, Ratio)> {
|
||||
async fn usage(process: Process) -> ProcessResult<(process::Process, Ratio, process::Memory)> {
|
||||
let usage_1 = process.cpu_usage().await?;
|
||||
futures_timer::Delay::new(Duration::from_millis(100)).await;
|
||||
let usage_2 = process.cpu_usage().await?;
|
||||
|
||||
Ok((process, usage_2 - usage_1))
|
||||
let memory = process.memory().await?;
|
||||
|
||||
Ok((process, usage_2 - usage_1, memory))
|
||||
}
|
||||
|
||||
async fn ps(tag: Tag) -> Vec<Value> {
|
||||
@ -43,7 +45,7 @@ async fn ps(tag: Tag) -> Vec<Value> {
|
||||
|
||||
let mut output = vec![];
|
||||
while let Some(res) = processes.next().await {
|
||||
if let Ok((process, usage)) = res {
|
||||
if let Ok((process, usage, memory)) = res {
|
||||
let mut dict = TaggedDictBuilder::new(&tag);
|
||||
dict.insert_untagged("pid", UntaggedValue::int(process.pid()));
|
||||
if let Ok(name) = process.name().await {
|
||||
@ -53,6 +55,14 @@ async fn ps(tag: Tag) -> Vec<Value> {
|
||||
dict.insert_untagged("status", UntaggedValue::string(format!("{:?}", status)));
|
||||
}
|
||||
dict.insert_untagged("cpu", UntaggedValue::decimal(usage.get::<ratio::percent>()));
|
||||
dict.insert_untagged(
|
||||
"mem",
|
||||
UntaggedValue::bytes(memory.rss().get::<information::byte>()),
|
||||
);
|
||||
dict.insert_untagged(
|
||||
"virtual",
|
||||
UntaggedValue::bytes(memory.vms().get::<information::byte>()),
|
||||
);
|
||||
output.push(dict.into_value());
|
||||
}
|
||||
}
|
||||
|
@ -170,29 +170,17 @@ pub(crate) async fn run_external_command(
|
||||
|
||||
let name_tag = command.name_tag.clone();
|
||||
if let Ok(mut popen) = popen {
|
||||
popen.detach();
|
||||
match stream_next {
|
||||
StreamNext::Last => {
|
||||
popen.detach();
|
||||
loop {
|
||||
match popen.poll() {
|
||||
None => {
|
||||
std::thread::sleep(std::time::Duration::new(0, 100_000_000));
|
||||
}
|
||||
_ => {
|
||||
let _ = popen.terminate();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
let _ = popen.wait();
|
||||
Ok(ClassifiedInputStream::new())
|
||||
}
|
||||
StreamNext::External => {
|
||||
popen.detach();
|
||||
let stdout = popen.stdout.take().unwrap();
|
||||
Ok(ClassifiedInputStream::from_stdout(stdout))
|
||||
}
|
||||
StreamNext::Internal => {
|
||||
popen.detach();
|
||||
let stdout = popen.stdout.take().unwrap();
|
||||
let file = futures::io::AllowStdIo::new(stdout);
|
||||
let stream = Framed::new(file, LinesCodec {});
|
||||
|
@ -505,10 +505,13 @@ impl Command {
|
||||
let call_info = raw_args
|
||||
.clone()
|
||||
.call_info
|
||||
.evaluate(®istry, &Scope::it_value(x.clone()))
|
||||
.unwrap();
|
||||
match command.run(&call_info, ®istry, &raw_args, x) {
|
||||
Ok(o) => o,
|
||||
.evaluate(®istry, &Scope::it_value(x.clone()));
|
||||
|
||||
match call_info {
|
||||
Ok(call_info) => match command.run(&call_info, ®istry, &raw_args, x) {
|
||||
Ok(o) => o,
|
||||
Err(e) => VecDeque::from(vec![ReturnValue::Err(e)]).to_output_stream(),
|
||||
},
|
||||
Err(e) => VecDeque::from(vec![ReturnValue::Err(e)]).to_output_stream(),
|
||||
}
|
||||
})
|
||||
|
@ -140,7 +140,9 @@ impl PrettyDebug for FormatInlineShape {
|
||||
match &self.shape {
|
||||
InlineShape::Nothing => b::blank(),
|
||||
InlineShape::Int(int) => b::primitive(format!("{}", int)),
|
||||
InlineShape::Decimal(decimal) => b::primitive(format!("{}", decimal)),
|
||||
InlineShape::Decimal(decimal) => {
|
||||
b::description(format_primitive(&Primitive::Decimal(decimal.clone()), None))
|
||||
}
|
||||
InlineShape::Range(range) => {
|
||||
let (left, left_inclusion) = &range.from;
|
||||
let (right, right_inclusion) = &range.to;
|
||||
|
@ -166,20 +166,20 @@ fn evaluate_reference(
|
||||
match name {
|
||||
hir::Variable::It(_) => Ok(scope.it.value.clone().into_value(tag)),
|
||||
hir::Variable::Other(inner) => match inner.slice(source) {
|
||||
x if x == "nu:env" => {
|
||||
x if x == "nu" => {
|
||||
let mut nu_dict = TaggedDictBuilder::new(&tag);
|
||||
|
||||
let mut dict = TaggedDictBuilder::new(&tag);
|
||||
for v in std::env::vars() {
|
||||
if v.0 != "PATH" && v.0 != "Path" {
|
||||
dict.insert_untagged(v.0, UntaggedValue::string(v.1));
|
||||
}
|
||||
}
|
||||
Ok(dict.into_value())
|
||||
}
|
||||
x if x == "nu:config" => {
|
||||
let config = crate::data::config::read(tag.clone(), &None)?;
|
||||
Ok(UntaggedValue::row(config).into_value(tag))
|
||||
}
|
||||
x if x == "nu:path" => {
|
||||
nu_dict.insert_value("env", dict.into_value());
|
||||
|
||||
let config = crate::data::config::read(&tag, &None)?;
|
||||
nu_dict.insert_value("config", UntaggedValue::row(config).into_value(&tag));
|
||||
|
||||
let mut table = vec![];
|
||||
let path = std::env::var_os("PATH");
|
||||
if let Some(paths) = path {
|
||||
@ -187,7 +187,9 @@ fn evaluate_reference(
|
||||
table.push(UntaggedValue::path(path).into_value(&tag));
|
||||
}
|
||||
}
|
||||
Ok(UntaggedValue::table(&table).into_value(tag))
|
||||
nu_dict.insert_value("path", UntaggedValue::table(&table).into_value(&tag));
|
||||
|
||||
Ok(nu_dict.into_value())
|
||||
}
|
||||
x => Ok(scope
|
||||
.vars
|
||||
|
@ -3,7 +3,7 @@ use futures::executor::block_on;
|
||||
|
||||
use futures_util::{StreamExt, TryStreamExt};
|
||||
use heim::process::{self as process, Process, ProcessResult};
|
||||
use heim::units::{ratio, Ratio};
|
||||
use heim::units::{information, ratio, Ratio};
|
||||
use std::usize;
|
||||
|
||||
use nu_errors::ShellError;
|
||||
@ -22,12 +22,14 @@ impl Ps {
|
||||
}
|
||||
}
|
||||
|
||||
async fn usage(process: Process) -> ProcessResult<(process::Process, Ratio)> {
|
||||
async fn usage(process: Process) -> ProcessResult<(process::Process, Ratio, process::Memory)> {
|
||||
let usage_1 = process.cpu_usage().await?;
|
||||
futures_timer::Delay::new(Duration::from_millis(100)).await;
|
||||
let usage_2 = process.cpu_usage().await?;
|
||||
|
||||
Ok((process, usage_2 - usage_1))
|
||||
let memory = process.memory().await?;
|
||||
|
||||
Ok((process, usage_2 - usage_1, memory))
|
||||
}
|
||||
|
||||
async fn ps(tag: Tag) -> Vec<Value> {
|
||||
@ -43,7 +45,7 @@ async fn ps(tag: Tag) -> Vec<Value> {
|
||||
|
||||
let mut output = vec![];
|
||||
while let Some(res) = processes.next().await {
|
||||
if let Ok((process, usage)) = res {
|
||||
if let Ok((process, usage, memory)) = res {
|
||||
let mut dict = TaggedDictBuilder::new(&tag);
|
||||
dict.insert_untagged("pid", UntaggedValue::int(process.pid()));
|
||||
if let Ok(name) = process.name().await {
|
||||
@ -53,6 +55,14 @@ async fn ps(tag: Tag) -> Vec<Value> {
|
||||
dict.insert_untagged("status", UntaggedValue::string(format!("{:?}", status)));
|
||||
}
|
||||
dict.insert_untagged("cpu", UntaggedValue::decimal(usage.get::<ratio::percent>()));
|
||||
dict.insert_untagged(
|
||||
"mem",
|
||||
UntaggedValue::bytes(memory.rss().get::<information::byte>()),
|
||||
);
|
||||
dict.insert_untagged(
|
||||
"virtual",
|
||||
UntaggedValue::bytes(memory.vms().get::<information::byte>()),
|
||||
);
|
||||
output.push(dict.into_value());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user