aboutsummaryrefslogtreecommitdiffstats
path: root/src/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/play.rs50
-rw-r--r--src/cmd/record.rs70
-rw-r--r--src/cmd/stream.rs60
-rw-r--r--src/cmd/watch.rs36
4 files changed, 99 insertions, 117 deletions
diff --git a/src/cmd/play.rs b/src/cmd/play.rs
index 3dda60c..4e0048e 100644
--- a/src/cmd/play.rs
+++ b/src/cmd/play.rs
@@ -78,7 +78,7 @@ impl PlaySession {
&'static [&'static dyn for<'a> Fn(
&'a mut Self,
)
- -> crate::component_future::Poll<
+ -> component_future::Poll<
(),
Error,
>] = &[
@@ -87,58 +87,62 @@ impl PlaySession {
&Self::poll_write_terminal,
];
- fn poll_open_file(&mut self) -> crate::component_future::Poll<(), Error> {
+ fn poll_open_file(&mut self) -> component_future::Poll<(), Error> {
match &mut self.file {
FileState::Closed { filename } => {
self.file = FileState::Opening {
filename: filename.to_string(),
fut: tokio::fs::File::open(filename.to_string()),
};
- Ok(crate::component_future::Async::DidWork)
+ Ok(component_future::Async::DidWork)
}
FileState::Opening { filename, fut } => {
- let file = try_ready!(fut.poll().with_context(|| {
- crate::error::OpenFile {
- filename: filename.to_string(),
- }
- }));
+ let file = component_future::try_ready!(fut
+ .poll()
+ .with_context(|| {
+ crate::error::OpenFile {
+ filename: filename.to_string(),
+ }
+ }));
let file = crate::ttyrec::File::new(file);
self.file = FileState::Open { file };
- Ok(crate::component_future::Async::DidWork)
+ Ok(component_future::Async::DidWork)
}
- _ => Ok(crate::component_future::Async::NothingToDo),
+ _ => Ok(component_future::Async::NothingToDo),
}
}
- fn poll_read_file(&mut self) -> crate::component_future::Poll<(), Error> {
+ fn poll_read_file(&mut self) -> component_future::Poll<(), Error> {
if let FileState::Open { file } = &mut self.file {
- if let Some(frame) = try_ready!(file.poll_read()) {
+ if let Some(frame) =
+ component_future::try_ready!(file.poll_read())
+ {
self.to_write.insert_at(frame.data, frame.time);
} else {
self.file = FileState::Eof;
}
- Ok(crate::component_future::Async::DidWork)
+ Ok(component_future::Async::DidWork)
} else {
- Ok(crate::component_future::Async::NothingToDo)
+ Ok(component_future::Async::NothingToDo)
}
}
- fn poll_write_terminal(
- &mut self,
- ) -> crate::component_future::Poll<(), Error> {
- if let Some(data) =
- try_ready!(self.to_write.poll().context(crate::error::Sleep))
+ fn poll_write_terminal(&mut self) -> component_future::Poll<(), Error> {
+ if let Some(data) = component_future::try_ready!(self
+ .to_write
+ .poll()
+ .context(crate::error::Sleep))
{
// TODO async
let stdout = std::io::stdout();
let mut stdout = stdout.lock();
stdout.write(&data).context(crate::error::WriteTerminal)?;
stdout.flush().context(crate::error::FlushTerminal)?;
- Ok(crate::component_future::Async::DidWork)
+ Ok(component_future::Async::DidWork)
} else if let FileState::Eof = self.file {
- Ok(crate::component_future::Async::Ready(()))
+ Ok(component_future::Async::Ready(()))
} else {
- Ok(crate::component_future::Async::NothingToDo)
+ Ok(component_future::Async::NothingToDo)
}
}
}
@@ -149,7 +153,7 @@ impl futures::future::Future for PlaySession {
type Error = Error;
fn poll(&mut self) -> futures::Poll<Self::Item, Self::Error> {
- crate::component_future::poll_future(self, Self::POLL_FNS)
+ component_future::poll_future(self, Self::POLL_FNS)
}
}
diff --git a/src/cmd/record.rs b/src/cmd/record.rs
index f2e0aab..6a31c5d 100644
--- a/src/cmd/record.rs
+++ b/src/cmd/record.rs
@@ -113,7 +113,7 @@ impl RecordSession {
&'static [&'static dyn for<'a> Fn(
&'a mut Self,
)
- -> crate::component_future::Poll<
+ -> component_future::Poll<
(),
Error,
>] = &[
@@ -124,36 +124,36 @@ impl RecordSession {
&Self::poll_write_file,
];
- fn poll_open_file(&mut self) -> crate::component_future::Poll<(), Error> {
+ fn poll_open_file(&mut self) -> component_future::Poll<(), Error> {
match &mut self.file {
FileState::Closed { filename } => {
self.file = FileState::Opening {
filename: filename.to_string(),
fut: tokio::fs::File::create(filename.to_string()),
};
- Ok(crate::component_future::Async::DidWork)
+ Ok(component_future::Async::DidWork)
}
FileState::Opening { filename, fut } => {
- let file = try_ready!(fut.poll().with_context(|| {
- crate::error::OpenFile {
- filename: filename.clone(),
- }
- }));
+ let file = component_future::try_ready!(fut
+ .poll()
+ .with_context(|| {
+ crate::error::OpenFile {
+ filename: filename.clone(),
+ }
+ }));
let mut file = crate::ttyrec::File::new(file);
file.write_frame(self.buffer.contents())?;
self.file = FileState::Open { file };
- Ok(crate::component_future::Async::DidWork)
+ Ok(component_future::Async::DidWork)
}
FileState::Open { .. } => {
- Ok(crate::component_future::Async::NothingToDo)
+ Ok(component_future::Async::NothingToDo)
}
}
}
- fn poll_read_process(
- &mut self,
- ) -> crate::component_future::Poll<(), Error> {
- match try_ready!(self.process.poll()) {
+ fn poll_read_process(&mut self) -> component_future::Poll<(), Error> {
+ match component_future::try_ready!(self.process.poll()) {
Some(crate::resize::Event::Process(e)) => {
match e {
crate::process::Event::CommandStart(..) => {
@@ -174,10 +174,10 @@ impl RecordSession {
}
}
}
- Ok(crate::component_future::Async::DidWork)
+ Ok(component_future::Async::DidWork)
}
Some(crate::resize::Event::Resize(_)) => {
- Ok(crate::component_future::Async::DidWork)
+ Ok(component_future::Async::DidWork)
}
None => {
if !self.done {
@@ -185,62 +185,54 @@ impl RecordSession {
}
// don't return final event here - wait until we are done
// writing all data to the file (see poll_write_file)
- Ok(crate::component_future::Async::DidWork)
+ Ok(component_future::Async::DidWork)
}
}
}
- fn poll_write_terminal(
- &mut self,
- ) -> crate::component_future::Poll<(), Error> {
+ fn poll_write_terminal(&mut self) -> component_future::Poll<(), Error> {
if self.sent_local == self.buffer.len() {
- return Ok(crate::component_future::Async::NothingToDo);
+ return Ok(component_future::Async::NothingToDo);
}
- let n = try_ready!(self
+ let n = component_future::try_ready!(self
.stdout
.poll_write(&self.buffer.contents()[self.sent_local..])
.context(crate::error::WriteTerminal));
self.sent_local += n;
self.needs_flush = true;
- Ok(crate::component_future::Async::DidWork)
+ Ok(component_future::Async::DidWork)
}
- fn poll_flush_terminal(
- &mut self,
- ) -> crate::component_future::Poll<(), Error> {
+ fn poll_flush_terminal(&mut self) -> component_future::Poll<(), Error> {
if !self.needs_flush {
- return Ok(crate::component_future::Async::NothingToDo);
+ return Ok(component_future::Async::NothingToDo);
}
- try_ready!(self
+ component_future::try_ready!(self
.stdout
.poll_flush()
.context(crate::error::FlushTerminal));
self.needs_flush = false;
- Ok(crate::component_future::Async::DidWork)
+ Ok(component_future::Async::DidWork)
}
- fn poll_write_file(
- &mut self,
- ) -> crate::component_future::Poll<(), Error> {
+ fn poll_write_file(&mut self) -> component_future::Poll<(), Error> {
let file = match &mut self.file {
FileState::Open { file } => file,
_ => {
- return Ok(crate::component_future::Async::NothingToDo);
+ return Ok(component_future::Async::NothingToDo);
}
};
match file.poll_write()? {
- futures::Async::Ready(()) => {
- Ok(crate::component_future::Async::DidWork)
- }
+ futures::Async::Ready(()) => Ok(component_future::Async::DidWork),
futures::Async::NotReady => {
// ship all data to the server before actually ending
if self.done && file.is_empty() {
- Ok(crate::component_future::Async::Ready(()))
+ Ok(component_future::Async::Ready(()))
} else {
- Ok(crate::component_future::Async::NotReady)
+ Ok(component_future::Async::NotReady)
}
}
}
@@ -253,6 +245,6 @@ impl futures::future::Future for RecordSession {
type Error = Error;
fn poll(&mut self) -> futures::Poll<Self::Item, Self::Error> {
- crate::component_future::poll_future(self, Self::POLL_FNS)
+ component_future::poll_future(self, Self::POLL_FNS)
}
}
diff --git a/src/cmd/stream.rs b/src/cmd/stream.rs
index 9a0f149..823a4b1 100644
--- a/src/cmd/stream.rs
+++ b/src/cmd/stream.rs
@@ -187,7 +187,7 @@ impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static>
&'static [&'static dyn for<'a> Fn(
&'a mut Self,
)
- -> crate::component_future::Poll<
+ -> component_future::Poll<
(),
Error,
>] = &[
@@ -200,26 +200,24 @@ impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static>
// this should never return Err, because we don't want server
// communication issues to ever interrupt a running process
- fn poll_read_client(
- &mut self,
- ) -> crate::component_future::Poll<(), Error> {
+ fn poll_read_client(&mut self) -> component_future::Poll<(), Error> {
match self.client.poll() {
Ok(futures::Async::Ready(Some(e))) => match e {
crate::client::Event::Disconnect => {
self.connected = false;
- Ok(crate::component_future::Async::DidWork)
+ Ok(component_future::Async::DidWork)
}
crate::client::Event::Connect => {
self.connected = true;
self.sent_remote = 0;
- Ok(crate::component_future::Async::DidWork)
+ Ok(component_future::Async::DidWork)
}
crate::client::Event::ServerMessage(..) => {
// we don't expect to ever see a server message once we
// start streaming, so if one comes through, assume
// something is messed up and try again
self.client.reconnect();
- Ok(crate::component_future::Async::DidWork)
+ Ok(component_future::Async::DidWork)
}
},
Ok(futures::Async::Ready(None)) => {
@@ -227,19 +225,17 @@ impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static>
unreachable!()
}
Ok(futures::Async::NotReady) => {
- Ok(crate::component_future::Async::NotReady)
+ Ok(component_future::Async::NotReady)
}
Err(..) => {
self.client.reconnect();
- Ok(crate::component_future::Async::DidWork)
+ Ok(component_future::Async::DidWork)
}
}
}
- fn poll_read_process(
- &mut self,
- ) -> crate::component_future::Poll<(), Error> {
- match try_ready!(self.process.poll()) {
+ fn poll_read_process(&mut self) -> component_future::Poll<(), Error> {
+ match component_future::try_ready!(self.process.poll()) {
Some(crate::resize::Event::Process(e)) => {
match e {
crate::process::Event::CommandStart(..) => {
@@ -257,12 +253,12 @@ impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static>
self.record_bytes(&output);
}
}
- Ok(crate::component_future::Async::DidWork)
+ Ok(component_future::Async::DidWork)
}
Some(crate::resize::Event::Resize(size)) => {
self.client
.send_message(crate::protocol::Message::resize(&size));
- Ok(crate::component_future::Async::DidWork)
+ Ok(component_future::Async::DidWork)
}
None => {
if !self.done {
@@ -270,51 +266,45 @@ impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static>
}
// don't return final event here - wait until we are done
// sending all data to the server (see poll_write_server)
- Ok(crate::component_future::Async::DidWork)
+ Ok(component_future::Async::DidWork)
}
}
}
- fn poll_write_terminal(
- &mut self,
- ) -> crate::component_future::Poll<(), Error> {
+ fn poll_write_terminal(&mut self) -> component_future::Poll<(), Error> {
if self.sent_local == self.buffer.len() {
- return Ok(crate::component_future::Async::NothingToDo);
+ return Ok(component_future::Async::NothingToDo);
}
- let n = try_ready!(self
+ let n = component_future::try_ready!(self
.stdout
.poll_write(&self.buffer.contents()[self.sent_local..])
.context(crate::error::WriteTerminal));
self.sent_local += n;
self.needs_flush = true;
- Ok(crate::component_future::Async::DidWork)
+ Ok(component_future::Async::DidWork)
}
- fn poll_flush_terminal(
- &mut self,
- ) -> crate::component_future::Poll<(), Error> {
+ fn poll_flush_terminal(&mut self) -> component_future::Poll<(), Error> {
if !self.needs_flush {
- return Ok(crate::component_future::Async::NothingToDo);
+ return Ok(component_future::Async::NothingToDo);
}
- try_ready!(self
+ component_future::try_ready!(self
.stdout
.poll_flush()
.context(crate::error::FlushTerminal));
self.needs_flush = false;
- Ok(crate::component_future::Async::DidWork)
+ Ok(component_future::Async::DidWork)
}
- fn poll_write_server(
- &mut self,
- ) -> crate::component_future::Poll<(), Error> {
+ fn poll_write_server(&mut self) -> component_future::Poll<(), Error> {
if self.sent_remote == self.buffer.len() || !self.connected {
// ship all data to the server before actually ending
if self.done {
- return Ok(crate::component_future::Async::Ready(()));
+ return Ok(component_future::Async::Ready(()));
} else {
- return Ok(crate::component_future::Async::NothingToDo);
+ return Ok(component_future::Async::NothingToDo);
}
}
@@ -323,7 +313,7 @@ impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static>
.send_message(crate::protocol::Message::terminal_output(buf));
self.sent_remote = self.buffer.len();
- Ok(crate::component_future::Async::DidWork)
+ Ok(component_future::Async::DidWork)
}
}
@@ -335,6 +325,6 @@ impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static>
type Error = Error;
fn poll(&mut self) -> futures::Poll<Self::Item, Self::Error> {
- crate::component_future::poll_future(self, Self::POLL_FNS)
+ component_future::poll_future(self, Self::POLL_FNS)
}
}
diff --git a/src/cmd/watch.rs b/src/cmd/watch.rs
index 011629d..67e3507 100644
--- a/src/cmd/watch.rs
+++ b/src/cmd/watch.rs
@@ -566,7 +566,7 @@ impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static>
&'static [&'static dyn for<'a> Fn(
&'a mut Self,
)
- -> crate::component_future::Poll<
+ -> component_future::Poll<
(),
Error,
>] = &[
@@ -576,13 +576,13 @@ impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static>
&Self::poll_watch_client,
];
- fn poll_resizer(&mut self) -> crate::component_future::Poll<(), Error> {
- let size = try_ready!(self.resizer.poll()).unwrap();
+ fn poll_resizer(&mut self) -> component_future::Poll<(), Error> {
+ let size = component_future::try_ready!(self.resizer.poll()).unwrap();
self.resize(size)?;
- Ok(crate::component_future::Async::DidWork)
+ Ok(component_future::Async::DidWork)
}
- fn poll_input(&mut self) -> crate::component_future::Poll<(), Error> {
+ fn poll_input(&mut self) -> component_future::Poll<(), Error> {
if self.raw_screen.is_none() {
self.raw_screen = Some(
crossterm::RawScreen::into_raw_mode()
@@ -595,7 +595,7 @@ impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static>
}
}
- let e = try_ready!(self.key_reader.poll()).unwrap();
+ let e = component_future::try_ready!(self.key_reader.poll()).unwrap();
let quit = match &mut self.state {
State::Temporary => unreachable!(),
State::LoggingIn { .. } => self.loading_keypress(&e)?,
@@ -603,16 +603,14 @@ impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static>
State::Watching { .. } => self.watch_keypress(&e)?,
};
if quit {
- Ok(crate::component_future::Async::Ready(()))
+ Ok(component_future::Async::Ready(()))
} else {
- Ok(crate::component_future::Async::DidWork)
+ Ok(component_future::Async::DidWork)
}
}
- fn poll_list_client(
- &mut self,
- ) -> crate::component_future::Poll<(), Error> {
- match try_ready!(self.list_client.poll()).unwrap() {
+ fn poll_list_client(&mut self) -> component_future::Poll<(), Error> {
+ match component_future::try_ready!(self.list_client.poll()).unwrap() {
crate::client::Event::Disconnect => {
self.reconnect(true)?;
}
@@ -624,19 +622,17 @@ impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static>
self.list_server_message(msg)?;
}
}
- Ok(crate::component_future::Async::DidWork)
+ Ok(component_future::Async::DidWork)
}
- fn poll_watch_client(
- &mut self,
- ) -> crate::component_future::Poll<(), Error> {
+ fn poll_watch_client(&mut self) -> component_future::Poll<(), Error> {
let client = if let State::Watching { client } = &mut self.state {
client
} else {
- return Ok(crate::component_future::Async::NothingToDo);
+ return Ok(component_future::Async::NothingToDo);
};
- match try_ready!(client.poll()).unwrap() {
+ match component_future::try_ready!(client.poll()).unwrap() {
crate::client::Event::Disconnect => {
self.reconnect(true)?;
}
@@ -645,7 +641,7 @@ impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static>
self.watch_server_message(msg)?;
}
}
- Ok(crate::component_future::Async::DidWork)
+ Ok(component_future::Async::DidWork)
}
}
@@ -657,7 +653,7 @@ impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static>
type Error = Error;
fn poll(&mut self) -> futures::Poll<Self::Item, Self::Error> {
- let res = crate::component_future::poll_future(self, Self::POLL_FNS);
+ let res = component_future::poll_future(self, Self::POLL_FNS);
if res.is_err() {
self.state = State::Temporary; // drop alternate screen
self.raw_screen = None;