Improve enter and fix bugs

This commit is contained in:
Jonathan Turner 2019-08-11 08:18:14 +12:00
parent 357ab46b58
commit 8f78995014
11 changed files with 54 additions and 17 deletions

View File

@ -51,7 +51,10 @@ pub fn autoview(
let result = table.run(raw.with_input(input), &context.commands).await.unwrap();
result.collect::<Vec<_>>().await;
} else {
println!("TODO!")
let table = context.expect_command("table");
let result = table.run(raw.with_input(input), &context.commands).await.unwrap();
result.collect::<Vec<_>>().await;
//println!("TODO!")
// TODO
// let mut host = context.host.lock().unwrap();
// for i in input.iter() {

View File

@ -158,13 +158,18 @@ impl InternalCommand {
let full_path = std::path::PathBuf::from(cwd);
let (file_extension, contents, contents_tag, _) =
let (file_extension, contents, contents_tag, span_source) =
crate::commands::open::fetch(
&full_path,
&location,
Span::unknown(),
)?;
if let Some(uuid) = contents_tag.origin {
// If we have loaded something, track its source
context.add_span_source(uuid, span_source);
}
match contents {
Value::Primitive(Primitive::String(string)) => {
let value = crate::commands::open::parse_as_value(
@ -178,7 +183,7 @@ impl InternalCommand {
}
value => context
.shell_manager
.push(Box::new(ValueShell::new(value.tagged(Tag::unknown())))),
.push(Box::new(ValueShell::new(value.tagged(contents_tag)))),
}
}
}

View File

@ -226,6 +226,7 @@ pub fn fetch(
}
} else {
cwd.push(Path::new(location));
let cwd = dunce::canonicalize(cwd).unwrap();
match std::fs::read(&cwd) {
Ok(bytes) => match std::str::from_utf8(&bytes) {
Ok(s) => Ok((

View File

@ -6,9 +6,17 @@ pub fn shells(args: CommandArgs, _registry: &CommandRegistry) -> Result<OutputSt
let mut shells_out = VecDeque::new();
let span = args.call_info.name_span;
for shell in args.shell_manager.shells.lock().unwrap().iter() {
let shells_len = args.shell_manager.shells.lock().unwrap().len();
for (index, shell) in args.shell_manager.shells.lock().unwrap().iter().enumerate() {
let mut dict = TaggedDictBuilder::new(Tag::unknown_origin(span));
dict.insert("name", shell.name());
if index == (shells_len - 1) {
dict.insert(" ", "X".to_string());
} else {
dict.insert(" ", " ".to_string());
}
dict.insert("name", shell.name(&args.call_info.source_map));
dict.insert("path", shell.path());
shells_out.push_back(dict.into_tagged_value());

View File

@ -15,16 +15,17 @@ pub fn tags(args: CommandArgs, _registry: &CommandRegistry) -> Result<OutputStre
let mut dict = TaggedDictBuilder::new(v.tag());
dict.insert("start", Value::int(span.start as i64));
dict.insert("end", Value::int(span.end as i64));
tags.insert_tagged("span", dict.into_tagged_value());
match origin.map(|x| source_map.get(&x)).flatten() {
Some(SpanSource::File(source)) => {
dict.insert("origin", Value::string(source));
tags.insert("origin", Value::string(source));
}
Some(SpanSource::Url(source)) => {
dict.insert("origin", Value::string(source));
tags.insert("origin", Value::string(source));
}
_ => {}
}
tags.insert_tagged("span", dict.into_tagged_value());
}
tags.into_tagged_value()

View File

@ -204,7 +204,7 @@ impl fmt::Debug for ValueDebug<'a> {
impl Tagged<Value> {
crate fn tagged_type_name(&self) -> Tagged<String> {
let name = self.type_name();
Tagged::from_simple_spanned_item(name, self.span())
Tagged::from_item(name, self.tag())
}
}

View File

@ -1,3 +1,4 @@
use crate::context::{SourceMap, SpanSource};
use crate::prelude::*;
use crate::Text;
use derive_new::new;
@ -108,6 +109,14 @@ impl<T> Tagged<T> {
self.tag.origin
}
pub fn origin_name(&self, source_map: &SourceMap) -> Option<String> {
match self.tag.origin.map(|x| source_map.get(&x)) {
Some(Some(SpanSource::File(file))) => Some(file.clone()),
Some(Some(SpanSource::Url(url))) => Some(url.clone()),
_ => None,
}
}
pub fn item(&self) -> &T {
&self.item
}

View File

@ -1,4 +1,5 @@
use crate::commands::command::EvaluatedStaticCommandArgs;
use crate::context::SourceMap;
use crate::object::dir_entry_dict;
use crate::prelude::*;
use crate::shell::completer::NuCompleter;
@ -55,7 +56,7 @@ impl FilesystemShell {
}
impl Shell for FilesystemShell {
fn name(&self) -> String {
fn name(&self, _source_map: &SourceMap) -> String {
"filesystem".to_string()
}

View File

@ -1,9 +1,10 @@
use crate::commands::command::EvaluatedStaticCommandArgs;
use crate::context::SourceMap;
use crate::errors::ShellError;
use crate::stream::OutputStream;
pub trait Shell {
fn name(&self) -> String;
fn name(&self, source_map: &SourceMap) -> String;
fn ls(&self, args: EvaluatedStaticCommandArgs) -> Result<OutputStream, ShellError>;
fn cd(&self, args: EvaluatedStaticCommandArgs) -> Result<OutputStream, ShellError>;
fn path(&self) -> String;

View File

@ -73,8 +73,8 @@ impl ShellManager {
pub fn next(&mut self) {
{
let mut x = self.shells.lock().unwrap();
let shell = x.pop().unwrap();
x.insert(0, shell);
let shell = x.remove(0);
x.push(shell);
}
self.set_path(self.path());
}
@ -82,8 +82,8 @@ impl ShellManager {
pub fn prev(&mut self) {
{
let mut x = self.shells.lock().unwrap();
let shell = x.remove(0);
x.push(shell);
let shell = x.pop().unwrap();
x.insert(0, shell);
}
self.set_path(self.path());
}

View File

@ -1,4 +1,5 @@
use crate::commands::command::EvaluatedStaticCommandArgs;
use crate::context::SourceMap;
use crate::prelude::*;
use crate::shell::shell::Shell;
use std::ffi::OsStr;
@ -53,8 +54,15 @@ impl ValueShell {
}
impl Shell for ValueShell {
fn name(&self) -> String {
"value".to_string()
fn name(&self, source_map: &SourceMap) -> String {
let origin_name = self.value.origin_name(source_map);
format!(
"{}",
match origin_name {
Some(x) => format!("{{{}}}", x),
None => format!("<{}>", self.value.item.type_name(),),
}
)
}
fn ls(&self, _args: EvaluatedStaticCommandArgs) -> Result<OutputStream, ShellError> {