فهرست منبع

Address clippy nits.

Kestrel 1 روز پیش
والد
کامیت
2dc81c1546
2فایلهای تغییر یافته به همراه9 افزوده شده و 14 حذف شده
  1. 0 4
      derive/src/lib.rs
  2. 9 10
      src/lib.rs

+ 0 - 4
derive/src/lib.rs

@@ -1,5 +1,3 @@
-use std::collections::BTreeMap;
-
 use quote::quote;
 
 fn do_action(input: syn::DeriveInput) -> Result<proc_macro::TokenStream, syn::Error> {
@@ -18,7 +16,6 @@ fn do_action(input: syn::DeriveInput) -> Result<proc_macro::TokenStream, syn::Er
 
     for var in enumdata.variants.iter() {
         let name = var.ident.to_string();
-        println!("variant name: {}", name);
 
         let Some(key) = name.chars().filter(|v| v.is_uppercase() && !keys.contains(v)).next() else {
             return Err(syn::Error::new(var.ident.span(), "no unused key for action entry"))
@@ -64,4 +61,3 @@ pub fn action(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
         Err(err) => err.to_compile_error().into()
     }
 }
-

+ 9 - 10
src/lib.rs

@@ -54,8 +54,8 @@ impl<AE: ActionEnum> ActionPrompt<AE> {
             let key_string = key.to_string();
             let Some((before,after)) = label.split_once(&key_string) else { continue };
 
-            if line.len() > 0 {
-                line.push_str("/");
+            if !line.is_empty() {
+                line.push('/');
             }
 
             line += format!("{reset}{before}{underline}{red}{key_string}{reset}{after}").as_str();
@@ -67,14 +67,14 @@ impl<AE: ActionEnum> ActionPrompt<AE> {
 
         line += format!(" {green}?{reset} ").as_str();
 
-        stdout.write(line.as_bytes())?;
+        stdout.write_all(line.as_bytes())?;
         stdout.flush()?;
         
         Ok(())
     }
 
     fn wait_for_answer(self, cancellable: bool) -> Result<Option<AE>, AskError> {
-        let _rawlock = std::io::stdout().into_raw_mode()?;
+        let stdoutlock = std::io::stdout().into_raw_mode()?;
 
         let stdin = std::io::stdin();
 
@@ -105,7 +105,7 @@ impl<AE: ActionEnum> ActionPrompt<AE> {
             }
         };
 
-        drop(_rawlock);
+        drop(stdoutlock);
 
         let reset = termion::style::Reset;
         let underline = termion::style::Underline;
@@ -160,7 +160,7 @@ impl<'l, T: std::fmt::Display> SelectPrompt<'l, T> {
             self.items.sort_by_cached_key(|v| v.0.clone());
         }
 
-        for _ in 0..self.height { writeln!(stdout, "")? };
+        for _ in 0..self.height { writeln!(stdout)? };
 
         write!(stdout, "{}{}",
             termion::cursor::Up(self.height as u16),
@@ -193,7 +193,7 @@ impl<'l, T: std::fmt::Display> SelectPrompt<'l, T> {
         }
     }
 
-    fn append_column(remaining_width: usize, rows: &mut Vec<String>, col: &mut Vec<&str>) -> Option<usize> {
+    fn append_column(remaining_width: usize, rows: &mut [String], col: &mut Vec<&str>) -> Option<usize> {
         if col.is_empty() || remaining_width == 0 {
             return None
         }
@@ -202,7 +202,7 @@ impl<'l, T: std::fmt::Display> SelectPrompt<'l, T> {
         let widths = col.iter().map(|v| v.graphemes(true).count()).collect::<Vec<_>>();
         let max_width = *widths.iter().max().unwrap() + 2;
 
-        let Some(newrem) = remaining_width.checked_sub(max_width) else { return None };
+        let newrem = remaining_width.checked_sub(max_width)?;
 
         for (row, (col, width)) in rows.iter_mut().zip(col.drain(..).zip(widths.into_iter())) {
             row.push_str(col);
@@ -262,11 +262,10 @@ impl<'l, T: std::fmt::Display> SelectPrompt<'l, T> {
     }
 
     fn input_loop(&mut self, stdout: &mut std::io::Stdout, cancellable: bool) -> Result<Option<T>, AskError> {
-        let mut keys = std::io::stdin().keys();
         let mut raw = stdout.into_raw_mode()?;
         self.refilter();
         self.repaint(&mut raw)?;
-        while let Some(key) = keys.next() {
+        for key in std::io::stdin().keys() {
             let key = key?;
 
             match key {