build: address clippy warnings
This commit is contained in:
parent
655f9d624c
commit
03432bf9bb
7 changed files with 47 additions and 46 deletions
4
build.rs
4
build.rs
|
@ -8,7 +8,7 @@ use vergen_gix::{BuildBuilder, CargoBuilder, Emitter, GixBuilder};
|
||||||
const ATPROTO_LEXICON_DIR: &str = "src/atproto/lexicons";
|
const ATPROTO_LEXICON_DIR: &str = "src/atproto/lexicons";
|
||||||
#[cfg(feature = "blog")]
|
#[cfg(feature = "blog")]
|
||||||
const ATPROTO_CLIENT_DIR: &str = "src/atproto";
|
const ATPROTO_CLIENT_DIR: &str = "src/atproto";
|
||||||
const SSH_KEY_ALGOS: &[(&'static str, Algorithm)] = &[
|
const SSH_KEY_ALGOS: &[(&str, Algorithm)] = &[
|
||||||
("rsa.pem", Algorithm::Rsa { hash: None }),
|
("rsa.pem", Algorithm::Rsa { hash: None }),
|
||||||
("ed25519.pem", Algorithm::Ed25519),
|
("ed25519.pem", Algorithm::Ed25519),
|
||||||
(
|
(
|
||||||
|
@ -25,7 +25,7 @@ fn main() -> Result<()> {
|
||||||
|
|
||||||
// Generate openSSH host keys
|
// Generate openSSH host keys
|
||||||
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
|
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
|
||||||
let mut rng = rand_core::OsRng::default();
|
let mut rng = rand_core::OsRng;
|
||||||
for (file_name, algo) in SSH_KEY_ALGOS {
|
for (file_name, algo) in SSH_KEY_ALGOS {
|
||||||
let path = out_dir.join(file_name);
|
let path = out_dir.join(file_name);
|
||||||
if path.exists() {
|
if path.exists() {
|
||||||
|
|
24
src/app.rs
24
src/app.rs
|
@ -113,7 +113,7 @@ impl App {
|
||||||
tui: Arc<RwLock<Option<Tui>>>,
|
tui: Arc<RwLock<Option<Tui>>>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let mut tui = tui.write().await;
|
let mut tui = tui.write().await;
|
||||||
let mut tui = tui.get_or_insert(
|
let tui = tui.get_or_insert(
|
||||||
Tui::new(term)?
|
Tui::new(term)?
|
||||||
.tick_rate(self.tick_rate)
|
.tick_rate(self.tick_rate)
|
||||||
.frame_rate(self.frame_rate),
|
.frame_rate(self.frame_rate),
|
||||||
|
@ -162,8 +162,8 @@ impl App {
|
||||||
let action_tx = self.action_tx.clone();
|
let action_tx = self.action_tx.clone();
|
||||||
let mut resume_tx: Option<Arc<CancellationToken>> = None;
|
let mut resume_tx: Option<Arc<CancellationToken>> = None;
|
||||||
loop {
|
loop {
|
||||||
self.handle_events(&mut tui).await?;
|
self.handle_events(tui).await?;
|
||||||
block_in_place(|| self.handle_actions(&mut tui))?;
|
block_in_place(|| self.handle_actions(tui))?;
|
||||||
if self.should_suspend {
|
if self.should_suspend {
|
||||||
if let Some(ref tx) = resume_tx {
|
if let Some(ref tx) = resume_tx {
|
||||||
tx.cancel();
|
tx.cancel();
|
||||||
|
@ -320,7 +320,7 @@ impl App {
|
||||||
.checked_sub(error_height)
|
.checked_sub(error_height)
|
||||||
.and_then(|n| n.checked_div(2))
|
.and_then(|n| n.checked_div(2))
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
if error_width < u16::MIN || error_width > size.width { u16::MIN } else { error_width },
|
if error_width > size.width { u16::MIN } else { error_width },
|
||||||
if size.height > error_height { error_height } else { size.height },
|
if size.height > error_height { error_height } else { size.height },
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -367,7 +367,7 @@ impl App {
|
||||||
let mut tabs = self
|
let mut tabs = self
|
||||||
.tabs
|
.tabs
|
||||||
.try_lock()
|
.try_lock()
|
||||||
.map_err(|err| std::io::Error::other(err))?;
|
.map_err(std::io::Error::other)?;
|
||||||
|
|
||||||
tabs.draw(
|
tabs.draw(
|
||||||
frame,
|
frame,
|
||||||
|
@ -378,7 +378,7 @@ impl App {
|
||||||
height: chunks[0].height,
|
height: chunks[0].height,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.map_err(|err| std::io::Error::other(err))?;
|
.map_err(std::io::Error::other)?;
|
||||||
|
|
||||||
// Render the content
|
// Render the content
|
||||||
let content_rect = Rect {
|
let content_rect = Rect {
|
||||||
|
@ -390,16 +390,16 @@ impl App {
|
||||||
|
|
||||||
self.content
|
self.content
|
||||||
.try_lock()
|
.try_lock()
|
||||||
.map_err(|err| std::io::Error::other(err))?
|
.map_err(std::io::Error::other)?
|
||||||
.draw(frame, content_rect)
|
.draw(frame, content_rect)
|
||||||
.map_err(|err| std::io::Error::other(err))?;
|
.map_err(std::io::Error::other)?;
|
||||||
|
|
||||||
// Render the eepy cat :3
|
// Render the eepy cat :3
|
||||||
self.cat
|
self.cat
|
||||||
.try_lock()
|
.try_lock()
|
||||||
.map_err(|err| std::io::Error::other(err))?
|
.map_err(std::io::Error::other)?
|
||||||
.draw(frame, frame.area())
|
.draw(frame, frame.area())
|
||||||
.map_err(|err| std::io::Error::other(err))?;
|
.map_err(std::io::Error::other)?;
|
||||||
|
|
||||||
if tabs.current_tab() == 2 {
|
if tabs.current_tab() == 2 {
|
||||||
let mut content_rect = content_rect;
|
let mut content_rect = content_rect;
|
||||||
|
@ -413,9 +413,9 @@ impl App {
|
||||||
// Render the post selection list if the blog tab is selected
|
// Render the post selection list if the blog tab is selected
|
||||||
self.selection_list
|
self.selection_list
|
||||||
.try_lock()
|
.try_lock()
|
||||||
.map_err(|err| std::io::Error::other(err))?
|
.map_err(std::io::Error::other)?
|
||||||
.draw(frame, content_rect)
|
.draw(frame, content_rect)
|
||||||
.map_err(|err| std::io::Error::other(err))?;
|
.map_err(std::io::Error::other)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "blog"))]
|
#[cfg(not(feature = "blog"))]
|
||||||
|
|
|
@ -69,7 +69,7 @@ pub mod blog {
|
||||||
.com
|
.com
|
||||||
.atproto
|
.atproto
|
||||||
.repo
|
.repo
|
||||||
.list_records(Object::from(list_records::Parameters {
|
.list_records(list_records::Parameters {
|
||||||
extra_data: Ipld::Null,
|
extra_data: Ipld::Null,
|
||||||
data: list_records::ParametersData {
|
data: list_records::ParametersData {
|
||||||
collection: com::whtwnd::blog::Entry::nsid(),
|
collection: com::whtwnd::blog::Entry::nsid(),
|
||||||
|
@ -81,7 +81,7 @@ pub mod blog {
|
||||||
.map_err(|_| eyre!("Invalid repo handle"))?,
|
.map_err(|_| eyre!("Invalid repo handle"))?,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
}))
|
})
|
||||||
.await?
|
.await?
|
||||||
.records;
|
.records;
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ impl KeyCodeExt for KeyCode {
|
||||||
19 => KeyCode::Pause,
|
19 => KeyCode::Pause,
|
||||||
|
|
||||||
// Anything else
|
// Anything else
|
||||||
0 | _ => KeyCode::Null,
|
_ => KeyCode::Null,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
17
src/main.rs
17
src/main.rs
|
@ -37,8 +37,8 @@ const SSH_KEYS: &[&[u8]] = &[
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub(crate) static ref OPTIONS: Cli = Cli::parse();
|
pub(crate) static ref OPTIONS: Cli = Cli::parse();
|
||||||
pub(crate) static ref SSH_SOCKET_ADDR: Option<SocketAddr> = SocketAddr::try_from((host_ip().ok()?, OPTIONS.ssh_port)).ok();
|
pub(crate) static ref SSH_SOCKET_ADDR: Option<SocketAddr> = Some(SocketAddr::from((host_ip().ok()?, OPTIONS.ssh_port)));
|
||||||
pub(crate) static ref WEB_SERVER_ADDR: Option<SocketAddr> = SocketAddr::try_from((host_ip().ok()?, OPTIONS.web_port)).ok();
|
pub(crate) static ref WEB_SERVER_ADDR: Option<SocketAddr> = Some(SocketAddr::from((host_ip().ok()?, OPTIONS.web_port)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
|
@ -63,7 +63,8 @@ pub fn host_ip() -> Result<[u8; 4]> {
|
||||||
.host
|
.host
|
||||||
.splitn(4, ".")
|
.splitn(4, ".")
|
||||||
.map(|octet_str| {
|
.map(|octet_str| {
|
||||||
u8::from_str_radix(octet_str, 10)
|
octet_str
|
||||||
|
.parse::<u8>()
|
||||||
.map_err(|_| eyre!("Octet component out of range (expected u8)"))
|
.map_err(|_| eyre!("Octet component out of range (expected u8)"))
|
||||||
})
|
})
|
||||||
.collect::<Result<Vec<u8>>>()?,
|
.collect::<Result<Vec<u8>>>()?,
|
||||||
|
@ -72,13 +73,15 @@ pub fn host_ip() -> Result<[u8; 4]> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ssh_config() -> Config {
|
fn ssh_config() -> Config {
|
||||||
let mut conf = Config::default();
|
let conf = Config {
|
||||||
conf.methods = MethodSet::NONE;
|
methods: MethodSet::NONE,
|
||||||
conf.keys = SSH_KEYS
|
keys: SSH_KEYS
|
||||||
.to_vec()
|
.to_vec()
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|pem| PrivateKey::from_openssh(pem).ok())
|
.filter_map(|pem| PrivateKey::from_openssh(pem).ok())
|
||||||
.collect();
|
.collect(),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
tracing::trace!("SSH config: {:#?}", conf);
|
tracing::trace!("SSH config: {:#?}", conf);
|
||||||
conf
|
conf
|
||||||
|
|
|
@ -47,7 +47,7 @@ impl TermWriter {
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
std::io::Error::other(String::from_iter(err.iter().map(|item| *item as char)))
|
std::io::Error::other(String::from_iter(err.iter().map(|item| *item as char)))
|
||||||
})
|
})
|
||||||
.and_then(|()| Ok(self.inner.clear()))
|
.map(|_| self.inner.clear())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,6 +70,7 @@ impl Write for TermWriter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::type_complexity)]
|
||||||
pub struct SshSession {
|
pub struct SshSession {
|
||||||
app: Option<Arc<Mutex<App>>>,
|
app: Option<Arc<Mutex<App>>>,
|
||||||
keystroke_tx: mpsc::UnboundedSender<Vec<u8>>,
|
keystroke_tx: mpsc::UnboundedSender<Vec<u8>>,
|
||||||
|
@ -250,7 +251,7 @@ impl SshServer {
|
||||||
pub async fn start(addr: SocketAddr, config: Config) -> eyre::Result<()> {
|
pub async fn start(addr: SocketAddr, config: Config) -> eyre::Result<()> {
|
||||||
let listener = TcpListener::bind(addr).await?;
|
let listener = TcpListener::bind(addr).await?;
|
||||||
|
|
||||||
Self::default()
|
Self
|
||||||
.run_on_socket(Arc::new(config), &listener)
|
.run_on_socket(Arc::new(config), &listener)
|
||||||
.await
|
.await
|
||||||
.map_err(|err| eyre!(err))
|
.map_err(|err| eyre!(err))
|
||||||
|
@ -263,7 +264,7 @@ impl Server for SshServer {
|
||||||
|
|
||||||
#[instrument(skip(self))]
|
#[instrument(skip(self))]
|
||||||
fn new_client(&mut self, peer_addr: Option<SocketAddr>) -> Self::Handler {
|
fn new_client(&mut self, peer_addr: Option<SocketAddr>) -> Self::Handler {
|
||||||
let session = tokio::task::block_in_place(|| SshSession::new());
|
|
||||||
session
|
tokio::task::block_in_place(SshSession::new)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -165,7 +165,7 @@ impl Tui {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Err(_) = timeout(attempt_timeout, self.await_shutdown()).await {
|
if timeout(attempt_timeout, self.await_shutdown()).await.is_err() {
|
||||||
timeout(attempt_timeout, abort_shutdown)
|
timeout(attempt_timeout, abort_shutdown)
|
||||||
.await
|
.await
|
||||||
.inspect_err(|_| {
|
.inspect_err(|_| {
|
||||||
|
@ -198,7 +198,6 @@ impl Tui {
|
||||||
pub async fn exit(&mut self) -> Result<()> {
|
pub async fn exit(&mut self) -> Result<()> {
|
||||||
self.stop().await?;
|
self.stop().await?;
|
||||||
// TODO: enable raw mode for pty
|
// TODO: enable raw mode for pty
|
||||||
if true || crossterm::terminal::is_raw_mode_enabled()? {
|
|
||||||
let mut term = self.terminal.try_lock()?;
|
let mut term = self.terminal.try_lock()?;
|
||||||
term.flush()?;
|
term.flush()?;
|
||||||
|
|
||||||
|
@ -211,8 +210,6 @@ impl Tui {
|
||||||
}
|
}
|
||||||
|
|
||||||
crossterm::execute!(term.backend_mut(), LeaveAlternateScreen, cursor::Show)?;
|
crossterm::execute!(term.backend_mut(), LeaveAlternateScreen, cursor::Show)?;
|
||||||
// crossterm::terminal::disable_raw_mode()?; // TODO: disable raw mode
|
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue