Skip to main content

Theme

Struct Theme 

Source
pub struct Theme { /* private fields */ }
Expand description

The theme of the file explorer.

This struct is used to customize the look of the file explorer. It allows to set the style of the widget and the style of the files. You can also wrap the widget in a block with the with_block method and add dinamic titles to it with with_title_top and with_title_bottom.

Implementations§

Source§

impl Theme

Source

pub const fn new() -> Self

Create a new empty theme.

The theme will not have any style set. To get a theme with the default style, use default.

§Example
let theme = Theme::new();
Source

pub fn add_default_title(self) -> Self

Add a top title to the theme. The title is the current working directory.

§Example

Suppose you have this tree file, with passport.png selected inside file_explorer:

/
├── .git
└── Documents
    ├── passport.png  <- selected
    └── resume.pdf

You will end up with something like this:

┌/Documents────────────────────────┐
│ ../                              │
│ passport.png                     │
│ resume.pdf                       │
└──────────────────────────────────┘

With this code:

use ratatui::widgets::*;
use ratatui_explorer::{FileExplorerBuilder, Theme};

let theme = Theme::default()
    .with_block(Block::default().borders(Borders::ALL))
    .add_default_title();

let file_explorer = FileExplorerBuilder::build_with_theme(theme).unwrap();

/* user select `password.png` */

let widget = file_explorer.widget();
/* render the widget */
Source

pub fn with_block(self, block: Block<'static>) -> Self

Wrap the file explorer with a custom Block widget.

Behind the scene, it use the List::block method. See its documentation for more.

You can use with_title_top and with_title_bottom to add dynamic titles to the block.

§Example
let theme = Theme::default().with_block(Block::default().borders(Borders::ALL));
Source

pub fn with_style<S: Into<Style>>(self, style: S) -> Self

Set the style of the widget.

Behind the scene, it use the List::style method. See its documentation for more.

§Example
let theme = Theme::default().with_style(Style::default().fg(Color::Yellow));
Source

pub fn with_item_style<S: Into<Style>>(self, item_style: S) -> Self

Set the style of all non directories items. To set the style of the directories, use with_dir_style.

Behind the scene, it use the Span::styled method. See its documentation for more.

§Example
let theme = Theme::default().with_item_style(Style::default().fg(Color::White));
Source

pub fn with_dir_style<S: Into<Style>>(self, dir_style: S) -> Self

Set the style of all directories items. To set the style of the non directories, use with_item_style.

Behind the scene, it use the Span::styled method. See its documentation for more.

§Example
let theme = Theme::default().with_dir_style(Style::default().fg(Color::Blue));
Source

pub fn with_highlight_item_style<S: Into<Style>>( self, highlight_item_style: S, ) -> Self

Set the style of all highlighted non directories items. To set the style of the highlighted directories, use with_highlight_dir_style.

Behind the scene, it use the List::highlight_style method. See its documentation for more.

§Example
let theme = Theme::default().with_highlight_item_style(Style::default().add_modifier(Modifier::BOLD));
Source

pub fn with_highlight_dir_style<S: Into<Style>>( self, highlight_dir_style: S, ) -> Self

Set the style of all highlighted directories items. To set the style of the highlighted non directories, use with_highlight_item_style.

Behind the scene, it use the List::highlight_style method. See its documentation for more.

§Example
let theme = Theme::default().with_highlight_dir_style(Style::default().fg(Color::Blue).add_modifier(Modifier::BOLD));
Source

pub fn with_highlight_symbol(self, highlight_symbol: &str) -> Self

Set the symbol used to highlight the selected item.

Behind the scene, it use the List::highlight_symbol method. See its documentation for more.

§Example
let theme = Theme::default().with_highlight_symbol("> ");
Source

pub fn with_highlight_spacing(self, highlight_spacing: HighlightSpacing) -> Self

Set the spacing between the highlighted item and the other items.

Behind the scene, it use the List::highlight_spacing method. See its documentation for more.

§Example
let theme = Theme::default().with_highlight_spacing(HighlightSpacing::Never);
Source

pub fn with_scroll_padding(self, scroll_padding: usize) -> Self

Sets the number of items around the currently selected item that should be kept visible.

/// Behind the scene, it use the List::scroll_padding method. See its documentation for more.

§Example
let theme = Theme::default().with_scroll_padding(1);
Source

pub fn with_title_top( self, title_top: impl Fn(&FileExplorer) -> Line<'_> + 'static + Send + Sync, ) -> Self

Add a top title factory to the theme.

title_top is a function that take a reference to the current FileExplorer and returns a Line to be displayed as a title at the top of the wrapping block (if it exist) of the file explorer. You can call this function multiple times to add multiple titles.

Behind the scene, it use the Block::title_top method. See its documentation for more.

§Example
let theme = Theme::default()
    .with_title_top(|file_explorer: &FileExplorer| {
        Line::from(format!("cwd - {}", file_explorer.cwd().display()))
    })
    .with_title_top(|file_explorer: &FileExplorer| {
        Line::from(format!("{} files", file_explorer.files().len() - 1)).right_aligned()
    });
Source

pub fn with_title_bottom( self, title_bottom: impl Fn(&FileExplorer) -> Line<'_> + 'static + Send + Sync, ) -> Self

Add a bottom title factory to the theme.

title_bottom is a function that take a reference to the current FileExplorer and returns a Line to be displayed as a title at the bottom of the wrapping block (if it exist) of the file explorer. You can call this function multiple times to add multiple titles.

Behind the scene, it use the Block::title_bottom method. See its documentation for more.

§Example
let theme = Theme::default()
    .with_title_bottom(|file_explorer: &FileExplorer| {
        Line::from(format!("cwd - {}", file_explorer.cwd().display()))
    })
    .with_title_bottom(|file_explorer: &FileExplorer| {
        Line::from(format!("{} files", file_explorer.files().len() - 1)).right_aligned()
    });
Source

pub const fn block(&self) -> Option<&Block<'static>>

Returns the wrapping block (if it exist) of the file explorer of the theme.

Source

pub const fn style(&self) -> &Style

Returns the style of the widget of the theme.

Source

pub const fn item_style(&self) -> &Style

Returns the style of the non directories items of the theme.

Source

pub const fn dir_style(&self) -> &Style

Returns the style of the directories items of the theme.

Source

pub const fn highlight_item_style(&self) -> &Style

Returns the style of the highlighted non directories items of the theme.

Source

pub const fn highlight_dir_style(&self) -> &Style

Returns the style of the highlighted directories items of the theme.

Source

pub fn highlight_symbol(&self) -> Option<&str>

Returns the symbol used to highlight the selected item of the theme.

Source

pub const fn highlight_spacing(&self) -> &HighlightSpacing

Returns the spacing between the highlighted item and the other items of the theme.

Source

pub const fn scroll_padding(&self) -> usize

Returns the number of items around the currently selected item that should be kept visible.

Source

pub fn title_top<'a>(&self, file_explorer: &'a FileExplorer) -> Vec<Line<'a>>

Returns the generated top titles of the theme.

Source

pub fn title_bottom<'a>(&self, file_explorer: &'a FileExplorer) -> Vec<Line<'a>>

Returns the generated bottom titles of the theme.

Trait Implementations§

Source§

impl Clone for Theme

Source§

fn clone(&self) -> Theme

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Theme

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Theme

Source§

fn default() -> Self

Return a slightly customized default theme. To get a theme with no style set, use new.

The theme will have a block with all borders, a white style for the items, a light blue style for the directories, a dark gray background for all the highlighted items.

§Example
let theme = Theme::default();
Source§

impl Eq for Theme

Source§

impl Hash for Theme

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Theme

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Theme

§

impl !UnwindSafe for Theme

§

impl Freeze for Theme

§

impl Send for Theme

§

impl Sync for Theme

§

impl Unpin for Theme

§

impl UnsafeUnpin for Theme

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.