summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/event.rs8
-rw-r--r--src/parse.rs16
-rw-r--r--src/state/history/mod.rs34
-rw-r--r--src/state/mod.rs8
-rw-r--r--src/state/readline.rs4
5 files changed, 32 insertions, 38 deletions
diff --git a/src/event.rs b/src/event.rs
index 7adc2e7..85a2127 100644
--- a/src/event.rs
+++ b/src/event.rs
@@ -44,7 +44,7 @@ impl Reader {
async fn new_event(&self, event: Option<Event>) {
let mut pending = self.pending.lock().await;
- pending.new_event(&event);
+ pending.new_event(event);
self.cvar.notify_one();
}
}
@@ -101,10 +101,10 @@ impl Pending {
unreachable!()
}
- fn new_event(&mut self, event: &Option<Event>) {
+ fn new_event(&mut self, event: Option<Event>) {
match event {
- Some(Event::Key(key)) => self.key.push_back(key.clone()),
- Some(Event::Resize(size)) => self.size = Some(*size),
+ Some(Event::Key(key)) => self.key.push_back(key),
+ Some(Event::Resize(size)) => self.size = Some(size),
Some(Event::PtyOutput) => self.pty_output = true,
Some(Event::PtyClose) => self.pty_close = true,
Some(Event::ClockTimer) => self.clock_timer = true,
diff --git a/src/parse.rs b/src/parse.rs
index 4bdbce2..45c83c5 100644
--- a/src/parse.rs
+++ b/src/parse.rs
@@ -4,7 +4,7 @@ use pest::Parser as _;
#[grammar = "shell.pest"]
struct Shell;
-#[derive(Debug, Clone)]
+#[derive(Debug)]
pub struct Word {
word: String,
interpolate: bool,
@@ -28,7 +28,7 @@ impl Word {
}
}
-#[derive(Debug, Clone)]
+#[derive(Debug)]
pub struct Exe {
exe: Word,
args: Vec<Word>,
@@ -56,7 +56,7 @@ impl Exe {
}
}
-#[derive(Debug, Clone)]
+#[derive(Debug)]
pub struct Pipeline {
exes: Vec<Exe>,
input_string: String,
@@ -90,7 +90,7 @@ impl Pipeline {
}
}
-#[derive(Debug, Clone)]
+#[derive(Debug)]
pub struct Commands {
pipelines: Vec<Pipeline>,
input_string: String,
@@ -144,12 +144,8 @@ impl Error {
}
}
- pub fn input(&self) -> &str {
- &self.input
- }
-
- pub fn error(&self) -> &anyhow::Error {
- &self.e
+ pub fn into_input(self) -> String {
+ self.input
}
}
diff --git a/src/state/history/mod.rs b/src/state/history/mod.rs
index a7b5d88..3573a1c 100644
--- a/src/state/history/mod.rs
+++ b/src/state/history/mod.rs
@@ -87,17 +87,22 @@ impl History {
pub async fn run(
&mut self,
- ast: &crate::parse::Commands,
+ ast: crate::parse::Commands,
event_w: async_std::channel::Sender<crate::event::Event>,
) -> anyhow::Result<usize> {
let (input_w, input_r) = async_std::channel::unbounded();
let (resize_w, resize_r) = async_std::channel::unbounded();
let entry = async_std::sync::Arc::new(async_std::sync::Mutex::new(
- Entry::new(Ok(ast.clone()), self.size, input_w, resize_w),
+ Entry::new(
+ ast.input_string().to_string(),
+ self.size,
+ input_w,
+ resize_w,
+ ),
));
run_commands(
- ast.clone(),
+ ast,
async_std::sync::Arc::clone(&entry),
crate::env::Env::new(0),
input_r,
@@ -123,7 +128,8 @@ impl History {
resize_r.close();
let err_str = format!("{}", e);
- let mut entry = Entry::new(Err(e), self.size, input_w, resize_w);
+ let mut entry =
+ Entry::new(e.into_input(), self.size, input_w, resize_w);
entry.vt.process(err_str.replace('\n', "\r\n").as_bytes());
let status = async_std::process::ExitStatus::from_raw(1 << 8);
entry.exit_info = Some(ExitInfo::new(status));
@@ -249,7 +255,7 @@ impl std::iter::DoubleEndedIterator for VisibleEntries {
}
pub struct Entry {
- ast: Result<crate::parse::Commands, crate::parse::Error>,
+ cmdline: String,
vt: vt100::Parser,
audible_bell_state: usize,
visual_bell_state: usize,
@@ -263,13 +269,13 @@ pub struct Entry {
impl Entry {
fn new(
- ast: Result<crate::parse::Commands, crate::parse::Error>,
+ cmdline: String,
size: (u16, u16),
input: async_std::channel::Sender<Vec<u8>>,
resize: async_std::channel::Sender<(u16, u16)>,
) -> Self {
Self {
- ast,
+ cmdline,
vt: vt100::Parser::new(size.0, size.1, 0),
audible_bell_state: 0,
visual_bell_state: 0,
@@ -302,7 +308,7 @@ impl Entry {
out.reset_attributes();
set_bgcolor(out, idx, focused);
- if let Some(info) = self.exit_info {
+ if let Some(info) = &self.exit_info {
if info.status.signal().is_some() {
out.set_fgcolor(textmode::color::MAGENTA);
} else if info.status.success() {
@@ -325,7 +331,7 @@ impl Entry {
out.reset_attributes();
set_bgcolor(out, idx, focused);
- let time = self.exit_info.map_or_else(
+ let time = self.exit_info.as_ref().map_or_else(
|| {
format!(
"[{}]",
@@ -436,10 +442,7 @@ impl Entry {
}
pub fn cmd(&self) -> &str {
- match &self.ast {
- Ok(ast) => ast.input_string(),
- Err(e) => e.input(),
- }
+ &self.cmdline
}
pub fn toggle_fullscreen(&mut self) {
@@ -468,10 +471,6 @@ impl Entry {
}
pub fn output_lines(&self, width: u16, focused: bool) -> usize {
- if let Err(e) = &self.ast {
- return e.error().to_string().lines().count();
- }
-
if self.binary() {
return 1;
}
@@ -498,7 +497,6 @@ impl Entry {
}
}
-#[derive(Copy, Clone)]
struct ExitInfo {
status: async_std::process::ExitStatus,
instant: std::time::Instant,
diff --git a/src/state/mod.rs b/src/state/mod.rs
index 3317b32..20261cf 100644
--- a/src/state/mod.rs
+++ b/src/state/mod.rs
@@ -224,7 +224,7 @@ impl State {
Ok(ast) => {
let idx = self
.history
- .run(&ast, event_w.clone())
+ .run(ast, event_w.clone())
.await
.unwrap();
self.set_focus(Focus::History(idx), Some(entry))
@@ -336,12 +336,11 @@ impl State {
textmode::Key::Ctrl(b'm') => {
let input = self.readline.input();
if !input.is_empty() {
- self.readline.clear_input();
- match self.parse(&input) {
+ match self.parse(input) {
Ok(ast) => {
let idx = self
.history
- .run(&ast, event_w.clone())
+ .run(ast, event_w.clone())
.await
.unwrap();
self.set_focus(Focus::History(idx), None).await;
@@ -353,6 +352,7 @@ impl State {
.await;
}
}
+ self.readline.clear_input();
}
}
textmode::Key::Ctrl(b'u') => self.readline.clear_backwards(),
diff --git a/src/state/readline.rs b/src/state/readline.rs
index 014efd8..db19bd7 100644
--- a/src/state/readline.rs
+++ b/src/state/readline.rs
@@ -87,8 +87,8 @@ impl Readline {
2 // XXX handle wrapping
}
- pub fn input(&self) -> String {
- self.input_line.clone()
+ pub fn input(&self) -> &str {
+ &self.input_line
}
pub fn add_input(&mut self, s: &str) {