runa-tui 0.6.2

A fast, keyboard-focused terminal file manager (TUI). Highly configurable and lightweight.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
//! Display configuration options for runa
//!
//! This module defines the display configuration options which are read from the runa.toml
//! configuration file.

use crate::ui::widgets::DialogPosition;
use ratatui::widgets::BorderType;
use serde::Deserialize;

/// Display configuration options
///
/// This struct holds various options related to the display of the file manager,
/// including border styles, preview settings, layout ratios, and more.
/// These options can be customized by the user in the configuration file.
/// The struct derives `Deserialize` to allow easy loading from a TOML file,
/// and `Debug` for convenient debugging output.
///
/// Default values are provided for all options to ensure a consistent user experience
/// even if the user does not specify certain settings.
#[derive(Deserialize, Debug)]
#[serde(default)]
pub(crate) struct Display {
    selection_marker: bool,
    dir_marker: bool,
    borders: BorderStyle,
    border_shape: BorderShape,
    titles: bool,
    icons: bool,
    separators: bool,
    parent: bool,
    preview: bool,
    preview_underline: bool,
    preview_underline_color: bool,
    entry_padding: u8,
    scroll_padding: usize,
    toggle_marker_jump: bool,
    instant_preview: bool,
    entry_count: EntryCountPosition,
    preview_options: PreviewOptions,
    layout: LayoutConfig,
    info: ShowInfoOptions,
}

/// Public methods for accessing display configuration options
impl Display {
    #[inline]
    pub(crate) fn selection_marker(&self) -> bool {
        self.selection_marker
    }

    #[inline]
    pub(crate) fn dir_marker(&self) -> bool {
        self.dir_marker
    }

    #[inline]
    pub(crate) fn is_unified(&self) -> bool {
        matches!(self.borders, BorderStyle::Unified)
    }

    #[inline]
    pub(crate) fn is_split(&self) -> bool {
        matches!(self.borders, BorderStyle::Split)
    }

    #[inline]
    pub(crate) fn border_shape(&self) -> &BorderShape {
        &self.border_shape
    }

    #[inline]
    pub(crate) fn titles(&self) -> bool {
        self.titles
    }

    #[inline]
    pub(crate) fn icons(&self) -> bool {
        self.icons
    }

    #[inline]
    pub(crate) fn separators(&self) -> bool {
        self.separators
    }

    #[inline]
    pub(crate) fn parent(&self) -> bool {
        self.parent
    }

    #[inline]
    pub(crate) fn preview(&self) -> bool {
        self.preview
    }

    #[inline]
    pub(crate) fn parent_ratio(&self) -> u16 {
        self.layout.parent_ratio()
    }

    #[inline]
    pub(crate) fn main_ratio(&self) -> u16 {
        self.layout.main_ratio()
    }

    #[inline]
    pub(crate) fn preview_ratio(&self) -> u16 {
        self.layout.preview_ratio()
    }

    #[inline]
    pub(crate) fn preview_underline(&self) -> bool {
        self.preview_underline
    }

    #[inline]
    pub(crate) fn preview_underline_color(&self) -> bool {
        self.preview_underline_color
    }

    #[inline]
    pub(crate) fn entry_padding(&self) -> u8 {
        self.entry_padding
    }

    #[inline]
    pub(crate) fn scroll_padding(&self) -> usize {
        self.scroll_padding
    }

    #[inline]
    pub(crate) fn toggle_marker_jump(&self) -> bool {
        self.toggle_marker_jump
    }

    #[inline]
    pub(crate) fn instant_preview(&self) -> bool {
        self.instant_preview
    }

    #[inline]
    pub(crate) fn entry_count(&self) -> EntryCountPosition {
        self.entry_count
    }

    #[inline]
    pub(crate) fn preview_options(&self) -> &PreviewOptions {
        &self.preview_options
    }

    #[inline]
    pub(crate) fn info(&self) -> &ShowInfoOptions {
        &self.info
    }

    /// Get padding string based on entry_padding
    pub(crate) fn padding_str(&self) -> &'static str {
        // ASCII whitespaces
        match self.entry_padding {
            0 => "",
            1 => " ",
            2 => "  ",
            3 => "   ",
            _ => "    ",
        }
    }
}

/// Default display configuration options
impl Default for Display {
    fn default() -> Self {
        Display {
            selection_marker: false,
            dir_marker: true,
            borders: BorderStyle::Unified,
            border_shape: BorderShape::Square,
            titles: true,
            icons: false,
            separators: true,
            parent: true,
            preview: true,
            preview_underline: true,
            preview_underline_color: false,
            entry_padding: 1,
            scroll_padding: 5,
            toggle_marker_jump: false,
            instant_preview: true,
            layout: LayoutConfig::default(),
            entry_count: EntryCountPosition::default(),
            preview_options: PreviewOptions::default(),
            info: ShowInfoOptions::default(),
        }
    }
}

/// Layout configuration for the display panes
/// This struct holds the ratio settings for the parent, main, and preview panes
#[derive(Deserialize, Debug)]
#[serde(default)]
pub(crate) struct LayoutConfig {
    parent: u16,
    main: u16,
    preview: u16,
}

/// Public methods for accessing layout configuration options
impl LayoutConfig {
    #[inline]
    fn parent_ratio(&self) -> u16 {
        self.parent
    }

    #[inline]
    fn main_ratio(&self) -> u16 {
        self.main
    }

    #[inline]
    fn preview_ratio(&self) -> u16 {
        self.preview
    }
}

impl Default for LayoutConfig {
    fn default() -> Self {
        Self {
            parent: 20,
            main: 40,
            preview: 40,
        }
    }
}

/// Entry count position options
/// This enum defines the possible positions for displaying the entry count
#[derive(Deserialize, Debug, Default, Clone, Copy, PartialEq)]
#[serde(rename_all = "lowercase")]
pub(crate) enum EntryCountPosition {
    #[default]
    Footer,
    Header,
    None,
}

/// Options for showing file information in the info dialog
/// This struct holds boolean flags for various file attributes
/// that can be displayed, as well as an optional position for the dialog
///
/// Positions can be specified using the DialogPosition enum
#[derive(Deserialize, Debug)]
#[serde(default)]
pub(crate) struct ShowInfoOptions {
    name: bool,
    file_type: bool,
    size: bool,
    modified: bool,
    perms: bool,
    position: Option<DialogPosition>,
}

/// Public methods for accessing show info configuration options
impl ShowInfoOptions {
    #[inline]
    pub(crate) fn name(&self) -> bool {
        self.name
    }

    #[inline]
    pub(crate) fn file_type(&self) -> bool {
        self.file_type
    }

    #[inline]
    pub(crate) fn size(&self) -> bool {
        self.size
    }

    #[inline]
    pub(crate) fn modified(&self) -> bool {
        self.modified
    }

    #[inline]
    pub(crate) fn perms(&self) -> bool {
        self.perms
    }

    #[inline]
    pub(crate) fn position(&self) -> &Option<DialogPosition> {
        &self.position
    }
}

/// Default show info configuration options
impl Default for ShowInfoOptions {
    fn default() -> Self {
        ShowInfoOptions {
            name: true,
            file_type: false,
            size: true,
            modified: true,
            perms: true,
            position: None,
        }
    }
}

/// Preview method options
/// This enum defines the available methods for previewing file contents
/// - Internal: Use the built-in preview functionality
/// - Bat: Use the external 'bat' command for previewing
#[derive(Deserialize, Debug, Clone, PartialEq)]
#[serde(rename_all = "lowercase")]
pub(crate) enum PreviewMethod {
    Internal,
    Bat,
}

/// Bat style options for file previewing
/// This enum defines the different styles that can be used with the 'bat' command
/// - Plain: No line numbers or decorations
/// - Numbers: Line numbers only
/// - Full: Full decorations including line numbers and and grid
#[derive(Deserialize, Debug, Clone, Copy, Default)]
#[serde(rename_all = "lowercase")]
pub(crate) enum BatStyle {
    #[default]
    Plain,
    Numbers,
    Full,
}

/// Preview configuration options
/// This struct holds various options related to file previewing,
/// including the preview method, bat style, and text wrapping.
/// These options can be customized by the user in the configuration file.
#[derive(Deserialize, Debug, Clone)]
pub(crate) struct PreviewOptions {
    #[serde(default = "PreviewOptions::default_method")]
    method: PreviewMethod,
    #[serde(default)]
    style: BatStyle,
    #[serde(default)]
    theme: Option<String>,
    #[serde(default = "PreviewOptions::default_wrap")]
    wrap: bool,
}

/// Public methods for accessing preview configuration options
impl PreviewOptions {
    fn default() -> Self {
        PreviewOptions {
            method: PreviewMethod::Internal,
            style: BatStyle::Plain,
            theme: None,
            wrap: false,
        }
    }

    fn default_method() -> PreviewMethod {
        PreviewMethod::Internal
    }

    #[inline]
    fn default_wrap() -> bool {
        false
    }

    #[inline]
    pub(crate) fn method(&self) -> &PreviewMethod {
        &self.method
    }

    /// Generate command-line arguments for the 'bat' command based on the preview options
    /// and the given theme name and pane width.
    /// # Returns
    /// A vector of strings representing the command-line arguments for 'bat'
    pub(crate) fn bat_args(&self, default_theme: &str, pane_width: usize) -> Vec<String> {
        let mut args = Vec::with_capacity(10);
        args.push("--color=always".to_string());
        args.push("--paging=never".to_string());
        args.push(format!("--terminal-width={}", pane_width));
        args.push(
            match self.style {
                BatStyle::Plain => "--style=plain",
                BatStyle::Numbers => "--style=numbers",
                BatStyle::Full => "--style=full",
            }
            .to_string(),
        );

        args.push("--theme".to_owned());
        args.push(self.theme.as_deref().unwrap_or(default_theme).to_string());

        args.push(
            if self.wrap {
                "--wrap=character"
            } else {
                "--wrap=never"
            }
            .to_string(),
        );

        args
    }
}

/// Border style options
/// This enum defines the different border styles that can be used in the UI
#[derive(Deserialize, Debug, Clone, PartialEq)]
#[serde(rename_all = "lowercase")]
pub(crate) enum BorderStyle {
    None,
    Unified,
    Split,
}

/// Border shape options
/// This enum defines the different border shapes that can be used in the UI
#[derive(Deserialize, Debug, Clone, PartialEq)]
#[serde(rename_all = "lowercase")]
pub(crate) enum BorderShape {
    Square,
    Rounded,
    Double,
    Thick,
}

/// Public methods for accessing border shape options
impl BorderShape {
    pub(crate) fn as_border_type(&self) -> BorderType {
        match self {
            BorderShape::Square => BorderType::Plain,
            BorderShape::Rounded => BorderType::Rounded,
            BorderShape::Double => BorderType::Double,
            BorderShape::Thick => BorderType::Thick,
        }
    }
}