Commit Graph

192 Commits (e04b0964aed02b639f969234e35bab5b1a74a73f)

Author SHA1 Message Date
Tom van Dijk 671d1b11fd Refactored parts of `runner::Runner` to take a Cli struct, instead of putting everything manually in `Runner`. 3 years ago
Arijit Basu 1756332e5b Fallback to tempdir if runtime is inaccessible
Fixes: https://github.com/sayanarijit/xplr/issues/319
3 years ago
Arijit Basu 1b1032d0bd Fix missing config error
Do not report error when config file is missing and it's not specified
via CLI args.
3 years ago
Arijit Basu 61657a70c7 Add support for loading extra config files
Use `-C` / `--extra-config` to load Lua files to overwrite the default
or user defined config.

This helps with integration, where integrating xplr with another tool
requires xplr to overwrite some config, without requiring the users to
install an xplr plugin or update the xplr config.

Example:

```bash
    xplr -C one.lua two.lua

    # Or

    xplr -C one.lua -C two.lua
```

> **WARNING:**
>
> Extra config doesn't require specifying the `version`, hence, it's the
> integration author or the user's responsibility to assert
> compatibility using the globally exposed `version` in the extra config
> files, similar to xplr plugins.

Ref: https://github.com/sayanarijit/xplr/issues/316
3 years ago
Arijit Basu 35c18a25dc Remove per directory buffer
Closes: https://github.com/sayanarijit/xplr/issues/289
3 years ago
Arijit Basu 9070cd9e17 Add more docs 3 years ago
Arijit Basu 6162744bef Minor improvements
Closes: https://github.com/sayanarijit/xplr/issues/305
3 years ago
Arijit Basu 6babfeb3d6 Minor improvements
Fixes: https://github.com/sayanarijit/xplr/issues/284
Closes: https://github.com/sayanarijit/xplr/issues/286
Partially fixes: https://github.com/sayanarijit/xplr/issues/285
3 years ago
Arijit Basu 4307ba657a Fix ToggleSelectionByPath
Fixes: https://github.com/sayanarijit/xplr/issues/295
3 years ago
Arijit Basu 329821ca1b Improve FocusNext and FocusPrevious behavior
Closes: https://github.com/sayanarijit/xplr/issues/253
3 years ago
Arijit Basu 4d8f1ef2ef Fix handling of relative paths
Closes: https://github.com/sayanarijit/xplr/issues/255
3 years ago
Arijit Basu 6b03598b5d Add more quit options
Adds the following messages.

- PrintPwdAndQuit
- PrintFocusPathAndQuit
- PrintSelectionAndQuit

Closed: https://github.com/sayanarijit/xplr/issues/257
3 years ago
Arijit Basu 6a70b568bf Fix FocusPath issue
Fixes: https://github.com/sayanarijit/xplr/issues/249
3 years ago
Arijit Basu f12e1e5290 Fix config path on macOS
Also, add `-c` / `--config` CLI option to specify custom config file.

Priority is:

`-c <PATH>` > `~/.config/xplr/init.lua` > `/etc/xplr/init.lua`.

Fixes: https://github.com/sayanarijit/xplr/issues/230
3 years ago
Arijit Basu 1513c325d6 Add option to disable recover mode
Use `config.general.disable_recover_mode = true` to disable the recover
mode.

Closes: https://github.com/sayanarijit/xplr/issues/232
3 years ago
Arijit Basu a2f42ac6fc Add support for FIFO based previewer
Adds basic support for nnn-like FIFO based previewer.

The FIFO can be manager with the following messages:

- StartFifo: /path/to/fifo
- StopFifo
- ToggleFifo: /path/to/fifo

A basic nnn plugin wrapper example:

```lua
-- Usage Example:
--
--   require("nnn_preview_wrapper").setup{
--     plugin_path = os.getenv("HOME") .. "/.config/nnn/plugins/preview-tabbed",
--     fifo_path = "/tmp/xplr.fifo",
--     mode = "action",
--     key = "p",
--   }
--
-- Press `:p` to toggle preview mode.

local function setup(o)

  if o.fifo_path == nil then
    o.fifo_path = os.getenv("NNN_FIFO")
  end

  if o.mode == nil then
    o.mode = "action"
  end

  if o.key == nil then
    o.key = "p"
  end

  local enabled = false
  local message = nil

  os.execute('[ ! -p "' .. o.fifo_path ..'" ] && mkfifo "' .. o.fifo_path .. '"')

  xplr.fn.custom.preview_toggle = function(app)

    if enabled then
      enabled = false
      message = "StopFifo"
    else
      os.execute('NNN_FIFO="' .. o.fifo_path .. '" "'.. o.plugin_path .. '" & ')
      enabled = true
      message = { StartFifo = o.fifo_path }
    end

    return { message }
  end

  xplr.config.modes.builtin[o.mode].key_bindings.on_key[o.key] = {
    help = "search with preview",
    messages = {
      "PopMode",
      { CallLuaSilently = "custom.preview_toggle" },
    },
  }
end

return { setup = setup }
```

Press `:p` to toggle preview mode.

Closes: https://github.com/sayanarijit/xplr/issues/205
3 years ago
Arijit Basu 2962a8d52d Further improve the API.
This improves the compatibility and adds the ability to introduce
non-breaking changes by using a builder pattern.

Example:

```rust
fn main() {
    match xplr::runner(None).and_then(|a| a.run()) {
        Ok(Some(out)) => print!("{}", out),
        Ok(None) => {}
        Err(err) => {
            if !err.to_string().is_empty() {
                eprintln!("error: {}", err);
            };

            std::process::exit(1);
        }
    }
}
```
3 years ago
Arijit Basu fabcc8e865 Implement CLI arguments
Going with custom CLI parsing for minimalism and flexibility.

Closes: https://github.com/sayanarijit/xplr/issues/228
3 years ago
Arijit Basu 902f20aa83 Fix focus jumping
Fixes: https://github.com/sayanarijit/xplr/issues/211
3 years ago
Arijit Basu 7496f5bf8f Disable mouse by default and bind `:m` to toggle
- Make mouse disabled by default.
- Add key binding `:m` to toggle mouse.

Closes: https://github.com/sayanarijit/xplr/issues/206
3 years ago
Arijit Basu 7de0811eaf No need to "Refresh" explicitly
Closes: https://github.com/sayanarijit/xplr/issues/207
3 years ago
Arijit Basu 72a86f8e0e Polish xplr library API
Minor improvements to the xplr library API.

Closes: https://github.com/sayanarijit/xplr/issues/213
3 years ago
Arijit Basu 6412856d73 Improve docs 3 years ago
Arijit Basu fc7d205d92 Improve CallLua and CallLuaSilently
Pass a custom table, optimized for convenience and speed.
3 years ago
Arijit Basu b4247a7d03 Improve CallLua, mime_essence, permissions
Refs:
- https://github.com/sayanarijit/xplr/issues/187
- https://github.com/sayanarijit/xplr/issues/194
- https://github.com/sayanarijit/xplr/issues/195
3 years ago
Arijit Basu db669cdcbf Remove "remaps:"
Remaps has been removed to simplify key bindings. With Lua, it's now
possible to remap using basic assignments.

For e.g.

```Lua
xplr.config.modes.builtin.default.key_bindings.on_key["v"] = xplr.config.modes.builtin.default.key_bindings.on_key.space
```

Help menu will auto detect remapped keys and display after removing the
redundant mappings.

Ref: https://github.com/sayanarijit/xplr/discussions/183#discussioncomment-774159
3 years ago
Arijit Basu cb695fcaa7 Add colorful permissions
Ref: https://github.com/sayanarijit/xplr/issues/187
3 years ago
Arijit Basu b86be16ee3 Make structs public
Public structs enable automatec documentation.
xplr is not (yet) a library. Even it want to become one, making fields
private is probably not the right way.
3 years ago
Arijit Basu 84a50a8fde Add CallLua and CallLuaSilently
This works:

```lua
xplr.fn.custom.ping = function(app)
  print("What's your name?")
  local name = io.read()
  os.execute('read -p "Hello ' .. name .. ', you are in ' .. app.pwd .. '"')
  return {
    { LogSuccess = "pong" },
  }
end
```

Then it can be called via `CallLua: custom.ping`.
3 years ago
Arijit Basu 10e874afe7 Fall back to default config when custom config fails
When the custom `init.lua` is corrupt, xplr will fall back to default
configuration, logging the encountered error after load.
3 years ago
Arijit Basu f9d13e5e4c Fix initial directory sync issue 3 years ago
Arijit Basu 25a9d03237 Finish porting config.yml to init.lua 3 years ago
Arijit Basu e977aeb7d3 Fix MacOS error directory not empty
With this change, xplr will delete the pipe files when command execution
is over.
3 years ago
Arijit Basu 003e90a7d1 Improve history further 3 years ago
Arijit Basu 97aa2ff8b4 Fix initial focus 3 years ago
Arijit Basu 5b2aee3479 Improve history navigation
Make path history behave like jump list and allow jumping back and
forth in the same directory.
3 years ago
Arijit Basu d96e620120 Begin porting config.yml to init.lua
This commit begins porting of `config.yml` to `init.lua`.
As of now, it's not be possible to do the complete migration
because of how lua and yaml handles `null`/`nil` value.

So, we will need to completely deprecate `config.yml` in order to do the
complete migration.
3 years ago
Arijit Basu 074e0d1250 Replace handlebars with Lua
Replace handlebars with Lua functions by introduction Lua function API.
3 years ago
Arijit Basu 79855dba15 Fix CallSilently
Closes: https://github.com/sayanarijit/xplr/issues/163
3 years ago
Arijit Basu 6cc863e6d4 Add send+anyhow support for mlua
Ref: https://github.com/khvzak/mlua/issues/48
3 years ago
Arijit Basu f744553a0a Add support for native lua bindings
Ref: https://github.com/sayanarijit/xplr/discussions/146#discussioncomment-741580
3 years ago
Arijit Basu 7eabd3fb7d Fix selecting broken symlink 3 years ago
Arijit Basu 8e98da5004 Add support for un-mapping keys.
Use `remaps: {key: null}` to un-map a key.

Also,
- `gx` will now open only the file under focus.
- `:sx` will open the selected files.

And other minor improvements.

Discussion: https://github.com/sayanarijit/xplr/discussions/146
3 years ago
Arijit Basu 57a0a49aae Hide logs also when calling subprocess 3 years ago
Arijit Basu 96f3640fc0 Rename `reckless` to `recover`
Also, improve the warning message.
3 years ago
Arijit Basu ae8a391064 Introduce `PopMode`
This change requires manual `Refresh` after mode switches.
Also, fix the rename operation.
3 years ago
Arijit Basu 7588620c8f Hind logs when switching to input mode
Ref: https://github.com/sayanarijit/xplr/pull/143#issuecomment-840069000
3 years ago
Arijit Basu c68bd96253 Add reckless mode
Pressing an invalid key will take you to the "reckless" mode. All you
need to do is calm down, escape that mode, and try again.

Closes: https://github.com/sayanarijit/xplr/issues/142
3 years ago
Arijit Basu 82b975c5f0 Fix some sync issues
Handle out messages immediately instead or scheduling in messages.
3 years ago
Arijit Basu cd5bf81646 Optimize performance
```
Benchmarking focus next item: Collecting 100 samples in estimated 5.1972 s (126k itera                                                                                      focus next item         time:   [41.216 us 41.346 us 41.494 us]
                        change: [-28.669% -28.110% -27.551%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 9 outliers among 100 measurements (9.00%)
  4 (4.00%) high mild
  5 (5.00%) high severe

Benchmarking focus previous item: Collecting 100 samples in estimated 5.0576 s (116k i                                                                                      focus previous item     time:   [43.589 us 43.754 us 43.927 us]
                        change: [-29.506% -28.748% -28.039%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 3 outliers among 100 measurements (3.00%)
  1 (1.00%) high mild
  2 (2.00%) high severe

Benchmarking focus first item: Collecting 100 samples in estimated 5.1765 s (116k iter                                                                                      focus first item        time:   [44.071 us 44.340 us 44.634 us]
                        change: [-26.739% -26.314% -25.885%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 12 outliers among 100 measurements (12.00%)
  8 (8.00%) high mild
  4 (4.00%) high severe

Benchmarking focus last item: Collecting 100 samples in estimated 5.1522 s (116k itera                                                                                      focus last item         time:   [43.950 us 44.214 us 44.541 us]
                        change: [-27.571% -26.953% -26.337%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 11 outliers among 100 measurements (11.00%)
  5 (5.00%) high mild
  6 (6.00%) high severe

Benchmarking leave and enter directory: Collecting 100 samples in estimated 5.4863 s (                                                                                      leave and enter directory
                        time:   [96.645 us 96.915 us 97.234 us]
                        change: [-28.720% -27.224% -25.666%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 9 outliers among 100 measurements (9.00%)
  6 (6.00%) high mild
  3 (3.00%) high severe
```
3 years ago
Arijit Basu 7c5468cabe Fix exploring and escaping paths
This PR targets 2 pain points.

1. The `Explore` message was async, which caused some unexpected
   behavior. This was fixed by splitting `Explore` into `ExplorePwd`,
   `ExplorePwdAsync` and `ExploreParentsAsync`. `ExploreParentsAsync`
   is similar to the former `Explore`, which is mainly used when loading
   `xplr` for the first time. However, what we'll be using frequently
   are `ExplorePwd` and `ExplorePwdAsync` messages.

2. Files with spaces caused some unexpected behavior. This was fixed by
   escaping the paths properly. This also fixed focusing of a file after
   creating or renaming it.

Anothor breaking change is that `XPLR_PIPE_FOCUS_OUT` has been removed.
`XPLR_FOCUS_PATH` is all we need. So, the rule of thumb is if a variable
contains one liner value, it can be used directly from the env vars.
Variables that can contain multi-line values, will be exposed via the
pipes.

Minor changes are

- Add `switch_mode` mode to the global key binding help menu
- Moved some UI related code from config.rs to ui.rs.
- Fixed compilation issue on `rustc 1.50.0`.
3 years ago
Arijit Basu 52fbaef189 Fix displaying global help menu
Also support toggle selection in search mode.
And use a pager to display logs.
3 years ago
Arijit Basu 3aa349f614 Don't refresh pipes on every iteration
From this commit, the app state will be written to the output pipes only
when invoking a command.

For auto refreshing pipes, we can brainstorm on `service`s concept.
3 years ago
Arijit Basu b3e6679b50 Add feature dynamic UI
Now, users can change the UI layout via the `SwitchLayout{Builtin|Custom}`
message, or by using key `ctrl-w`.

There are 3 default layout options -

- default
- no_help
- no_selection
- no_help_no_selection

Also, the initial mode and the initial layout can be specified in the
config.

Closes: https://github.com/sayanarijit/xplr/issues/107
3 years ago
Arijit Basu 474c17b493
Minor fix 3 years ago
Arijit Basu 0584a43c7c Add SwitchModeBuiltin and SwitchModeCustom
Also, use a better prompt symbol.

Ref: https://github.com/sayanarijit/xplr/issues/107
3 years ago
Arijit Basu 2c7ec47253 Fix `cd` on first focus
Fix issue where running `xplr /path/to/file` doesn't `cd` into the
parent directory.
3 years ago
Arijit Basu 36af3e8ced Fix pipes not updating properly
Let's not optimize things until we have tests.
3 years ago
Arijit Basu 8ddc000895 Make config private 3 years ago
Arijit Basu f38398e900 Make internals private 3 years ago
Arijit Basu 33e500a16d Move pipe writing logic from runner to app
Ref: https://github.com/sayanarijit/xplr/issues/103
3 years ago
Arijit Basu 014043d330 Fix formatting the global help menu 3 years ago
Arijit Basu 1ffa85f30f Do not exit on permission denial
While trying to enter restricted directories, log error instead or
exiting.
3 years ago
Arijit Basu 785c20de13 Sync pwd
Sync session's $PWD with `xplr`'s current directory.
If you use alacritty, every window will open in `xplr`'s current
directory.
3 years ago
Arijit Basu c11099f651 Fix follow symlink behavior.
Use `gf` to follow symlinks instead of `enter`/`l`.

Or use the message `FollowSymlink`.
3 years ago
Arijit Basu 87cd6ff015 Fix global help menu not displaying sort & filter 3 years ago
Arijit Basu 1f99e8ba99 Follow file symlinks
Follow symlink to files to it's parent directory.

Also, hide file size for directories.

Ref: https://github.com/sayanarijit/xplr/issues/84
3 years ago
Arijit Basu ca13ebb193 Added inode size
Also supports sorting by inode size.

Closes: https://github.com/sayanarijit/xplr/issues/84
3 years ago
Arijit Basu b53f0c21bb Improve read-only mode
Do not include non-read-only actions in the in read-only mode. i.e. do
not display non-read-only actions in help menu.

Ref: https://github.com/sayanarijit/xplr/issues/22
3 years ago
Arijit Basu 21f87d6a08 Add read-only mode
Ref: https://github.com/sayanarijit/xplr/issues/22
3 years ago
Arijit Basu e70fa57228 Fix selection
Fixes: https://github.com/sayanarijit/xplr/issues/81
3 years ago
Arijit Basu 1bb2622f24 Improve key inputs
Add support proper implementations of -

- backspace
- ctrl-w
- ctrl-u

Also, improved sort and filter behavior.

Fixes: https://github.com/sayanarijit/xplr/issues/77
3 years ago
Arijit Basu a8896740c8 Add sorting support
Also improve filtering.

Closes: https://github.com/sayanarijit/xplr/issues/58
3 years ago
Arijit Basu 54bad4aa09 Add mode selection commands
- SelectAll
- SelectPath
- UnSelectAll
- UnSelectPath
- ToggleSelectAll
- ToggleSelectionByPath
3 years ago
Arijit Basu 0c82a645d9 Add history pipe 3 years ago
Arijit Basu af1cda5762 Better symlink support
Closes: https://github.com/sayanarijit/xplr/issues/37
3 years ago
Arijit Basu 49ffd8e1f1 Fix exit error codes
Also remove cucumber-rust (will try https://github.com/rust-rspec/rspec)

Fixes: https://github.com/sayanarijit/xplr/issues/33
3 years ago
Arijit Basu 55e1a6a0fa Add basic history navigation
Use `ctrl-i` (tab) and `ctrl-o` to navigate history.

Closes: https://github.com/sayanarijit/xplr/issues/49
3 years ago
Arijit Basu f247acf626 Fix remap behaviour and help menu
Remapping a key should overwrite default. Also, remapped keys shouldn't
be redundantly visible in help menu.

Also, display log time.
3 years ago
Arijit Basu 055c1083d6 Support easier key remaps
Also,

- Add key binding `~` to go to homedir.
- Add customizable cursor and prompts.
- Improve the help menus.
3 years ago
Arijit Basu 080e1686f3 Improve version compatibility
From this version, xplr won't annoy the users to visit the upgrade guide
when there is no need.

Also, users will only get upgrade related notification when it is
there is one.
3 years ago
Arijit Basu 3598be0f19 Improve config defaults
- Rename `custom` field for node metadata to `meta`.
- Move `icon` to `meta.icon`.
- Rename `normal_ui` to `default_ui`.
- Rename `filetypes` to `node_types`.
- Split `modes` into `modes.builtin` and `modes.custom`.
- Add the missing `create file` mode.
- Rename `focused_ui` to `focus_ui`.
- Make `general.table.header` non-nullable.
- Add support for incremental configuration updates.

Ref: https://github.com/sayanarijit/xplr/issues/45
3 years ago
Arijit Basu 6aa3df301e Separate config.yml file from rust files
Also be less aggressive for version compatibility.

Use the following logic:

Knowing that we use `{major}.{minor}.{patch}` versioning,

- Major version mismatch are incompatible. Fail with error, suggesting to
  visit the Upgrade Guide.
- Minor version updates and patch fixes are compatible. Suggest user to
  update the config file version manually. Or visit the Upgrade Guide.

- However, if the config file has greater value for minor version
  than the app, also fail with error. Suggesting the user to visit Upgrade
  Guide. Though in this case, the user will be downgrading.

Ref: https://github.com/sayanarijit/xplr/issues/45
3 years ago
Arijit Basu 233f6d44a5
Update version 3 years ago
Arijit Basu 2596c0c4c3 Remove task priority
Since we are now blocking on task inputs, the priority is no longer
required.
3 years ago
Arijit Basu 9f78a1fcff Ability to call commands silently
Some commands doesn't require to capture stdout and stderr.
They can be called without needing to reset the screen.

Add `CallSilently` and `BashExecSilently` to execute those commands
faster.

Also, some optimization.
3 years ago
Arijit Basu a68fec0c11
No need to clone selection 3 years ago
Arijit Basu b50ce48264
Revert "Optimize the main thread"
This reverts commit 097c9dd8c5.

Queued tasks might create unexpected issues. We need a test suit first.
3 years ago
Arijit Basu 097c9dd8c5 Optimize the main thread 3 years ago
Arijit Basu b9e9601a71
Fix failed build and update version 3 years ago
Maxim Baz 70a3794857 Fix symlink support
canonicalize() and metadata() both resolve symlinks, thus showing symlinks as regular files
3 years ago
Arijit Basu c06a3cb51e
Update version 3 years ago
Arijit Basu 6d0ea06d7b Add pwd watcher
Also optimize the main thread.
3 years ago
Arijit Basu 0a3cf7b5c1
Update version 3 years ago
Arijit Basu fa37cd1c10 Improve search and filter
Concern:
Using `ResetNodeFilters` to clear the filters while searching or exiting
from search unexpectedly resets the `show hidden` mode because the
action not only removes the target filter, it resets all the other
filters as well.

Solution:
Implement `RemoveNodeFilterFromInput` to be able to clear or remove
target filters without having to reset it.
3 years ago
Arijit Basu 91a319fc80
Update version 3 years ago
Arijit Basu 23b51cf8fe
Fix failed build and re-publish 3 years ago
Arijit Basu 2bd2b743fb
Fix renaming 3 years ago
Arijit Basu a484c2fd39
Update default.nix 3 years ago
Arijit Basu e34755b11b Update version
Also fix nix hash
3 years ago