Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement preview pane #691

Draft
wants to merge 4 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/en/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ that can be overwritten.

Tries to auto complete the path in the input buffer

#### xplr.fn.builtin.fmt_general_selection_item

Formats each node in the selection

#### xplr.fn.builtin.fmt_general_preview_renderer

Renders the focused node in preview pane

See: [xplr.util.preview](https://xplr.dev/en/xplr.util#xplrutilpreview)

The focused node is passed as the node value, and layout_hight is passed
dynamically.
When there is no item under focus, the node value will be nil.

#### xplr.fn.builtin.fmt_general_table_row_cols_0

Renders the first column in the table
Expand Down
47 changes: 47 additions & 0 deletions docs/en/src/general-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,18 @@ Style for each item in the selection list.

Type: [Style](https://xplr.dev/en/style)

#### xplr.config.general.preview.renderer.format

Preview renderer for the path under focus.

Type: nullable string

#### xplr.config.general.preview.renderer.style

Style for preview panel.

Type: [Style](https://xplr.dev/en/style)

#### xplr.config.general.search.algorithm

The default search algorithm
Expand Down Expand Up @@ -542,6 +554,41 @@ Style of the selection panel borders.

Type: [Style](https://xplr.dev/en/style)

#### xplr.config.general.panel_ui.preview.title.format

The content for the preview panel title.

Type: nullable string

#### xplr.config.general.panel_ui.preview.title.style

Style of the preview panel title.

Type: [Style](https://xplr.dev/en/style)

#### xplr.config.general.panel_ui.preview.borders

#### xplr.config.general.panel_ui.preview.style

Style of the preview panel.

Type: [Style](https://xplr.dev/en/style)
Defines where to show borders for the preview panel.

Type: nullable list of [Border](https://xplr.dev/en/borders#border)

#### xplr.config.general.panel_ui.preview.border_type

Type of the borders for preview panel.

Type: nullable [Border Type](https://xplr.dev/en/borders#border-type)

#### xplr.config.general.panel_ui.preview.border_style

Style of the preview panel borders.

Type: [Style](https://xplr.dev/en/style)

#### xplr.config.general.panel_ui.sort_and_filter.title.format

The content for the sort & filter panel title.
Expand Down
32 changes: 27 additions & 5 deletions docs/en/src/xplr.util.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ xplr.util.path_split(".././foo")

### xplr.util.node

Get [Node][5] information of a given path.
Get [Node][2] information of a given path.
Doesn't check if the path exists.
Returns nil if the path is "/".
Errors out if absolute path can't be obtained.

Type: function( path:string ) -> [Node][5]|nil
Type: function( path:string ) -> [Node][2]|nil

Example:

Expand All @@ -129,9 +129,9 @@ xplr.util.node("/")

### xplr.util.node_type

Get the configured [Node Type][6] of a given [Node][5].
Get the configured [Node Type][6] of a given [Node][2].

Type: function( [Node][5], [xplr.config.node_types][7]|nil ) -> [Node Type][6]
Type: function( [Node][2], [xplr.config.node_types][7]|nil ) -> [Node Type][6]

If the second argument is missing, global config `xplr.config.node_types`
will be used.
Expand Down Expand Up @@ -501,11 +501,33 @@ xplr.util.permissions_octal(app.focused_node.permission)
-- { 0, 7, 5, 4 }
```

### xplr.util.preview

Renders a preview of the given node as string.

You probably want to use it inside the function mentioned in
[xplr.config.general.preview.renderer.format][9], or inside a
[custom dynamic layout][10].

Type: function( { node:[Node][2]|nil, layout_size:[Size][5] } ) -> string

Example:

```lua
xplr.util.preview({
node = xplr.util.node("/foo"),
layout_size = { x = 0, y = 0, height = 10, width = 10 },
})
-- "Preview of /foo"
```

[1]: https://xplr.dev/en/lua-function-calls#explorer-config
[2]: https://xplr.dev/en/lua-function-calls#node
[3]: https://xplr.dev/en/style
[4]: https://xplr.dev/en/layout
[5]: https://xplr.dev/en/lua-function-calls#node
[5]: https://xplr.dev/en/layout#size
[6]: https://xplr.dev/en/node-type
[7]: https://xplr.dev/en/node_types
[8]: https://xplr.dev/en/column-renderer#permission
[9]: https://xplr.dev/en/general-config#xplrconfiggeneralpreviewrendererformat
[10]: https://xplr.dev/en/layout#dynamic
12 changes: 9 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,13 +414,19 @@ impl App {
prompt: config.general.prompt.format.clone().unwrap_or_default(),
};

let hist = if &pwd == "/" {
pwd.clone()
} else {
format!("{0}/", &pwd)
};

let mut app = Self {
bin,
version: VERSION.to_string(),
config,
vroot,
initial_vroot,
pwd: pwd.clone(),
pwd,
initial_pwd,
directory_buffer: Default::default(),
last_focus: Default::default(),
Expand All @@ -435,7 +441,7 @@ impl App {
explorer_config,
logs: Default::default(),
logs_hidden: Default::default(),
history: History::default().push(format!("{pwd}/")),
history: History::default().push(hist),
last_modes: Default::default(),
hostname,
hooks,
Expand Down Expand Up @@ -1295,7 +1301,7 @@ impl App {
}

pub fn scroll_up_half(mut self) -> Result<Self> {
self.msg_out.push_back(MsgOut::ScrollUp);
self.msg_out.push_back(MsgOut::ScrollUpHalf);
Ok(self)
}

Expand Down
13 changes: 13 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ pub struct SelectionConfig {
pub item: UiElement,
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct PreviewConfig {
#[serde(default)]
pub renderer: UiElement,
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct SearchConfig {
Expand Down Expand Up @@ -275,6 +282,9 @@ pub struct PanelUi {
#[serde(default)]
pub selection: PanelUiConfig,

#[serde(default)]
pub preview: PanelUiConfig,

#[serde(default)]
pub input_and_logs: PanelUiConfig,

Expand Down Expand Up @@ -318,6 +328,9 @@ pub struct GeneralConfig {
#[serde(default)]
pub selection: SelectionConfig,

#[serde(default)]
pub preview: PreviewConfig,

#[serde(default)]
pub search: SearchConfig,

Expand Down
57 changes: 52 additions & 5 deletions src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,16 @@ xplr.config.general.selection.item.format = "builtin.fmt_general_selection_item"
-- Type: [Style](https://xplr.dev/en/style)
xplr.config.general.selection.item.style = {}

-- Preview renderer for the path under focus.
--
-- Type: nullable string
xplr.config.general.preview.renderer.format = "builtin.fmt_general_preview_renderer"

-- Style for preview panel.
--
-- Type: [Style](https://xplr.dev/en/style)
xplr.config.general.preview.renderer.style = { add_modifiers = { "Dim" } }

-- The default search algorithm
--
-- Type: [Search Algorithm](https://xplr.dev/en/searching#algorithm)
Expand Down Expand Up @@ -338,9 +348,7 @@ xplr.config.general.sort_and_filter_ui.separator.format = " › "
-- The style of the separator for the Sort & filter panel.
--
-- Type: [Style](https://xplr.dev/en/style)
xplr.config.general.sort_and_filter_ui.separator.style = {
add_modifiers = { "Dim" },
}
xplr.config.general.sort_and_filter_ui.separator.style = { add_modifiers = { "Dim" } }

-- The content of the default identifier in Sort & filter panel.
--
Expand Down Expand Up @@ -634,12 +642,41 @@ xplr.config.general.panel_ui.selection.borders = nil
-- Type of the borders for selection panel.
--
-- Type: nullable [Border Type](https://xplr.dev/en/borders#border-type)
xplr.config.general.panel_ui.selection.border_type = nil
xplr.config.general.panel_ui.selection.border_type = "Double"

-- Style of the selection panel borders.
--
-- Type: [Style](https://xplr.dev/en/style)
xplr.config.general.panel_ui.selection.border_style = {}
xplr.config.general.panel_ui.selection.border_style = { fg = "Red" }

-- The content for the preview panel title.
--
-- Type: nullable string
xplr.config.general.panel_ui.preview.title.format = nil

-- Style of the preview panel title.
--
-- Type: [Style](https://xplr.dev/en/style)
xplr.config.general.panel_ui.preview.title.style = {}

-- Style of the preview panel.
--
-- Type: [Style](https://xplr.dev/en/style)
xplr.config.general.panel_ui.preview.style = {}
-- Defines where to show borders for the preview panel.
--
-- Type: nullable list of [Border](https://xplr.dev/en/borders#border)
xplr.config.general.panel_ui.preview.borders = nil

-- Type of the borders for preview panel.
--
-- Type: nullable [Border Type](https://xplr.dev/en/borders#border-type)
xplr.config.general.panel_ui.preview.border_type = nil

-- Style of the preview panel borders.
--
-- Type: [Style](https://xplr.dev/en/style)
xplr.config.general.panel_ui.preview.border_style = {}

-- The content for the sort & filter panel title.
--
Expand Down Expand Up @@ -2948,6 +2985,7 @@ xplr.fn.builtin.try_complete_path = function(m)
end
end

-- Formats each node in the selection
xplr.fn.builtin.fmt_general_selection_item = function(n)
local nl = xplr.util.paint("\\n", { add_modifiers = { "Italic", "Dim" } })
local sh_config = { with_prefix_dots = true, without_suffix_dots = true }
Expand All @@ -2961,6 +2999,15 @@ xplr.fn.builtin.fmt_general_selection_item = function(n)
return xplr.util.paint(shortened:gsub("\n", nl), style)
end

-- Renders the focused node in preview pane
--
-- See: [xplr.util.preview](https://xplr.dev/en/xplr.util#xplrutilpreview)
--
-- The focused node is passed as the node value, and layout_hight is passed
-- dynamically.
-- When there is no item under focus, the node value will be nil.
xplr.fn.builtin.fmt_general_preview_renderer = xplr.util.preview

-- Renders the first column in the table
xplr.fn.builtin.fmt_general_table_row_cols_0 = function(m)
local r = ""
Expand Down
Loading
Loading