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
impl Theme
Sourcepub fn add_default_title(self) -> Self
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.pdfYou 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 */Sourcepub fn with_block(self, block: Block<'static>) -> Self
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));Sourcepub fn with_style<S: Into<Style>>(self, style: S) -> Self
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));Sourcepub fn with_item_style<S: Into<Style>>(self, item_style: S) -> Self
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));Sourcepub fn with_dir_style<S: Into<Style>>(self, dir_style: S) -> Self
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));Sourcepub fn with_highlight_item_style<S: Into<Style>>(
self,
highlight_item_style: S,
) -> Self
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));Sourcepub fn with_highlight_dir_style<S: Into<Style>>(
self,
highlight_dir_style: S,
) -> Self
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));Sourcepub fn with_highlight_symbol(self, highlight_symbol: &str) -> Self
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("> ");Sourcepub fn with_highlight_spacing(self, highlight_spacing: HighlightSpacing) -> Self
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);Sourcepub fn with_scroll_padding(self, scroll_padding: usize) -> Self
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);Sourcepub fn with_title_top(
self,
title_top: impl Fn(&FileExplorer) -> Line<'_> + 'static + Send + Sync,
) -> Self
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()
});Sourcepub fn with_title_bottom(
self,
title_bottom: impl Fn(&FileExplorer) -> Line<'_> + 'static + Send + Sync,
) -> Self
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()
});Sourcepub const fn block(&self) -> Option<&Block<'static>>
pub const fn block(&self) -> Option<&Block<'static>>
Returns the wrapping block (if it exist) of the file explorer of the theme.
Sourcepub const fn item_style(&self) -> &Style
pub const fn item_style(&self) -> &Style
Returns the style of the non directories items of the theme.
Sourcepub const fn dir_style(&self) -> &Style
pub const fn dir_style(&self) -> &Style
Returns the style of the directories items of the theme.
Sourcepub const fn highlight_item_style(&self) -> &Style
pub const fn highlight_item_style(&self) -> &Style
Returns the style of the highlighted non directories items of the theme.
Sourcepub const fn highlight_dir_style(&self) -> &Style
pub const fn highlight_dir_style(&self) -> &Style
Returns the style of the highlighted directories items of the theme.
Sourcepub fn highlight_symbol(&self) -> Option<&str>
pub fn highlight_symbol(&self) -> Option<&str>
Returns the symbol used to highlight the selected item of the theme.
Sourcepub const fn highlight_spacing(&self) -> &HighlightSpacing
pub const fn highlight_spacing(&self) -> &HighlightSpacing
Returns the spacing between the highlighted item and the other items of the theme.
Sourcepub const fn scroll_padding(&self) -> usize
pub const fn scroll_padding(&self) -> usize
Returns the number of items around the currently selected item that should be kept visible.
Sourcepub fn title_top<'a>(&self, file_explorer: &'a FileExplorer) -> Vec<Line<'a>>
pub fn title_top<'a>(&self, file_explorer: &'a FileExplorer) -> Vec<Line<'a>>
Returns the generated top titles of the theme.
Sourcepub fn title_bottom<'a>(&self, file_explorer: &'a FileExplorer) -> Vec<Line<'a>>
pub fn title_bottom<'a>(&self, file_explorer: &'a FileExplorer) -> Vec<Line<'a>>
Returns the generated bottom titles of the theme.
Trait Implementations§
impl Eq for Theme
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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