diff options
author | Jesse Luehrs <doy@tozt.net> | 2022-01-05 07:01:08 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2022-01-05 07:01:08 -0500 |
commit | 404ae6202e24c7bfc5625edb3ac064df4ecd105f (patch) | |
tree | 1177bdc4c2b4f8d857bf3d5630ee82fd2e4ccdd3 | |
parent | e893d7cb8ca855e2843f60ec0b1045510e1577cf (diff) | |
download | nbsh-404ae6202e24c7bfc5625edb3ac064df4ecd105f.tar.gz nbsh-404ae6202e24c7bfc5625edb3ac064df4ecd105f.zip |
shorten some names
-rw-r--r-- | src/main.rs | 10 | ||||
-rw-r--r-- | src/pipeline/builtins/command.rs | 2 | ||||
-rw-r--r-- | src/pipeline/builtins/mod.rs | 18 | ||||
-rw-r--r-- | src/pipeline/command.rs | 2 | ||||
-rw-r--r-- | src/pipeline/mod.rs | 12 | ||||
-rw-r--r-- | src/state/history/entry.rs | 12 | ||||
-rw-r--r-- | src/state/history/mod.rs | 18 | ||||
-rw-r--r-- | src/state/history/pty.rs | 14 | ||||
-rw-r--r-- | src/state/mod.rs | 24 | ||||
-rw-r--r-- | src/state/readline.rs | 2 |
10 files changed, 55 insertions, 59 deletions
diff --git a/src/main.rs b/src/main.rs index 69fe1f0..d858f58 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,9 @@ #![allow(clippy::type_complexity)] mod env; +pub use env::Env; mod event; +pub use event::Event; mod format; mod info; mod parse; @@ -74,7 +76,7 @@ async fn async_main() -> anyhow::Result<i32> { .chain(signals); while signals.next().await.is_some() { event_w - .send(crate::event::Event::Resize( + .send(Event::Resize( terminal_size::terminal_size().map_or( (24, 80), |( @@ -93,7 +95,7 @@ async fn async_main() -> anyhow::Result<i32> { let event_w = event_w.clone(); async_std::task::spawn(async move { while let Some(key) = input.read_key().await.unwrap() { - event_w.send(event::Event::Key(key)).await.unwrap(); + event_w.send(Event::Key(key)).await.unwrap(); } }); } @@ -112,9 +114,9 @@ async fn async_main() -> anyhow::Result<i32> { let mut interval = async_std::stream::interval( std::time::Duration::from_secs(1), ); - event_w.send(crate::event::Event::ClockTimer).await.unwrap(); + event_w.send(Event::ClockTimer).await.unwrap(); while interval.next().await.is_some() { - event_w.send(crate::event::Event::ClockTimer).await.unwrap(); + event_w.send(Event::ClockTimer).await.unwrap(); } }); } diff --git a/src/pipeline/builtins/command.rs b/src/pipeline/builtins/command.rs index b49b41d..b69463b 100644 --- a/src/pipeline/builtins/command.rs +++ b/src/pipeline/builtins/command.rs @@ -41,7 +41,7 @@ impl Command { self.io.pre_exec(f); } - pub fn spawn(self, env: &crate::env::Env) -> anyhow::Result<Child> { + pub fn spawn(self, env: &crate::Env) -> anyhow::Result<Child> { let Self { f, exe, io } = self; (f)(exe, env, io) } diff --git a/src/pipeline/builtins/mod.rs b/src/pipeline/builtins/mod.rs index 26405f4..36e308a 100644 --- a/src/pipeline/builtins/mod.rs +++ b/src/pipeline/builtins/mod.rs @@ -7,7 +7,7 @@ pub use command::{Child, Command}; type Builtin = &'static (dyn for<'a> Fn( crate::parse::Exe, - &'a crate::env::Env, + &'a crate::Env, command::Io, ) -> anyhow::Result<command::Child<'a>> + Sync @@ -31,12 +31,12 @@ static BUILTINS: once_cell::sync::Lazy< #[allow(clippy::unnecessary_wraps)] fn cd( exe: crate::parse::Exe, - env: &crate::env::Env, + env: &crate::Env, io: command::Io, ) -> anyhow::Result<command::Child> { async fn async_cd( exe: crate::parse::Exe, - _env: &crate::env::Env, + _env: &crate::Env, io: command::Io, ) -> std::process::ExitStatus { macro_rules! bail { @@ -121,12 +121,12 @@ fn cd( // this later, since the binary seems totally fine fn echo( exe: crate::parse::Exe, - env: &crate::env::Env, + env: &crate::Env, io: command::Io, ) -> anyhow::Result<command::Child> { async fn async_echo( exe: crate::parse::Exe, - _env: &crate::env::Env, + _env: &crate::Env, io: command::Io, ) -> std::process::ExitStatus { macro_rules! write_stdout { @@ -159,7 +159,7 @@ fn echo( fn and( mut exe: crate::parse::Exe, - env: &crate::env::Env, + env: &crate::Env, io: command::Io, ) -> anyhow::Result<command::Child> { exe.shift(); @@ -175,7 +175,7 @@ fn and( fn or( mut exe: crate::parse::Exe, - env: &crate::env::Env, + env: &crate::Env, io: command::Io, ) -> anyhow::Result<command::Child> { exe.shift(); @@ -191,7 +191,7 @@ fn or( fn command( mut exe: crate::parse::Exe, - env: &crate::env::Env, + env: &crate::Env, io: command::Io, ) -> anyhow::Result<command::Child> { exe.shift(); @@ -202,7 +202,7 @@ fn command( fn builtin( mut exe: crate::parse::Exe, - env: &crate::env::Env, + env: &crate::Env, io: command::Io, ) -> anyhow::Result<command::Child> { exe.shift(); diff --git a/src/pipeline/command.rs b/src/pipeline/command.rs index 271ce85..a5b5f79 100644 --- a/src/pipeline/command.rs +++ b/src/pipeline/command.rs @@ -90,7 +90,7 @@ impl Command { } } - pub fn spawn(self, env: &crate::env::Env) -> anyhow::Result<Child> { + pub fn spawn(self, env: &crate::Env) -> anyhow::Result<Child> { match self.inner { Inner::Binary(mut cmd) => { Ok(Child::Binary(cmd.spawn().map_err(|e| { diff --git a/src/pipeline/mod.rs b/src/pipeline/mod.rs index fc6fdb0..d4c1cab 100644 --- a/src/pipeline/mod.rs +++ b/src/pipeline/mod.rs @@ -9,7 +9,7 @@ const PID0: nix::unistd::Pid = nix::unistd::Pid::from_raw(0); #[derive(Debug, serde::Serialize, serde::Deserialize)] pub enum Event { Suspend(usize), - Exit(crate::env::Env), + Exit(crate::Env), } mod builtins; @@ -37,7 +37,7 @@ pub async fn run() -> anyhow::Result<i32> { } async fn run_with_env( - env: &mut crate::env::Env, + env: &mut crate::Env, shell_write: &async_std::fs::File, ) -> anyhow::Result<()> { let pipeline = crate::parse::Pipeline::parse(env.pipeline().unwrap())?; @@ -49,10 +49,10 @@ async fn run_with_env( async fn read_data( mut fh: async_std::fs::File, -) -> anyhow::Result<crate::env::Env> { +) -> anyhow::Result<crate::Env> { let mut data = vec![]; fh.read_to_end(&mut data).await?; - let env = crate::env::Env::from_bytes(&data); + let env = crate::Env::from_bytes(&data); Ok(env) } @@ -67,7 +67,7 @@ async fn write_event( fn spawn_children( pipeline: crate::parse::Pipeline, - env: &crate::env::Env, + env: &crate::Env, ) -> anyhow::Result<(Vec<Child>, Option<nix::unistd::Pid>)> { let mut cmds: Vec<_> = pipeline.into_exes().map(Command::new).collect(); for i in 0..(cmds.len() - 1) { @@ -103,7 +103,7 @@ fn spawn_children( async fn wait_children( children: Vec<Child<'_>>, pg: Option<nix::unistd::Pid>, - env: &crate::env::Env, + env: &crate::Env, shell_write: &async_std::fs::File, ) -> std::process::ExitStatus { enum Res { diff --git a/src/state/history/entry.rs b/src/state/history/entry.rs index 932ec80..31b4926 100644 --- a/src/state/history/entry.rs +++ b/src/state/history/entry.rs @@ -2,7 +2,7 @@ use std::os::unix::process::ExitStatusExt as _; pub struct Entry { cmdline: String, - env: crate::env::Env, + env: crate::Env, vt: vt100::Parser, audible_bell_state: usize, visual_bell_state: usize, @@ -17,7 +17,7 @@ pub struct Entry { impl Entry { pub fn new( cmdline: String, - env: crate::env::Env, + env: crate::Env, size: (u16, u16), input: async_std::channel::Sender<Vec<u8>>, resize: async_std::channel::Sender<(u16, u16)>, @@ -214,7 +214,7 @@ impl Entry { &self.cmdline } - pub fn env(&self) -> &crate::env::Env { + pub fn env(&self) -> &crate::Env { &self.env } @@ -271,12 +271,12 @@ impl Entry { pub async fn finish( &mut self, - env: crate::env::Env, - event_w: async_std::channel::Sender<crate::event::Event>, + env: crate::Env, + event_w: async_std::channel::Sender<crate::Event>, ) { self.exit_info = Some(ExitInfo::new(*env.latest_status())); self.env = env; - event_w.send(crate::event::Event::PtyClose).await.unwrap(); + event_w.send(crate::Event::PtyClose).await.unwrap(); } } diff --git a/src/state/history/mod.rs b/src/state/history/mod.rs index 9df3103..0723f77 100644 --- a/src/state/history/mod.rs +++ b/src/state/history/mod.rs @@ -91,8 +91,8 @@ impl History { pub async fn run( &mut self, ast: crate::parse::Commands, - env: &crate::env::Env, - event_w: async_std::channel::Sender<crate::event::Event>, + env: &crate::Env, + event_w: async_std::channel::Sender<crate::Event>, ) -> anyhow::Result<usize> { let (input_w, input_r) = async_std::channel::unbounded(); let (resize_w, resize_r) = async_std::channel::unbounded(); @@ -122,8 +122,8 @@ impl History { pub async fn parse_error( &mut self, e: crate::parse::Error, - env: &crate::env::Env, - event_w: async_std::channel::Sender<crate::event::Event>, + env: &crate::Env, + event_w: async_std::channel::Sender<crate::Event>, ) -> anyhow::Result<usize> { // XXX would be great to not have to do this let (input_w, input_r) = async_std::channel::unbounded(); @@ -272,10 +272,10 @@ impl std::iter::DoubleEndedIterator for VisibleEntries { fn run_commands( ast: crate::parse::Commands, entry: async_std::sync::Arc<async_std::sync::Mutex<Entry>>, - mut env: crate::env::Env, + mut env: crate::Env, input_r: async_std::channel::Receiver<Vec<u8>>, resize_r: async_std::channel::Receiver<(u16, u16)>, - event_w: async_std::channel::Sender<crate::event::Event>, + event_w: async_std::channel::Sender<crate::Event>, ) { async_std::task::spawn(async move { let pty = match pty::Pty::new( @@ -328,8 +328,8 @@ fn run_commands( async fn run_pipeline( pty: &pty::Pty, - env: &mut crate::env::Env, - event_w: async_std::channel::Sender<crate::event::Event>, + env: &mut crate::Env, + event_w: async_std::channel::Sender<crate::Event>, ) -> anyhow::Result<(async_std::process::ExitStatus, bool)> { let mut cmd = pty_process::Command::new(std::env::current_exe().unwrap()); cmd.arg("--internal-cmd-runner"); @@ -380,7 +380,7 @@ async fn run_pipeline( match read.or(exit).await { Res::Read(Ok(event)) => match event { crate::pipeline::Event::Suspend(idx) => event_w - .send(crate::event::Event::ChildSuspend(idx)) + .send(crate::Event::ChildSuspend(idx)) .await .unwrap(), crate::pipeline::Event::Exit(new_env) => *env = new_env, diff --git a/src/state/history/pty.rs b/src/state/history/pty.rs index 96be550..146cf68 100644 --- a/src/state/history/pty.rs +++ b/src/state/history/pty.rs @@ -12,7 +12,7 @@ impl Pty { entry: &async_std::sync::Arc<async_std::sync::Mutex<super::Entry>>, input_r: async_std::channel::Receiver<Vec<u8>>, resize_r: async_std::channel::Receiver<(u16, u16)>, - event_w: async_std::channel::Sender<crate::event::Event>, + event_w: async_std::channel::Sender<crate::Event>, ) -> anyhow::Result<Self> { let (close_w, close_r) = async_std::channel::unbounded(); @@ -50,7 +50,7 @@ async fn pty_task( input_r: async_std::channel::Receiver<Vec<u8>>, resize_r: async_std::channel::Receiver<(u16, u16)>, close_r: async_std::channel::Receiver<()>, - event_w: async_std::channel::Sender<crate::event::Event>, + event_w: async_std::channel::Sender<crate::Event>, ) { loop { enum Res { @@ -68,10 +68,7 @@ async fn pty_task( Res::Read(res) => match res { Ok(bytes) => { entry.lock_arc().await.process(&buf[..bytes]); - event_w - .send(crate::event::Event::PtyOutput) - .await - .unwrap(); + event_w.send(crate::Event::PtyOutput).await.unwrap(); } Err(e) => { if e.raw_os_error() != Some(libc::EIO) { @@ -98,10 +95,7 @@ async fn pty_task( }, Res::Close(res) => match res { Ok(()) => { - event_w - .send(crate::event::Event::PtyClose) - .await - .unwrap(); + event_w.send(crate::Event::PtyClose).await.unwrap(); return; } Err(e) => { diff --git a/src/state/mod.rs b/src/state/mod.rs index 356b17a..28ab705 100644 --- a/src/state/mod.rs +++ b/src/state/mod.rs @@ -24,7 +24,7 @@ pub enum Action { pub struct State { readline: readline::Readline, history: history::History, - env: crate::env::Env, + env: crate::Env, focus: Focus, scene: Scene, escape: bool, @@ -37,7 +37,7 @@ impl State { Self { readline: readline::Readline::new(), history: history::History::new(), - env: crate::env::Env::new(), + env: crate::Env::new(), focus: Focus::Readline, scene: Scene::Readline, escape: false, @@ -121,11 +121,11 @@ impl State { pub async fn handle_event( &mut self, - event: crate::event::Event, - event_w: &async_std::channel::Sender<crate::event::Event>, + event: crate::Event, + event_w: &async_std::channel::Sender<crate::Event>, ) -> Option<Action> { match event { - crate::event::Event::Key(key) => { + crate::Event::Key(key) => { return if self.escape { self.escape = false; self.handle_key_escape(key, event_w.clone()).await @@ -148,12 +148,12 @@ impl State { } }; } - crate::event::Event::Resize(new_size) => { + crate::Event::Resize(new_size) => { self.readline.resize(new_size).await; self.history.resize(new_size).await; return Some(Action::Resize(new_size.0, new_size.1)); } - crate::event::Event::PtyOutput => { + crate::Event::PtyOutput => { // the number of visible lines may have changed, so make sure // the focus is still visible self.history @@ -165,7 +165,7 @@ impl State { .await; self.scene = self.default_scene(self.focus, None).await; } - crate::event::Event::PtyClose => { + crate::Event::PtyClose => { if let Some(idx) = self.focus_idx() { let entry = self.history.entry(idx).await; if !entry.running() { @@ -186,12 +186,12 @@ impl State { } } } - crate::event::Event::ChildSuspend(idx) => { + crate::Event::ChildSuspend(idx) => { if self.focus_idx() == Some(idx) { self.set_focus(Focus::Readline, None).await; } } - crate::event::Event::ClockTimer => {} + crate::Event::ClockTimer => {} }; Some(Action::Refresh) } @@ -199,7 +199,7 @@ impl State { async fn handle_key_escape( &mut self, key: textmode::Key, - event_w: async_std::channel::Sender<crate::event::Event>, + event_w: async_std::channel::Sender<crate::Event>, ) -> Option<Action> { match key { textmode::Key::Ctrl(b'd') => { @@ -319,7 +319,7 @@ impl State { async fn handle_key_readline( &mut self, key: textmode::Key, - event_w: async_std::channel::Sender<crate::event::Event>, + event_w: async_std::channel::Sender<crate::Event>, ) -> Option<Action> { match key { textmode::Key::Char(c) => { diff --git a/src/state/readline.rs b/src/state/readline.rs index 375bc92..e423e62 100644 --- a/src/state/readline.rs +++ b/src/state/readline.rs @@ -22,7 +22,7 @@ impl Readline { pub async fn render( &self, out: &mut impl textmode::Textmode, - env: &crate::env::Env, + env: &crate::Env, focus: bool, offset: time::UtcOffset, ) -> anyhow::Result<()> { |