runa_tui/
cli.rs

1use crate::config::Config;
2
3pub enum CliAction {
4    RunApp,
5    Exit,
6}
7
8pub fn handle_args() -> CliAction {
9    let args: Vec<String> = std::env::args().collect();
10    let config_path = Config::default_path();
11
12    if args.len() <= 1 {
13        return CliAction::RunApp;
14    }
15
16    match args[1].as_str() {
17        "-h" | "--help" => {
18            print_help();
19            CliAction::Exit
20        }
21        "--config-help" => {
22            print_config_help();
23            CliAction::Exit
24        }
25        "--init" => {
26            if let Err(e) = Config::generate_default(&config_path, true) {
27                eprintln!("Error: {}", e);
28            }
29            CliAction::Exit
30        }
31        "--init-full" => {
32            if let Err(e) = Config::generate_default(&config_path, false) {
33                eprintln!("Error: {}", e);
34            }
35            CliAction::Exit
36        }
37        arg => {
38            eprintln!("Unknown argument: {}", arg);
39            CliAction::Exit
40        }
41    }
42}
43
44fn print_help() {
45    println!(
46        r#"runa - A fast and lightweight console file browser written in Rust
47
48USAGE:
49    rn [OPTIONS]
50
51OPTIONS:
52    --help, -h            Print help information
53    --init                Generate full default config at ~/.config/runa/runa.toml
54    --init-minimal        Generate minimal config (overrides only)
55    --config-help         Display all the configuration options
56
57ENVIRONMENT:
58    RUNA_CONFIG         Override the default config path
59"#
60    );
61}
62
63fn print_config_help() {
64    let help_text = r##"
65runa - Full Configuration Guide (runa.toml)
66
67# General Settings
68  dirs_first              (bool)  Sort directories before files
69  show_hidden             (bool)  Show hidden files (dotfiles)
70  show_system             (bool)  Show system/protected files
71  case_insensitive        (bool)  Ignore case when searching/sorting
72  always_show             (list)  List of hidden names to always show
73
74[display]
75  selection_marker        (bool)  Show the cursor marker
76  dir_marker              (bool)  Show a marker for directories
77  borders                 (str)   "none", "unified", or "split"
78  titles                  (bool)  Show pane titles at the top
79  separators              (bool)  Draw vertical lines between panes
80  parent                  (bool)  Show the parent directory pane
81  preview                 (bool)  Show the file preview pane
82  preview_underline       (bool)  Use underline for preview selection instead of a highlighted selection
83  preview_underline_color (bool)  Use underline colors instead of selection colors
84  entry_padding           (usize) Entry padding for all the panes
85  scroll_padding          (usize) Scroll padding of the main pane
86
87[display.layout]
88  parent                  (u16)   Width % of the parent pane
89  main                    (u16)   Width % of the center pane
90  preview                 (u16)   Width % of the preview pane
91
92[theme]
93  selection_icon          (str)   The cursor string (e.g., "> ")
94
95# Theme sections          (Each supports "fg" and "bg" keys,)
96[theme.selection]         Selection bar colors    fg (str), bg (str)
97[theme.accent]            Border/title accents    fg (str), bg (str)
98[theme.entry]             Standard entry colors   fg (str), bg (str)
99[theme.directory]         Directory entry colors  fg (str), bg (str)
100[theme.separator]         Vertical line colors    fg (str), bg (str)
101[theme.parent]            Parent pane text        fg (str), bg (str)
102[theme.preview]           Preview pane text       fg (str), bg (str)
103[theme.path]              Path bar colors         fg (str), bg (str)
104[theme.underline]         Underline colors        fg (str), bg (str)
105[theme.widget]            Popup/widget settings:
106  position                (str/list/table)  "center", "top_left", "bottom_right", [38, 32], { x = 25, y = 60 }
107  size                    (str/list/table)  "small", "medium", "large", [38, 32], { w = 38, h = 32 }
108[theme.widget.color]      fg/bg for popups/widgets  fg (str), bg (str)
109[theme.widget.border]     fg/bg for popup borders   fg (str), bg (str)
110
111
112[editor]
113  cmd                    (str)   Command to open files (e.g., "nvim")
114
115[keys]
116  open_file              (list)  e.g., ["Enter"]
117  go_up                  (list)  e.g., ["k", "Up"]
118  go_down                (list)  e.g., ["j", "Down"]
119  go_parent              (list)  e.g., ["h", "Left", "Backspace"]
120  go_into_dir            (list)  e.g., ["l", "Right"]
121  quit                   (list)  e.g., ["q", "Esc"]
122  delete                 (list)  e.g., ["d"]
123  copy                   (list)  e.g., ["y"]
124  paste                  (list)  e.g., ["p"]
125  rename                 (list)  e.g., ["r"]
126  create                 (list)  e.g., ["n"]
127  create_directory       (list)  e.g., ["Shift+n"]
128  filter                 (list)  e.g., ["f"]
129  toggle_marker          (list)  e.g., [" "]
130
131Use 'Shift+x' or 'Ctrl+x' as needed. " " means space bar.
132
133EXAMPLES:
134  borders = "split"
135
136  [display.layout]
137  main = 40
138
139  [theme.accent]
140  fg = "#00ff00"
141  bg = "default"
142"##;
143
144    println!("{}", help_text);
145}