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";
|
||||
#[cfg(feature = "blog")]
|
||||
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 }),
|
||||
("ed25519.pem", Algorithm::Ed25519),
|
||||
(
|
||||
|
@ -25,7 +25,7 @@ fn main() -> Result<()> {
|
|||
|
||||
// Generate openSSH host keys
|
||||
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 {
|
||||
let path = out_dir.join(file_name);
|
||||
if path.exists() {
|
||||
|
|
24
src/app.rs
24
src/app.rs
|
@ -113,7 +113,7 @@ impl App {
|
|||
tui: Arc<RwLock<Option<Tui>>>,
|
||||
) -> Result<()> {
|
||||
let mut tui = tui.write().await;
|
||||
let mut tui = tui.get_or_insert(
|
||||
let tui = tui.get_or_insert(
|
||||
Tui::new(term)?
|
||||
.tick_rate(self.tick_rate)
|
||||
.frame_rate(self.frame_rate),
|
||||
|
@ -162,8 +162,8 @@ impl App {
|
|||
let action_tx = self.action_tx.clone();
|
||||
let mut resume_tx: Option<Arc<CancellationToken>> = None;
|
||||
loop {
|
||||
self.handle_events(&mut tui).await?;
|
||||
block_in_place(|| self.handle_actions(&mut tui))?;
|
||||
self.handle_events(tui).await?;
|
||||
block_in_place(|| self.handle_actions(tui))?;
|
||||
if self.should_suspend {
|
||||
if let Some(ref tx) = resume_tx {
|
||||
tx.cancel();
|
||||
|
@ -320,7 +320,7 @@ impl App {
|
|||
.checked_sub(error_height)
|
||||
.and_then(|n| n.checked_div(2))
|
||||
.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 },
|
||||
));
|
||||
|
||||
|
@ -367,7 +367,7 @@ impl App {
|
|||
let mut tabs = self
|
||||
.tabs
|
||||
.try_lock()
|
||||
.map_err(|err| std::io::Error::other(err))?;
|
||||
.map_err(std::io::Error::other)?;
|
||||
|
||||
tabs.draw(
|
||||
frame,
|
||||
|
@ -378,7 +378,7 @@ impl App {
|
|||
height: chunks[0].height,
|
||||
},
|
||||
)
|
||||
.map_err(|err| std::io::Error::other(err))?;
|
||||
.map_err(std::io::Error::other)?;
|
||||
|
||||
// Render the content
|
||||
let content_rect = Rect {
|
||||
|
@ -390,16 +390,16 @@ impl App {
|
|||
|
||||
self.content
|
||||
.try_lock()
|
||||
.map_err(|err| std::io::Error::other(err))?
|
||||
.map_err(std::io::Error::other)?
|
||||
.draw(frame, content_rect)
|
||||
.map_err(|err| std::io::Error::other(err))?;
|
||||
.map_err(std::io::Error::other)?;
|
||||
|
||||
// Render the eepy cat :3
|
||||
self.cat
|
||||
.try_lock()
|
||||
.map_err(|err| std::io::Error::other(err))?
|
||||
.map_err(std::io::Error::other)?
|
||||
.draw(frame, frame.area())
|
||||
.map_err(|err| std::io::Error::other(err))?;
|
||||
.map_err(std::io::Error::other)?;
|
||||
|
||||
if tabs.current_tab() == 2 {
|
||||
let mut content_rect = content_rect;
|
||||
|
@ -413,9 +413,9 @@ impl App {
|
|||
// Render the post selection list if the blog tab is selected
|
||||
self.selection_list
|
||||
.try_lock()
|
||||
.map_err(|err| std::io::Error::other(err))?
|
||||
.map_err(std::io::Error::other)?
|
||||
.draw(frame, content_rect)
|
||||
.map_err(|err| std::io::Error::other(err))?;
|
||||
.map_err(std::io::Error::other)?;
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "blog"))]
|
||||
|
|
|
@ -69,7 +69,7 @@ pub mod blog {
|
|||
.com
|
||||
.atproto
|
||||
.repo
|
||||
.list_records(Object::from(list_records::Parameters {
|
||||
.list_records(list_records::Parameters {
|
||||
extra_data: Ipld::Null,
|
||||
data: list_records::ParametersData {
|
||||
collection: com::whtwnd::blog::Entry::nsid(),
|
||||
|
@ -81,7 +81,7 @@ pub mod blog {
|
|||
.map_err(|_| eyre!("Invalid repo handle"))?,
|
||||
),
|
||||
},
|
||||
}))
|
||||
})
|
||||
.await?
|
||||
.records;
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ impl KeyCodeExt for KeyCode {
|
|||
19 => KeyCode::Pause,
|
||||
|
||||
// Anything else
|
||||
0 | _ => KeyCode::Null,
|
||||
_ => KeyCode::Null,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
23
src/main.rs
23
src/main.rs
|
@ -37,8 +37,8 @@ const SSH_KEYS: &[&[u8]] = &[
|
|||
#[rustfmt::skip]
|
||||
lazy_static! {
|
||||
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 WEB_SERVER_ADDR: Option<SocketAddr> = SocketAddr::try_from((host_ip().ok()?, OPTIONS.web_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> = Some(SocketAddr::from((host_ip().ok()?, OPTIONS.web_port)));
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
|
@ -63,7 +63,8 @@ pub fn host_ip() -> Result<[u8; 4]> {
|
|||
.host
|
||||
.splitn(4, ".")
|
||||
.map(|octet_str| {
|
||||
u8::from_str_radix(octet_str, 10)
|
||||
octet_str
|
||||
.parse::<u8>()
|
||||
.map_err(|_| eyre!("Octet component out of range (expected u8)"))
|
||||
})
|
||||
.collect::<Result<Vec<u8>>>()?,
|
||||
|
@ -72,13 +73,15 @@ pub fn host_ip() -> Result<[u8; 4]> {
|
|||
}
|
||||
|
||||
fn ssh_config() -> Config {
|
||||
let mut conf = Config::default();
|
||||
conf.methods = MethodSet::NONE;
|
||||
conf.keys = SSH_KEYS
|
||||
.to_vec()
|
||||
.iter()
|
||||
.filter_map(|pem| PrivateKey::from_openssh(pem).ok())
|
||||
.collect();
|
||||
let conf = Config {
|
||||
methods: MethodSet::NONE,
|
||||
keys: SSH_KEYS
|
||||
.to_vec()
|
||||
.iter()
|
||||
.filter_map(|pem| PrivateKey::from_openssh(pem).ok())
|
||||
.collect(),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
tracing::trace!("SSH config: {:#?}", conf);
|
||||
conf
|
||||
|
|
|
@ -47,7 +47,7 @@ impl TermWriter {
|
|||
.map_err(|err| {
|
||||
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 {
|
||||
app: Option<Arc<Mutex<App>>>,
|
||||
keystroke_tx: mpsc::UnboundedSender<Vec<u8>>,
|
||||
|
@ -250,7 +251,7 @@ impl SshServer {
|
|||
pub async fn start(addr: SocketAddr, config: Config) -> eyre::Result<()> {
|
||||
let listener = TcpListener::bind(addr).await?;
|
||||
|
||||
Self::default()
|
||||
Self
|
||||
.run_on_socket(Arc::new(config), &listener)
|
||||
.await
|
||||
.map_err(|err| eyre!(err))
|
||||
|
@ -263,7 +264,7 @@ impl Server for SshServer {
|
|||
|
||||
#[instrument(skip(self))]
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -157,7 +157,7 @@ impl Tui {
|
|||
|
||||
pub async fn stop(&self) -> Result<()> {
|
||||
self.cancel();
|
||||
|
||||
|
||||
let attempt_timeout = Duration::from_millis(50);
|
||||
let abort_shutdown = async {
|
||||
while !self.task.is_finished() {
|
||||
|
@ -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)
|
||||
.await
|
||||
.inspect_err(|_| {
|
||||
|
@ -198,21 +198,18 @@ impl Tui {
|
|||
pub async fn exit(&mut self) -> Result<()> {
|
||||
self.stop().await?;
|
||||
// TODO: enable raw mode for pty
|
||||
if true || crossterm::terminal::is_raw_mode_enabled()? {
|
||||
let mut term = self.terminal.try_lock()?;
|
||||
term.flush()?;
|
||||
let mut term = self.terminal.try_lock()?;
|
||||
term.flush()?;
|
||||
|
||||
if self.paste {
|
||||
crossterm::execute!(term.backend_mut(), DisableBracketedPaste)?;
|
||||
}
|
||||
|
||||
if self.mouse {
|
||||
crossterm::execute!(term.backend_mut(), DisableMouseCapture)?;
|
||||
}
|
||||
|
||||
crossterm::execute!(term.backend_mut(), LeaveAlternateScreen, cursor::Show)?;
|
||||
// crossterm::terminal::disable_raw_mode()?; // TODO: disable raw mode
|
||||
if self.paste {
|
||||
crossterm::execute!(term.backend_mut(), DisableBracketedPaste)?;
|
||||
}
|
||||
|
||||
if self.mouse {
|
||||
crossterm::execute!(term.backend_mut(), DisableMouseCapture)?;
|
||||
}
|
||||
|
||||
crossterm::execute!(term.backend_mut(), LeaveAlternateScreen, cursor::Show)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue