forked from extern/nushell
Fix push/pop for shell manager
This commit is contained in:
parent
fef447a659
commit
953d28ef74
@ -140,19 +140,21 @@ impl InternalCommand {
|
|||||||
}
|
}
|
||||||
CommandAction::Exit => std::process::exit(0),
|
CommandAction::Exit => std::process::exit(0),
|
||||||
CommandAction::EnterValueShell(value) => {
|
CommandAction::EnterValueShell(value) => {
|
||||||
context.shell_manager.push(Box::new(ValueShell::new(value)));
|
context
|
||||||
|
.shell_manager
|
||||||
|
.insert_at_current(Box::new(ValueShell::new(value)));
|
||||||
}
|
}
|
||||||
CommandAction::EnterShell(location) => {
|
CommandAction::EnterShell(location) => {
|
||||||
let path = std::path::Path::new(&location);
|
let path = std::path::Path::new(&location);
|
||||||
|
|
||||||
if path.is_dir() {
|
if path.is_dir() {
|
||||||
// If it's a directory, add a new filesystem shell
|
// If it's a directory, add a new filesystem shell
|
||||||
context
|
context.shell_manager.insert_at_current(Box::new(
|
||||||
.shell_manager
|
FilesystemShell::with_location(
|
||||||
.push(Box::new(FilesystemShell::with_location(
|
|
||||||
location,
|
location,
|
||||||
context.registry().clone(),
|
context.registry().clone(),
|
||||||
)?));
|
)?,
|
||||||
|
));
|
||||||
} else {
|
} else {
|
||||||
// If it's a file, attempt to open the file as a value and enter it
|
// If it's a file, attempt to open the file as a value and enter it
|
||||||
let cwd = context.shell_manager.path();
|
let cwd = context.shell_manager.path();
|
||||||
@ -180,11 +182,13 @@ impl InternalCommand {
|
|||||||
Span::unknown(),
|
Span::unknown(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
context.shell_manager.push(Box::new(ValueShell::new(value)));
|
context
|
||||||
}
|
|
||||||
value => context
|
|
||||||
.shell_manager
|
.shell_manager
|
||||||
.push(Box::new(ValueShell::new(value.tagged(contents_tag)))),
|
.insert_at_current(Box::new(ValueShell::new(value)));
|
||||||
|
}
|
||||||
|
value => context.shell_manager.insert_at_current(Box::new(
|
||||||
|
ValueShell::new(value.tagged(contents_tag)),
|
||||||
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -195,7 +199,7 @@ impl InternalCommand {
|
|||||||
context.shell_manager.next();
|
context.shell_manager.next();
|
||||||
}
|
}
|
||||||
CommandAction::LeaveShell => {
|
CommandAction::LeaveShell => {
|
||||||
context.shell_manager.pop();
|
context.shell_manager.remove_at_current();
|
||||||
if context.shell_manager.is_empty() {
|
if context.shell_manager.is_empty() {
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
}
|
}
|
||||||
|
@ -23,19 +23,30 @@ impl ShellManager {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn push(&mut self, shell: Box<dyn Shell + Send>) {
|
pub fn insert_at_current(&mut self, shell: Box<dyn Shell + Send>) {
|
||||||
self.shells.lock().unwrap().push(shell);
|
self.shells.lock().unwrap().push(shell);
|
||||||
self.current_shell = self.shells.lock().unwrap().len() - 1;
|
self.current_shell = self.shells.lock().unwrap().len() - 1;
|
||||||
self.set_path(self.path());
|
self.set_path(self.path());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pop(&mut self) {
|
pub fn remove_at_current(&mut self) {
|
||||||
self.shells.lock().unwrap().pop();
|
{
|
||||||
let new_len = self.shells.lock().unwrap().len();
|
let mut shells = self.shells.lock().unwrap();
|
||||||
|
if shells.len() > 0 {
|
||||||
|
if self.current_shell == shells.len() - 1 {
|
||||||
|
shells.pop();
|
||||||
|
let new_len = shells.len();
|
||||||
if new_len > 0 {
|
if new_len > 0 {
|
||||||
self.current_shell = new_len - 1;
|
self.current_shell = new_len - 1;
|
||||||
self.set_path(self.path());
|
} else {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
shells.remove(self.current_shell);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.set_path(self.path());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
|
@ -45,9 +45,11 @@ fn knows_the_filesystems_entered() {
|
|||||||
n
|
n
|
||||||
mv andres.nu ../expected/andres.nu
|
mv andres.nu ../expected/andres.nu
|
||||||
exit
|
exit
|
||||||
|
n
|
||||||
cd ..
|
cd ..
|
||||||
rm red_pill --recursive
|
rm red_pill --recursive
|
||||||
exit
|
exit
|
||||||
|
n
|
||||||
rm blue_pill --recursive
|
rm blue_pill --recursive
|
||||||
exit
|
exit
|
||||||
"#
|
"#
|
||||||
|
Loading…
Reference in New Issue
Block a user