Only handle data over pty channel
This commit is contained in:
parent
321e5842d3
commit
c6c663c4ac
|
@ -1,3 +1,5 @@
|
|||
use tracing::trace;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Input {
|
||||
Char(char),
|
||||
|
@ -16,7 +18,10 @@ impl From<&[u8]> for Input {
|
|||
[27, 91, 65] => Input::Up,
|
||||
[27, 91, 66] => Input::Down,
|
||||
[13] => Input::Enter,
|
||||
_ => Input::Other,
|
||||
other => {
|
||||
trace!("{other:?}");
|
||||
Input::Other
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
15
src/ssh.rs
15
src/ssh.rs
|
@ -23,6 +23,7 @@ pub struct Handler {
|
|||
tunnels: IndexMap<String, Option<Tunnel>>,
|
||||
|
||||
user: Option<String>,
|
||||
pty_channel: Option<ChannelId>,
|
||||
|
||||
terminal: Option<Terminal<CrosstermBackend<TerminalHandle>>>,
|
||||
renderer: Renderer,
|
||||
|
@ -35,6 +36,7 @@ impl Handler {
|
|||
all_tunnels,
|
||||
tunnels: IndexMap::new(),
|
||||
user: None,
|
||||
pty_channel: None,
|
||||
terminal: None,
|
||||
renderer: Default::default(),
|
||||
selected: None,
|
||||
|
@ -203,16 +205,21 @@ impl russh::server::Handler for Handler {
|
|||
|
||||
async fn data(
|
||||
&mut self,
|
||||
_channel: ChannelId,
|
||||
channel: ChannelId,
|
||||
data: &[u8],
|
||||
_session: &mut Session,
|
||||
) -> Result<(), Self::Error> {
|
||||
// Make sure we only handle user input, and not other data send over ssh
|
||||
if let Some(pty_channel) = self.pty_channel
|
||||
&& pty_channel == channel
|
||||
{
|
||||
let input: Input = data.into();
|
||||
trace!(?input, "data");
|
||||
trace!(?input, "input");
|
||||
|
||||
if self.handle_input(input).await? {
|
||||
self.redraw().await?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -308,10 +315,12 @@ impl russh::server::Handler for Handler {
|
|||
_modes: &[(russh::Pty, u32)],
|
||||
session: &mut Session,
|
||||
) -> Result<(), Self::Error> {
|
||||
trace!(col_width, row_height, "pty_request");
|
||||
trace!(col_width, row_height, ?channel, "pty_request");
|
||||
|
||||
self.resize(col_width, row_height).await?;
|
||||
|
||||
self.pty_channel = Some(channel);
|
||||
|
||||
session.channel_success(channel)?;
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in New Issue
Block a user