feat: added cd
added cd and fixed all the warnings in the source code
This commit is contained in:
@@ -5,10 +5,10 @@ use std::{
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use anyhow::{bail, Context};
|
||||
use ed25519_dalek::{Keypair, Signature, Signer, Verifier};
|
||||
use anyhow::bail;
|
||||
use ed25519_dalek::{Signature, Signer, Verifier};
|
||||
use sparse_05_common::messages::{
|
||||
Capabilities, Command, OperatingSystem, Response, CONNECTED_MESSAGE, CONNECT_MESSAGE,
|
||||
Capabilities, Command, Response, CONNECTED_MESSAGE, CONNECT_MESSAGE,
|
||||
};
|
||||
use tokio::{fs, net::UdpSocket};
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use std::{
|
||||
io::{self, Read, Write},
|
||||
os::fd::AsRawFd,
|
||||
path::PathBuf,
|
||||
sync::{
|
||||
atomic::{AtomicBool, Ordering},
|
||||
@@ -11,7 +10,6 @@ use std::{
|
||||
|
||||
use sparse_05_common::messages::{Capabilities, Command, Response};
|
||||
use structopt::StructOpt;
|
||||
use tempfile::NamedTempFile;
|
||||
use tokio::{
|
||||
io::{stderr, stdout, AsyncWriteExt},
|
||||
runtime::Handle,
|
||||
@@ -46,7 +44,7 @@ pub enum SparseCommands {
|
||||
},
|
||||
}
|
||||
|
||||
macro_rules! libc_try {
|
||||
/*macro_rules! libc_try {
|
||||
($expr:expr) => {
|
||||
if unsafe { $expr } == -1 {
|
||||
return Err(std::io::Error::last_os_error())?;
|
||||
@@ -71,7 +69,7 @@ fn set_term_attrs<F: AsRawFd>(fd: &mut F, attrs: &libc::termios) -> anyhow::Resu
|
||||
fn convert_termios_raw(attrs: &mut libc::termios) -> anyhow::Result<()> {
|
||||
unsafe { libc::cfmakeraw(attrs) };
|
||||
Ok(())
|
||||
}
|
||||
}*/
|
||||
|
||||
async fn run_command(
|
||||
stdin: &mut Receiver<Vec<u8>>,
|
||||
@@ -159,11 +157,10 @@ pub(super) async fn shell(
|
||||
println!("Source code available at https://github.com/r-a303931/sparse (feel free to give it a star!)");
|
||||
println!("Type #help to view a list of sparse commands\n");
|
||||
|
||||
let mut stdin = tokio::io::stdin();
|
||||
let mut stdout = io::stdout();
|
||||
let backup_term_attrs = get_term_attrs(&stdin)?;
|
||||
/* let backup_term_attrs = get_term_attrs(&stdin)?;
|
||||
let mut raw_term_attrs = get_term_attrs(&stdin)?;
|
||||
convert_termios_raw(&mut raw_term_attrs)?;
|
||||
convert_termios_raw(&mut raw_term_attrs)?;*/
|
||||
|
||||
let mut cwd = "/".to_string();
|
||||
|
||||
@@ -195,7 +192,7 @@ pub(super) async fn shell(
|
||||
}
|
||||
});
|
||||
|
||||
loop {
|
||||
'outer: loop {
|
||||
print!(
|
||||
"{}@{}:{} {} ",
|
||||
capabilities.userent.as_deref().unwrap_or("unknown user!"),
|
||||
@@ -280,6 +277,23 @@ pub(super) async fn shell(
|
||||
}
|
||||
pause.store(false, Ordering::Relaxed);
|
||||
}
|
||||
(Ok(SparseCommands::Cd { folder }), _) => {
|
||||
let Ok(_) = connection.send_command(Command::Cd(folder.clone())).await else {
|
||||
continue;
|
||||
};
|
||||
let resp = loop {
|
||||
let Ok(resp) = connection.get_response().await else {
|
||||
continue 'outer;
|
||||
};
|
||||
if let Response::CdDone(res) = resp {
|
||||
break res;
|
||||
}
|
||||
};
|
||||
match resp {
|
||||
Ok(rcwd) => cwd = rcwd.to_string_lossy().to_string(),
|
||||
Err(e) => eprintln!("{e}"),
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
if !input.to_string().trim().is_empty() && !pause.load(Ordering::Relaxed) {
|
||||
if let Err(e) = run_command(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use std::{
|
||||
net::{Ipv4Addr, SocketAddr, ToSocketAddrs},
|
||||
net::{SocketAddr, ToSocketAddrs},
|
||||
path::PathBuf,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user