Auto generate messages docs

- Huge refactor.
- Run `python docs/script/generate.py` to generate `docs/en/src/messages.md`.
pull/459/head
Arijit Basu 2 years ago committed by Arijit Basu
parent 67eca1ecdf
commit 3d81a49cec

2
.gitignore vendored

@ -12,3 +12,5 @@ book/
# Jetbrains config
.idea/
.venv/

@ -18,6 +18,8 @@
- [Layout][34]
- [Mode][35]
- [Message][8]
- [Full List of Messages][38]
- [Input Operation][39]
- [Borders][31]
- [Style][11]
- [Sorting][12]
@ -75,3 +77,5 @@
[35]: mode.md
[36]: lua-function-calls.md
[37]: environment-variables-and-pipes.md
[38]: messages.md
[39]: input-operation.md

@ -18,8 +18,8 @@ The loaded config can be further extended using the `-C` or `--extra-config`
command-line option.
> **NEED HELP:** Auto generate rest of the docs from [src/init.lua][1]
> using [docs/script/generate.lua][2].
> using [docs/script/generate.py][2].
[1]: https://github.com/sayanarijit/xplr/blob/main/src/init.lua
[2]: https://github.com/sayanarijit/xplr/blob/main/docs/script/generate.lua
[2]: https://github.com/sayanarijit/xplr/blob/main/docs/script/generate.py
[3]: https://www.lua.org

@ -5,7 +5,7 @@ This configuration is exposed via the `xplr.config.general` API.
For now, kindly refer to [**init.lua**][1]
> **NEED HELP:** Auto generate rest of the docs from [src/init.lua][1]
> using [docs/script/generate.lua][2].
> using [docs/script/generate.py][2].
[1]: https://github.com/sayanarijit/xplr/blob/main/src/init.lua
[2]: https://github.com/sayanarijit/xplr/blob/main/docs/script/generate.lua
[2]: https://github.com/sayanarijit/xplr/blob/main/docs/script/generate.py

@ -0,0 +1,25 @@
# Input Operation
Cursor based input operation can be one of the following:
- { SetCursor = int }
- { InsertCharacter = str }
- "GoToPreviousCharacter"
- "GoToNextCharacter"
- "GoToPreviousWord"
- "GoToNextWord"
- "GoToStart"
- "GoToEnd"
- "DeletePreviousCharacter"
- "DeleteNextCharacter"
- "DeletePreviousWord"
- "DeleteNextWord"
- "DeleteLine"
## Also See:
- [Message][1]
- [Full List of Messages][2]
[1]: message.md
[2]: messages.md

@ -5,7 +5,7 @@ This configuration is exposed via the `xplr.config.layouts` API.
For now, kindly refer to [**init.lua**][1]
> **NEED HELP:** Auto generate rest of the docs from [src/init.lua][1]
> using [docs/script/generate.lua][2].
> using [docs/script/generate.py][2].
[1]: https://github.com/sayanarijit/xplr/blob/main/src/init.lua
[2]: https://github.com/sayanarijit/xplr/blob/main/docs/script/generate.lua
[2]: https://github.com/sayanarijit/xplr/blob/main/docs/script/generate.py

@ -11,7 +11,7 @@ You can send these messages to an xplr session in the following ways:
- Via shell command using the [input pipe][4]
- Via socket (coming soon)
## Format
### Format
To send messages using the [key bindings][2] or
[Lua function calls][3], messages are represented in
@ -29,844 +29,14 @@ represented using
- FocusPath: "/path/to/file"
- Call: { command: bash, args: ["-c", "read -p test"] }
## Full List of Messages
## Also See:
### "ExplorePwd"
- [Full List of Messages][1]
**YAML:** `ExplorePwd`
Explore the present working directory and register the filtered nodes.
This operation is expensive. So, try to avoid using it too often.
### "ExplorePwdAsync"
**YAML:** `ExplorePwdAsync`
Explore the present working directory and register the filtered nodes asynchronously.
This operation happens asynchronously. That means, the xplr directory buffers won't be updated
immediately. Hence, it needs to be used with care and probably with special checks in place.
To explore `$PWD` synchronously, use `ExplorePwd` instead.
### "ExploreParentsAsync"
**YAML:** `ExploreParentsAsync`
Explore the present working directory along with its parents and register the filtered nodes.
This operation happens asynchronously. That means, the xplr directory buffers won't be updated
immediately. Hence, it needs to be used with care and probably with special checks in place.
To explore just the `$PWD` synchronously, use `ExplorePwd` instead.
### "Refresh"
**YAML:** `Refresh`
Refresh the UI.
But it will not re-explore the directory if the working directory is the same.
If there is some change in the working directory and you want to re-explore it,
use the `Explore` message instead.
Also, it will not clear the screen. Use `ClearScreen` for that.
### "ClearScreen"
**YAML:** `ClearScreen`
Clears the screen.
### "FocusNext"
**YAML:** `FocusNext`
Focus next node.
### { FocusNextByRelativeIndex = int }
**YAML:** `FocusNextByRelativeIndex: int`
Focus on the `n`th node relative to the current focus where `n` is a given value.
**YAML Example:** `FocusNextByRelativeIndex: 2`
**Lua Example:** `{ FocusNextByRelativeIndex = 2 }`
### "FocusNextByRelativeIndexFromInput"
**YAML:** `FocusNextByRelativeIndexFromInput`
Focus on the `n`th node relative to the current focus where `n` is read from
the input buffer.
### "FocusPrevious"
**YAML:** `FocusPrevious`
Focus on the previous item.
### { FocusPreviousByRelativeIndex = int }
**YAML:** `FocusPreviousByRelativeIndex: int`
Focus on the `-n`th node relative to the current focus where `n` is a given value.
**YAML Example:** `FocusPreviousByRelativeIndex: 2`
**Lua Example:** `{ FocusPreviousByRelativeIndex = 2 }`
### "FocusPreviousByRelativeIndexFromInput"
**YAML:** `FocusPreviousByRelativeIndexFromInput`
Focus on the `-n`th node relative to the current focus where `n` is read from
the input buffer.
### "FocusFirst"
**YAML:** `FocusFirst`
Focus on the first node.
### "FocusLast"
**YAML:** `FocusLast`
Focus on the last node.
### { FocusPath = "string" }
**YAML:** `FocusPath: string`
Focus on the given path.
**YAML Example:** `FocusPath: /path/to/file`
**Lua Example:** `{ FocusPath = "/path/to/file" }`
### "FocusPathFromInput"
**YAML:** `FocusPathFromInput`
Focus on the path read from input buffer.
### { FocusByIndex = int }
**YAML:** `FocusByIndex: int`
Focus on the absolute `n`th node where `n` is a given value.
**YAML Example:** `FocusByIndex: 2`
**Lua Example:** `{ FocusByIndex = 2 }`
### "FocusByIndexFromInput"
**YAML:** `FocusByIndexFromInput`
Focus on the absolute `n`th node where `n` is read from the input buffer.
### { FocusByFileName = "string" }
**YAML:** `FocusByFileName: string`
Focus on the file by name from the present working directory.
**YAML Example:** `FocusByFileName: filename.ext`
**Lua Example:** `{ FocusByFileName = "filename.ext" }`
### { ChangeDirectory = "string" }
**YAML:** `ChangeDirectory: string`
Change the present working directory ($PWD)
**YAML Example:** `ChangeDirectory: /path/to/directory`
**Lua Example:** `{ ChangeDirectory = "/path/to/directory" }`
### "Enter"
**YAML:** `Enter`
Enter into the currently focused path if it's a directory.
### "Back"
**YAML:** `Back`
Go back to the parent directory.
### "LastVisitedPath"
**YAML:** `LastVisitedPath`
Go to the last path visited.
### "NextVisitedPath"
**YAML:** `NextVisitedPath`
Go to the next path visited.
### "FollowSymlink"
**YAML:** `FollowSymlink`
Follow the symlink under focus to its actual location.
### { UpdateInputBuffer = [Input Opertaion][71] }
**YAML:** `BufferInput: Input Operation`
Update the input buffer using cursor based operations.
**YAML Example:** `UpdateInputBuffer: GoToPreviousWord`
**Lua Example:** `{ UpdateInputBuffer = "GoToPreviousWord" }`
### "UpdateInputBufferFromKey"
**YAML:** `UpdateInputBufferFromKey`
Update the input buffer from the key read from keyboard input.
### { BufferInput = "string" }
**YAML:** `BufferInput: string`
Append/buffer the given string into the input buffer.
**YAML Example:** `BufferInput: foo`
**Lua Example:** `{ BufferInput = "foo" }`
### "BufferInputFromKey"
**YAML:** `BufferInputFromKey`
Append/buffer the characted read from a keyboard input into the
input buffer.
### { SetInputBuffer = "string" }
**YAML:** `SetInputBuffer: string`
Set/rewrite the input buffer with the given string.
When the input buffer is not-null (even if empty string)
it will show in the UI.
**YAML Example:** `SetInputBuffer: foo`
**Lua Example:** `{ SetInputBuffer = "foo" }`
### "RemoveInputBufferLastCharacter"
**YAML:** `RemoveInputBufferLastCharacter`
Remove input buffer's last character.
### "RemoveInputBufferLastWord"
**YAML:** `RemoveInputBufferLastWord`
Remove input buffer's last word.
### "ResetInputBuffer"
**YAML:** `ResetInputBuffer`
Reset the input buffer back to null. It will not show in the UI.
### { SwitchMode = "string" }
**YAML:** `SwitchMode: string`
Switch input [mode][8].
It clears the input buffer.
> **NOTE:** To be specific about which mode to switch to, use `SwitchModeBuiltin` or
> `SwitchModeCustom` instead.
**YAML Example:** `SwitchMode: default`
**Lua Example:** `{ SwitchMode = "default" }`
### { SwitchModeKeepingInputBuffer = "string" }
**YAML:** `SwitchModeKeepingInputBuffer: string`
Switch input [mode][8].
It keeps the input buffer.
> **NOTE:** To be specific about which mode to switch to, use
> `SwitchModeBuiltinKeepingInputBuffer` or
> `SwitchModeCustomKeepingInputBuffer` instead.
**YAML Example:** `SwitchModeKeepingInputBuffer: default`
**Lua Example:** `{ SwitchModeKeepingInputBuffer = "default" }`
### { SwitchModeBuiltin = "string" }
**YAML:** `SwitchModeBuiltin: string`
Switch to a [builtin mode][9].
It clears the input buffer.
**YAML Example:** `SwitchModeBuiltin: default`
**Lua Example:** `{ SwitchModeBuiltin = "default" }`
### { SwitchModeBuiltinKeepingInputBuffer = "string" }
**YAML:** `SwitchModeBuiltinKeepingInputBuffer: string`
Switch to a [builtin mode][9].
It keeps the input buffer.
**YAML Example:** `SwitchModeBuiltinKeepingInputBuffer: default`
**Lua Example:** `{ SwitchModeBuiltinKeepingInputBuffer = "default" }`
### { SwitchModeCustom = "string" }
**YAML:** `SwitchModeCustom: string`
Switch to a [custom mode][10].
It clears the input buffer.
**YAML Example:** `SwitchModeCustom: my_custom_mode`
**Lua Example:** `{ SwitchModeCustom = "my_custom_mode" }`
### { SwitchModeCustomKeepingInputBuffer = "string" }
**YAML:** `SwitchModeCustom: string`
Switch to a [custom mode][10].
It keeps the input buffer.
**YAML Example:** `SwitchModeCustomKeepingInputBuffer: my_custom_mode`
**Lua Example:** `{ SwitchModeCustomKeepingInputBuffer = "my_custom_mode" }`
### "PopMode"
**YAML:** `PopMode`
Pop the last mode from the history and switch to it.
It clears the input buffer.
### PopModeKeepingInputBuffer
**YAML:** `PopModeKeepingInputBuffer`
Pop the last mode from the history and switch to it.
It keeps the input buffer.
### { SwitchLayout = "string" }
**YAML:** `SwitchLayout: string`
Switch [layout][11].
> **NOTE:** To be specific about which layout to switch to, use `SwitchLayoutBuiltin` or
> `SwitchLayoutCustom` instead.
**YAML Example:** `SwitchLayout: default`
**Lua Example:** `{ SwitchLayout = "default" }`
### { SwitchLayoutBuiltin = "string" }
**YAML:** `SwitchLayoutBuiltin: string`
Switch to a [builtin layout][12].
**YAML Example:** `SwitchLayoutBuiltin: default`
**Lua Example:** `{ SwitchLayoutBuiltin = "default" }`
### { SwitchLayoutCustom = "string" }
**YAML:** `SwitchLayoutCustom: string`
Switch to a [custom layout][13].
**YAML Example:** `SwitchLayoutCustom: my_custom_layout`
**Lua Example:** `{ SwitchLayoutCustom = "my_custom_layout" }`
### { Call = "string" }
**YAML:** `Call: string`
Call a shell command with the given arguments.
Note that the arguments will be shell-escaped.
So to read the variables, the `-c` option of the shell
can be used.
You may need to pass `ExplorePwd` depening on the expectation.
**YAML Example:** `Call: { command: bash, args: ["-c", "read -p test"] }`
**Lua Example:** `{ Call = { command = "bash", args = { "-c", "read -p test" } } }`
### { CallSilently = "string" }
**YAML:** `CallSilently: string`
Like `Call` but without the flicker. The stdin, stdout
stderr will be piped to null. So it's non-interactive.
**YAML Example:** `CallSilently: { command: tput, args: ["bell"] }`
**Lua Example:** `{ CallSilently = { command = "tput", args = { "bell" } } }`
### { BashExec = "string" }
**YAML:** `BashExec: string`
An alias to `Call: {command: bash, args: ["-c", "{string}"], silent: false}`
where `{string}` is the given value.
**YAML Example:** `BashExec: "read -p test"`
**Lua Example:** `{ BashExec = "read -p test" }`
### { BashExecSilently = "string" }
**YAML:** `BashExecSilently(String)`
Like `BashExec` but without the flicker. The stdin, stdout
stderr will be piped to null. So it's non-interactive.
**YAML Example:** `BashExecSilently: "tput bell"`
**Lua Example:** `{ BashExecSilently = "tput bell" }`
### { CallLua = "string" }
**YAML:** `CallLua: string`
Call a Lua function.
A [Lua Context][14] object will be passed to the [function][3] as argument.
The function can optionally return a list of messages for xplr to handle
after the executing the function.
**YAML Example:** `CallLua: custom.some_custom_funtion`
**Lua Example:** `{ CallLua = "custom.some_custom_funtion" }`
### { CallLuaSilently = "string" }
**YAML:** `CallLuaSilently: string`
Like `CallLua` but without the flicker. The stdin, stdout
stderr will be piped to null. So it's non-interactive.
**YAML Example:** `CallLuaSilently: custom.some_custom_function`
**Lua Example:** `{ CallLuaSilently = "custom.some_custom_function" }`
### { LuaEval = "string" }
**YAML:** `LuaEval: string`
Execute Lua code without needing to define a function.
If the `string` is a callable, xplr will try to call it with with the
[Lua Context][14] argument.
**YAML Example:** `LuaEval: "return { { LogInfo = io.read() } }"`
**YAML Example:** `LuaEval: "function(app) return { { LogInfo = app.pwd } } end"`
**Lua Example:** `{ LuaEval = [[return { { LogInfo = io.read() } }]] }`
**Lua Example:** `{ LuaEval = [[function(app) return { { LogInfo = app.pwd } } end]] }`
### { LuaEvalSilently = "string" }
**YAML:** `LuaEvalSilently: string`
Like `LuaEval` but without the flicker. The stdin, stdout
stderr will be piped to null. So it's non-interactive.
**YAML Example:** `LuaEvalSilently: "return { { LogInfo = 'foo' } }"`
**Lua Example:** `{ LuaEvalSilently = [[return { { LogInfo = "foo" } }]] }`
### "Select"
**YAML:** `Select`
Select the focused node.
### "SelectAll"
**YAML:** `SelectAll`
Select all the visible nodes.
### { SelectPath = "string" }
**YAML:** `SelectPath: string`
Select the given path.
**YAML Example:** `SelectPath: /path/to/file`
**Lua Example:** `{ SelectPath = "/path/to/file" }`
### "UnSelect"
**YAML:** `UnSelect`
Unselect the focused node.
### "UnSelectAll"
**YAML:** `UnSelectAll`
Unselect all the visible nodes.
### { UnSelectPath = "string)" }
**YAML:** `UnSelectPath: string`
UnSelect the given path.
**YAML Example:** `UnSelectPath: /path/to/file`
**Lua Example:** `{ UnSelectPath = "/path/to/file" }`
### "ToggleSelection"
**YAML:** `ToggleSelection`
Toggle selection on the focused node.
### "ToggleSelectAll"
**YAML:** `ToggleSelectAll`
Toggle between select all and unselect all.
### { ToggleSelectionByPath = "string" }
**YAML:** `ToggleSelectionByPath: string`
Toggle selection by file path.
**YAML Example:** `ToggleSelectionByPath: /path/to/file`
**Lua Example:** `{ ToggleSelectionByPath = "/path/to/file" }`
### "ClearSelection"
**YAML:** `ClearSelection`
Clear the selection.
### { AddNodeFilter = { filter = [Filter][15], input = "string" }
**YAML:** `AddNodeFilter: { filter = Filter, input = string }`
Add a [filter][16] to exclude nodes while exploring directories.
**YAML Example:** `AddNodeFilter: { filter: RelativePathDoesStartWith, input: foo }`
**Lua Example:** `{ AddNodeFilter = { filter = "RelativePathDoesStartWith", input = "foo" } }`
### { RemoveNodeFilter = { filter = [Filter][15], input = "string" }
**YAML:** `RemoveNodeFilter: { filter = Filter, input = string`
Remove an existing [filter][16].
**YAML Example:** `RemoveNodeFilter: { filter: RelativePathDoesStartWith, input: foo }`
**Lua Example:** `{ RemoveNodeFilter: { filter: "RelativePathDoesStartWith", input: "foo" } }`
### { ToggleNodeFilter = { filter = [Filter][15], input = "string" }
**YAML:** `ToggleNodeFilter: { filter = Filter, input = string }`
Remove a [filter][16] if it exists, else, add a it.
**YAML Example:** `ToggleNodeFilter: { filter: RelativePathDoesStartWith, input: foo }`
**Lua Example:** `{ ToggleNodeFilter = { filter = "RelativePathDoesStartWith", input = "foo" } }`
### { AddNodeFilterFromInput = [Filter][15] }
**YAML:** `AddNodeFilterFromInput: Filter`
Add a node [filter][16] reading the input from the buffer.
**YAML Example:** `AddNodeFilterFromInput: RelativePathDoesStartWith`
**Lua Example:** `{ AddNodeFilterFromInput = "RelativePathDoesStartWith" }`
### { RemoveNodeFilterFromInput = [Filter][15] }
**YAML:** `RemoveNodeFilterFromInput: Filter`
Remove a node [filter][16] reading the input from the buffer.
**YAML Example:** `RemoveNodeFilterFromInput: RelativePathDoesStartWith`
**Lua Example:** `{ RemoveNodeFilterFromInput = "RelativePathDoesStartWith" }`
### "RemoveLastNodeFilter"
**YAML:** `RemoveLastNodeFilter`
Remove the last node [filter][16].
### "ResetNodeFilters"
**YAML:** `ResetNodeFilters`
Reset the node [filters][16] back to the default configuration.
### "ClearNodeFilters"
**YAML:** `ClearNodeFilters`
Clear all the node [filters][16].
### { AddNodeSorter = { sorter = [Sorter][17], reverse = bool } }
**YAML:** `AddNodeSorter: { sorter: Sorter, reverse = bool }`
Add a [sorter][17] to sort nodes while exploring directories.
**YAML Example:** `AddNodeSorter: { sorter: ByRelativePath, reverse: false }`
**YAML Example:** `{ AddNodeSorter = { sorter = "ByRelativePath", reverse = false } }`
### { RemoveNodeSorter = [Sorter][17] }
**YAML:** `RemoveNodeSorter: Sorter`
Remove an existing [sorter][17].
**YAML Example:** `RemoveNodeSorter: ByRelativePath`
**Lua Example:** `{ RemoveNodeSorter = "ByRelativePath" }`
### { ReverseNodeSorter = [Sorter][17] }
**YAML:** `ReverseNodeSorter: Sorter`
Reverse a node [sorter][17].
**YAML Example:** `ReverseNodeSorter: ByRelativePath`
**Lua Example:** `{ ReverseNodeSorter = "ByRelativePath" }`
### { ToggleNodeSorter = { sorter = [Sorter][17], reverse = bool } }
**YAML:** `ToggleNodeSorter: { sorter: Sorter, reverse = bool }`
Remove a [sorter][17] if it exists, else, add a it.
**YAML Example:** `ToggleSorterSorter: {sorter: ByRelativePath, reverse: false }`
**Lua Example:** `{ ToggleSorterSorter: { sorter = "ByRelativePath", reverse = false } }`
### "ReverseNodeSorters"
**YAML:** `ReverseNodeSorters`
Reverse the node [sorters][17].
### "RemoveLastNodeSorter"
**YAML:** `RemoveLastNodeSorter`
Remove the last node [sorter][17].
### "ResetNodeSorters"
**YAML:** `ResetNodeSorters`
Reset the node [sorters][17] back to the default configuration.
### "ClearNodeSorters"
**YAML:** `ClearNodeSorters`
Clear all the node [sorters][17].
### "EnableMouse"
**YAML:** `EnableMouse`
Enable mouse
### "DisableMouse"
**YAML:** `DisableMouse`
Disable mouse
### "ToggleMouse"
**YAML:** `ToggleMouse`
Toggle mouse
### { StartFifo = "string" }
**YAML:** `StartFifo: string`
Start piping the focused path to the given fifo path
**YAML Example:** `StartFifo: /tmp/xplr.fifo`
**Lua Example:** `{ StartFifo = "/tmp/xplr.fifo }`
### "StopFifo"
**YAML:** `StopFifo`
Close the active fifo and stop piping.
### { ToggleFifo = "string" }
**YAML:** `ToggleFifo: string`
Toggle betwen {Start|Stop}Fifo
**YAML Example:** `ToggleFifo: /path/to/fifo`
**Lua Example:** `{ ToggleFifo = "/path/to/fifo" }`
### { LogInfo = "string" }
**YAML:** `LogInfo: string`
Log information message.
**YAML Example:** `LogInfo: launching satellite`
**Lua Example:** `{ LogInfo = "launching satellite" }`
### { LogSuccess = "String" }
**YAML:** `LogSuccess: string`
Log a success message.
**YAML Example:** `LogSuccess: satellite reached destination`.
**Lua Example:** `{ LogSuccess = "satellite reached destination" }`.
### { LogWarning = "string" }
**YAML:** `LogWarning: string`
Log an warning message.
**YAML Example:** `LogWarning: satellite is heating`
**Lua Example:** `{ LogWarning = "satellite is heating" }`
### { LogError = "string" }
**YAML:** `LogError: string`
Log an error message.
**YAML Example:** `LogError: satellite crashed`
**Lua Example:** `{ LogError = "satellite crashed" }`
### "Quit"
**YAML:** `Quit`
Quit with returncode zero (success).
### "PrintPwdAndQuit"
**YAML:** `PrintPwdAndQuit`
Print $PWD and quit.
### "PrintFocusPathAndQuit"
**YAML:** `PrintFocusPathAndQuit`
Print the path under focus and quit. It can be empty string if there's nothing to focus.
### "PrintSelectionAndQuit"
**YAML:** `PrintSelectionAndQuit`
Print the selected paths and quit. It can be empty is no path is selected.
### "PrintResultAndQuit"
**YAML:** `PrintResultAndQuit`
Print the selected paths if it's not empty, else, print the focused node's path.
### "PrintAppStateAndQuit"
**YAML:** `PrintAppStateAndQuit`
Print the state of application in YAML format. Helpful for debugging or generating
the default configuration file.
### { Debug = "string" }
**YAML:** `Debug: string`
Write the application state to a file, without quitting. Also helpful for debugging.
**YAML Example:** `Debug: /path/to/file`
**Lua Example:** `{ Debug = "/path/to/file" }`
### "Terminate"
**YAML:** `Terminate`
Terminate the application with a non-zero return code.
## InputOperation
Cursor based input operation can be one of the following:
- { SetCursor = int }
- { InsertCharacter = str }
- "GoToPreviousCharacter"
- "GoToNextCharacter"
- "GoToPreviousWord"
- "GoToNextWord"
- "GoToStart"
- "GoToEnd"
- "DeletePreviousCharacter"
- "DeleteNextCharacter"
- "DeletePreviousWord"
- "DeleteNextWord"
- "DeleteLine"
[1]: #full-list-of-messages
[1]: messages.md
[2]: key-bindings.md
[3]: lua-function-calls.md
[4]: environment-variables-and-pipes.md#input-pipe
[5]: https://www.lua.org/
[6]: http://yaml.org/
[7]: https://www.json.org
[8]: modes.md#mode
[9]: modes.md#builtin
[10]: modes.md#custom
[11]: layouts.md
[12]: layouts.md#builtin
[13]: layouts.md#custom
[14]: lua-function-calls.md#lua-context
[15]: filtering.md#filter
[16]: filtering.md
[17]: sorting.md#sorter
[71]: #inputoperation

File diff suppressed because it is too large Load Diff

@ -5,7 +5,7 @@ This configuration is exposed via the `xplr.config.modes` API.
For now, kindly refer to [**init.lua**][1]
> **NEED HELP:** Auto generate rest of the docs from [src/init.lua][1]
> using [docs/script/generate.lua][2].
> using [docs/script/generate.py][2].
[1]: https://github.com/sayanarijit/xplr/blob/main/src/init.lua
[2]: https://github.com/sayanarijit/xplr/blob/main/docs/script/generate.lua
[2]: https://github.com/sayanarijit/xplr/blob/main/docs/script/generate.py

@ -5,7 +5,7 @@ This configuration is exposed via the `xplr.config.node_types` API.
For now, kindly refer to [**init.lua**][1]
> **NEED HELP:** Auto generate rest of the docs from [src/init.lua][1]
> using [docs/script/generate.lua][2].
> using [docs/script/generate.py][2].
[1]: https://github.com/sayanarijit/xplr/blob/main/src/init.lua
[2]: https://github.com/sayanarijit/xplr/blob/main/docs/script/generate.lua
[2]: https://github.com/sayanarijit/xplr/blob/main/docs/script/generate.py

@ -1,45 +0,0 @@
-- Configuration documentation generator
--
-- TODO implement
--
-- This script generates configuration docs by parsing the comments and
-- properties from `src/init.lua`.
--
-- Usage:
--
-- ```
-- lua ./docs/script/generate.lua
-- ```
--
-- Or
--
-- ```
-- xplr -C ./docs/script/generate.lua --on-load Quit
-- ```
-- Generates ./docs/en/src/configuration.md
local function generate_configuration(lines) end
-- Generates ./docs/en/src/general-config.md
local function generate_general_config(lines) end
-- Generates ./docs/en/src/node_types.md
local function generate_node_types(lines) end
-- Generates ./docs/en/src/general-config.md
local function generate_layouts(lines) end
-- Generates ./docs/en/src/general-config.md
local function generate_modes(lines) end
local function main()
local init = io.lines("./src/init.lua")
generate_configuration(init)
generate_general_config(init)
generate_node_types(init)
generate_layouts(init)
generate_modes(init)
end
main()

@ -0,0 +1,116 @@
from dataclasses import dataclass
@dataclass
class Section:
title: str
body: list
@dataclass
class Category:
title: str
sections: list
@dataclass
class Result:
categories: list
msgs: list
TEMPLATE = """
# Full List of Messages
xplr messages categorized based on their purpose.
## Categories
{categories}
{msgs}
## Also See:
- [Message](message.md)
"""
def gen_messages():
path = "./src/msg/in_/external.rs"
res = []
reading = False
with open(path) as f:
lines = iter(f.read().splitlines())
for line in lines:
line = line.strip()
if line.startswith("pub enum ExternalMsg {"):
reading = True
continue
if not reading:
continue
if line == "}":
break
if line.startswith("/// ### "):
line = line.lstrip("/// ### ").rstrip("-").strip()
sec = Section(title=None, body=[])
cat = Category(title=line, sections=[sec])
res.append(cat)
continue
if line.startswith("/// "):
line = line.lstrip("/// ").strip()
res[-1].sections[-1].body.append(line)
continue
elif not line.strip() or line.strip() == "///":
res[-1].sections[-1].body.append("")
elif "," in line:
line = line.split(",")[0].split("(")[0]
res[-1].sections[-1].title = line
sec = Section(title=None, body=[])
res[-1].sections.append(sec)
continue
result = Result(categories=[], msgs=[])
for cat in res:
slug = cat.title.lower().replace(" ", "-")
result.categories.append(f"- [{cat.title}](#{slug})")
result.msgs.append(f"### {cat.title}")
result.msgs.append("")
for sec in cat.sections:
if not sec.title:
continue
result.msgs.append(f"#### {sec.title}")
result.msgs.append("")
for line in sec.body:
result.msgs.append(f"{line}")
result.msgs.append("")
return result
def main():
res = gen_messages()
doc = TEMPLATE.format(
categories="\n".join(res.categories), msgs="\n".join(res.msgs)
)
print(doc)
with open("./docs/en/src/messages.md", "w") as f:
print(doc, file=f)
if __name__ == "__main__":
main()

File diff suppressed because it is too large Load Diff

@ -0,0 +1,26 @@
use crate::node::Node;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub struct DirectoryBuffer {
pub parent: String,
pub nodes: Vec<Node>,
pub total: usize,
pub focus: usize,
}
impl DirectoryBuffer {
pub fn new(parent: String, nodes: Vec<Node>, focus: usize) -> Self {
let total = nodes.len();
Self {
parent,
nodes,
total,
focus,
}
}
pub fn focused_node(&self) -> Option<&Node> {
self.nodes.get(self.focus)
}
}

@ -5,11 +5,15 @@
pub mod app;
pub mod cli;
pub mod config;
pub mod directory_buffer;
pub mod event_reader;
pub mod explorer;
pub mod input;
pub mod lua;
pub mod msg;
pub mod node;
pub mod permissions;
pub mod pipe;
pub mod pipe_reader;
pub mod pwd_watcher;
pub mod runner;

File diff suppressed because it is too large Load Diff

@ -0,0 +1,10 @@
use crate::app::DirectoryBuffer;
use crate::input::Key;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub enum InternalMsg {
AddLastFocus(String, Option<String>),
SetDirectory(DirectoryBuffer),
HandleKey(Key),
}

@ -0,0 +1,12 @@
pub mod external;
pub mod internal;
pub use external::ExternalMsg;
pub use internal::InternalMsg;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub enum MsgIn {
Internal(internal::InternalMsg),
External(external::ExternalMsg),
}

@ -0,0 +1,2 @@
pub mod in_;
pub mod out;

@ -0,0 +1,31 @@
use serde::{Deserialize, Serialize};
use crate::app::{Command, Task};
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub enum MsgOut {
ExplorePwdAsync,
ExploreParentsAsync,
Refresh,
ClearScreen,
Quit,
Debug(String),
Call(Command),
CallSilently(Command),
CallLua(String),
CallLuaSilently(String),
LuaEval(String),
LuaEvalSilently(String),
Enque(Task),
EnableMouse,
DisableMouse,
ToggleMouse,
StartFifo(String),
StopFifo,
ToggleFifo(String),
PrintPwdAndQuit,
PrintFocusPathAndQuit,
PrintSelectionAndQuit,
PrintResultAndQuit,
PrintAppStateAndQuit,
}

@ -0,0 +1,159 @@
use crate::permissions::Permissions;
use humansize::{file_size_opts as options, FileSize};
use serde::{Deserialize, Serialize};
use std::cmp::Ordering;
use std::path::{Path, PathBuf};
fn to_humansize(size: u64) -> String {
size.file_size(options::CONVENTIONAL)
.unwrap_or_else(|_| format!("{} B", size))
}
fn mime_essence(path: &Path, is_dir: bool) -> String {
if is_dir {
String::from("inode/directory")
} else {
mime_guess::from_path(&path)
.first()
.map(|m| m.essence_str().to_string())
.unwrap_or_default()
}
}
#[derive(Debug, Clone, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct ResolvedNode {
pub absolute_path: String,
pub extension: String,
pub is_dir: bool,
pub is_file: bool,
pub is_readonly: bool,
pub mime_essence: String,
pub size: u64,
pub human_size: String,
}
impl ResolvedNode {
pub fn from(path: PathBuf) -> Self {
let extension = path
.extension()
.map(|e| e.to_string_lossy().to_string())
.unwrap_or_default();
let (is_dir, is_file, is_readonly, size) = path
.metadata()
.map(|m| {
(m.is_dir(), m.is_file(), m.permissions().readonly(), m.len())
})
.unwrap_or((false, false, false, 0));
let mime_essence = mime_essence(&path, is_dir);
let human_size = to_humansize(size);
Self {
absolute_path: path.to_string_lossy().to_string(),
extension,
is_dir,
is_file,
is_readonly,
mime_essence,
size,
human_size,
}
}
}
#[derive(Debug, Clone, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct Node {
pub parent: String,
pub relative_path: String,
pub absolute_path: String,
pub extension: String,
pub is_dir: bool,
pub is_file: bool,
pub is_symlink: bool,
pub is_broken: bool,
pub is_readonly: bool,
pub mime_essence: String,
pub size: u64,
pub human_size: String,
pub permissions: Permissions,
pub canonical: Option<ResolvedNode>,
pub symlink: Option<ResolvedNode>,
}
impl Node {
pub fn new(parent: String, relative_path: String) -> Self {
let absolute_path = PathBuf::from(&parent)
.join(&relative_path)
.to_string_lossy()
.to_string();
let path = PathBuf::from(&absolute_path);
let extension = path
.extension()
.map(|e| e.to_string_lossy().to_string())
.unwrap_or_default();
let (is_broken, maybe_canonical_meta) = path
.canonicalize()
.map(|p| (false, Some(ResolvedNode::from(p))))
.unwrap_or_else(|_| (true, None));
let (is_symlink, is_dir, is_file, is_readonly, size, permissions) =
path.symlink_metadata()
.map(|m| {
(
m.file_type().is_symlink(),
m.is_dir(),
m.is_file(),
m.permissions().readonly(),
m.len(),
Permissions::from(&m),
)
})
.unwrap_or_else(|_| {
(false, false, false, false, 0, Permissions::default())
});
let mime_essence = mime_essence(&path, is_dir);
let human_size = to_humansize(size);
Self {
parent,
relative_path,
absolute_path,
extension,
is_dir,
is_file,
is_symlink,
is_broken,
is_readonly,
mime_essence,
size,
human_size,
permissions,
canonical: maybe_canonical_meta.clone(),
symlink: if is_symlink {
maybe_canonical_meta
} else {
None
},
}
}
}
impl Ord for Node {
fn cmp(&self, other: &Self) -> Ordering {
// Notice that the we flip the ordering on costs.
// In case of a tie we compare positions - this step is necessary
// to make implementations of `PartialEq` and `Ord` consistent.
other.relative_path.cmp(&self.relative_path)
}
}
impl PartialOrd for Node {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}

@ -0,0 +1,55 @@
use std::path::PathBuf;
use anyhow::Result;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Pipe {
pub path: String,
pub msg_in: String,
pub selection_out: String,
pub result_out: String,
pub directory_nodes_out: String,
pub global_help_menu_out: String,
pub logs_out: String,
pub history_out: String,
}
impl Pipe {
pub fn from_session_path(path: &str) -> Result<Self> {
let path = PathBuf::from(path).join("pipe");
let msg_in = path.join("msg_in").to_string_lossy().to_string();
let selection_out =
path.join("selection_out").to_string_lossy().to_string();
let result_out = path.join("result_out").to_string_lossy().to_string();
let directory_nodes_out = path
.join("directory_nodes_out")
.to_string_lossy()
.to_string();
let global_help_menu_out = path
.join("global_help_menu_out")
.to_string_lossy()
.to_string();
let logs_out = path.join("logs_out").to_string_lossy().to_string();
let history_out =
path.join("history_out").to_string_lossy().to_string();
Ok(Self {
path: path.to_string_lossy().to_string(),
msg_in,
selection_out,
result_out,
directory_nodes_out,
global_help_menu_out,
logs_out,
history_out,
})
}
}
Loading…
Cancel
Save