Repository: cantino/mcfly (language: rust)

Issue:
Please consider adding a config to enable/disable the tip/banner.
Please consider adding a config to enable/disable the tip/banner.


Discussion / hints:
I would like to claim this one and try to implement it. 

I have one idea on a potential solution. We add a boolean property to Settings called disable_menu. By default, it will be false. If users want to disable the menu, they can use an env variable to disable it. If the disable_menu is false, the menu will be displayed, otherwise disable the menu.

- settings.rs
```rust
pub struct Settings {
    // insert other properties
    pub disable_menu: bool,
}

impl Settings {
    pub fn parse_args() -> Settings {
        settings.disable_menu = match env::var_os("MCFLY_DISABLE_MENU") {
            Some(_val) => true,
            None => false,
        };
    }
}
```

- interface.rs
```rust
fn menubar<W: Write>(&self, screen: &mut W) {
    if !self.settings.disable_menu {
        // show menu
    }
 }
```
This seems reasonable @michaelnavs!

Fix patch:
diff --git a/README.md b/README.md
index f18d8332..bdd53c81 100644
--- a/README.md
+++ b/README.md
@@ -282,6 +282,19 @@ fish:
 set -gx MCFLY_INTERFACE_VIEW BOTTOM
 ```
 
+### Disable menu interface
+To disable the menu interface, set the environment variable `MCFLY_DISABLE_MENU`.
+
+bash / zsh:
+```bash
+export MCFLY_DISABLE_MENU=TRUE
+```
+
+fish:
+```bash
+set -gx MCFLY_DISABLE_MENU TRUE
+```
+
 ### Results sorting
 To change the sorting of results shown, set `MCFLY_RESULTS_SORT` (default: RANK).
 Possible values `RANK` and `LAST_RUN`
diff --git a/src/interface.rs b/src/interface.rs
index c246c783..6cdc8019 100644
--- a/src/interface.rs
+++ b/src/interface.rs
@@ -133,21 +133,23 @@ impl<'a> Interface<'a> {
     }
 
     fn menubar<W: Write>(&self, screen: &mut W) {
-        let (width, _height): (u16, u16) = terminal_size().unwrap();
-        write!(
-            screen,
-            "{hide}{cursor}{clear}{fg}{bg}{text:width$}{reset_bg}",
-            hide = cursor::Hide,
-            fg = color::Fg(color::LightWhite),
-            bg = self.menu_mode.bg(),
-            cursor = cursor::Goto(1, self.info_line_index()),
-            clear = clear::CurrentLine,
-            text = self.menu_mode.text(self),
-            reset_bg = color::Bg(color::Reset),
-            width = width as usize
-        )
-        .unwrap();
-        screen.flush().unwrap();
+        if !self.settings.disable_menu {
+            let (width, _height): (u16, u16) = terminal_size().unwrap();
+            write!(
+                screen,
+                "{hide}{cursor}{clear}{fg}{bg}{text:width$}{reset_bg}",
+                hide = cursor::Hide,
+                fg = color::Fg(color::LightWhite),
+                bg = self.menu_mode.bg(),
+                cursor = cursor::Goto(1, self.info_line_index()),
+                clear = clear::CurrentLine,
+                text = self.menu_mode.text(self),
+                reset_bg = color::Bg(color::Reset),
+                width = width as usize
+            )
+            .unwrap();
+            screen.flush().unwrap();
+        }
     }
 
     fn prompt<W: Write>(&self, screen: &mut W) {
diff --git a/src/settings.rs b/src/settings.rs
index 4b1cccb7..74f5581b 100644
--- a/src/settings.rs
+++ b/src/settings.rs
@@ -86,6 +86,7 @@ pub struct Settings {
     pub delete_without_confirm: bool,
     pub interface_view: InterfaceView,
     pub result_sort: ResultSort,
+    pub disable_menu: bool,
 }
 
 impl Default for Settings {
@@ -114,6 +115,7 @@ impl Default for Settings {
             delete_without_confirm: false,
             interface_view: InterfaceView::Top,
             result_sort: ResultSort::Rank,
+            disable_menu: false,
         }
     }
 }
@@ -480,6 +482,12 @@ impl Settings {
             Some(_val) => true,
             None => false,
         };
+
+        settings.disable_menu = match env::var_os("MCFLY_DISABLE_MENU") {
+            Some(_val) => true,
+            None => false,
+        };
+
         settings.key_scheme = match env::var("MCFLY_KEY_SCHEME").as_ref().map(String::as_ref) {
             Ok("vim") => KeyScheme::Vim,
             _ => KeyScheme::Emacs,


Test patch: