瀏覽代碼

[UI] Default category is now proposed to user in input request

Signed-off-by: Slava Barinov <rayslava@gmail.com>
Slava Barinov 4 年之前
父節點
當前提交
9782574158
共有 3 個文件被更改,包括 8 次插入8 次删除
  1. 0 1
      Cargo.toml
  2. 6 5
      src/categories.rs
  3. 2 2
      src/ui.rs

+ 0 - 1
Cargo.toml

@@ -16,7 +16,6 @@ shellexpand = "2.1"
 radix_trie = { version = "0.2", features = ["serde"] }
 libc = { version = "0.2" }
 const_format = "0.2"
-
 teloxide = { version = "0.4.0", features = ["auto-send", "macros"], optional = true }
 log = { version = "0.4.8", optional = true }
 pretty_env_logger = { version = "0.4.0", optional = true }

+ 6 - 5
src/categories.rs

@@ -77,12 +77,13 @@ pub fn get_top_category<'a>(item: &str, storage: &'a CatStats) -> Option<&'a str
 pub fn get_category(item: &str, storage: &mut CatStats) -> String {
     let istty = unsafe { isatty(libc::STDOUT_FILENO as i32) } != 0;
     if istty {
-        let cat = input_category(item);
+        let topcat = match get_top_category(item, storage) {
+            Some(cat) => String::from(cat),
+            None => String::new(),
+        };
+        let cat = input_category(item, &topcat);
         if cat.is_empty() {
-            match get_top_category(item, storage) {
-                Some(cat) => String::from(cat),
-                None => String::new(),
-            }
+            topcat
         } else {
             assign_category(&item, &cat, storage);
             cat

+ 2 - 2
src/ui.rs

@@ -19,9 +19,9 @@ pub fn run_tv() {
     println!("Hello, world!");
 }
 
-pub fn input_category(item: &str) -> String {
+pub fn input_category(item: &str, cat: &str) -> String {
     let mut x = String::with_capacity(64);
-    print!("Category for '{}'? > ", item);
+    print!("'{}'? (default: {}) > ", item, cat);
     let _ = stdout().flush();
     stdin().read_line(&mut x).expect("Error reading input");
     String::from(x.trim_end_matches('\n'))