diff --git a/en/404.html b/en/404.html index c41d43a..d30b788 100644 --- a/en/404.html +++ b/en/404.html @@ -76,7 +76,7 @@ diff --git a/en/alternatives.html b/en/alternatives.html index c0dbc81..911641b 100644 --- a/en/alternatives.html +++ b/en/alternatives.html @@ -75,7 +75,7 @@ diff --git a/en/awesome-integrations.html b/en/awesome-integrations.html index aa00bf7..9330ed1 100644 --- a/en/awesome-integrations.html +++ b/en/awesome-integrations.html @@ -75,7 +75,7 @@ diff --git a/en/awesome-plugins.html b/en/awesome-plugins.html index a1ea38c..57b6902 100644 --- a/en/awesome-plugins.html +++ b/en/awesome-plugins.html @@ -75,7 +75,7 @@ diff --git a/en/column-renderer.html b/en/column-renderer.html index 6240231..2e374fe 100644 --- a/en/column-renderer.html +++ b/en/column-renderer.html @@ -75,7 +75,7 @@ @@ -325,7 +325,7 @@ xplr.config.general.table.col_widths = { -
@@ -337,7 +337,7 @@ xplr.config.general.table.col_widths = { - diff --git a/en/community.html b/en/community.html index 76a23e7..269fc0c 100644 --- a/en/community.html +++ b/en/community.html @@ -75,7 +75,7 @@ diff --git a/en/configuration.html b/en/configuration.html index 180f2db..c6146cc 100644 --- a/en/configuration.html +++ b/en/configuration.html @@ -75,7 +75,7 @@ @@ -175,7 +175,7 @@ following fields:

-
@@ -187,7 +187,7 @@ following fields:

- diff --git a/en/configure-key-bindings.html b/en/configure-key-bindings.html new file mode 100644 index 0000000..914b80f --- /dev/null +++ b/en/configure-key-bindings.html @@ -0,0 +1,330 @@ + + + + + + Configure Key Bindings - xplr book + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + +
+
+

Configure Key Bindings

+

In xplr, each keyboard input passes through a bunch of handlers (e.g. on_key, +on_number, default etc.) in a given order. If any of the handlers is +configured to with an action, it will intercept the key and produce +messages for xplr to handle.

+

Key Bindings

+

Key bindings contains the following information:

+ +

on_key

+

Type: mapping of Key to nullable Action

+

Defines what to do when an exact key is pressed.

+

on_alphabet

+

Type: nullable Action

+

An action to perform if the keyboard input is an alphabet and is not mapped via +the on_key field.

+

on_number

+

Type: nullable Action

+

An action to perform if the keyboard input is a number and is not mapped via +the on_key field.

+

on_alphanumeric

+

Type: nullable Action

+

An action to perform if the keyboard input is alphanumeric and is not mapped +via the on_key, on_alphabet or on_number field.

+

on_special_character

+

Type: nullable Action

+

An action to perform if the keyboard input is a special character and is not +mapped via the on_key field.

+

on_character

+

Type: nullable Action

+

An action to perform if the keyboard input is a character and is not mapped +via the on_key, on_alphabet, on_number, on_alphanumeric +or on_special_character field.

+

on_navigation

+

Type: nullable Action

+

An action to perform if the keyboard input is a navigation key and is not +mapped via the on_key field.

+

default

+

Type: nullable Action

+

Default action to perform in case if a keyboard input not mapped via any of the +on_* fields mentioned above.

+

Key

+

A key can be one of the following:

+
    +
  • 0, 1, ... 9
  • +
  • a, b, ... z
  • +
  • A, B, ... Z
  • +
  • f1, f2, ... f12
  • +
  • backspace
  • +
  • left
  • +
  • right
  • +
  • up
  • +
  • down
  • +
  • home
  • +
  • end
  • +
  • page-up
  • +
  • page-down
  • +
  • back-tab
  • +
  • delete
  • +
  • insert
  • +
  • enter
  • +
  • tab
  • +
  • esc
  • +
  • ctrl-a, ctrl-b, ... ctrl-z
  • +
  • ctrl-backspace, ctrl-left, ... ctrl-esc
  • +
  • alt-a, alt-b, ... alt-z
  • +
+

And finally, the special characters - including space (" ") with their ctrl +bindings.

+

Action

+

An action contains the following information:

+ +

help

+

Type: nullable string

+

Description of what it does. If unspecified, it will be excluded from the help +menu.

+

messages

+

Type: A list of Message to send.

+

The list of messages to send when a key is pressed.

+

Tutorial: Adding a New Mode

+

Assuming xplr is installed and setup, let's +add our own mode to integrate xplr with fzf.

+

We'll call it fzxplr mode.

+

First, let's add a custom mode called fzxplr, and map the key F to an +action that will call fzf to search and focus on a file or enter into a +directory.

+
xplr.config.modes.custom.fzxplr = {
+  name = "fzxplr",
+  key_bindings = {
+    on_key = {
+      F = {
+        help = "search",
+        messages = {
+          {
+            BashExec = [===[
+            PTH=$(cat "${XPLR_PIPE_DIRECTORY_NODES_OUT:?}" | awk -F/ '{print $NF}' | fzf)
+            if [ -d "$PTH" ]; then
+              echo ChangeDirectory: "'"${PWD:?}/${PTH:?}"'" >> "${XPLR_PIPE_MSG_IN:?}"
+            else
+              echo FocusPath: "'"${PWD:?}/${PTH:?}"'" >> "${XPLR_PIPE_MSG_IN:?}"
+            fi
+            ]===]
+          },
+          "PopMode",
+        },
+      },
+    },
+    default = {
+      messages = {
+        "PopMode",
+      },
+    },
+  },
+}
+
+

As you can see, the key F in mode fzxplr (the name can be anything) +executes a script in bash.

+

BashExec, PopMode, SwitchModeBuiltin, ChangeDirectory and FocusPath +are messages, $XPLR_PIPE_MSG_IN, +$XPLR_PIPE_DIRECTORY_NODES_OUT are +environment variables exported by xplr +before executing the command. They contain the path to the +input and output pipes that +allows external tools to interact with xplr.

+

Now that we have our new mode ready, let's add an entry point to this mode via +the default mode.

+
xplr.config.modes.builtin.default.key_bindings.on_key["F"] = {
+  help = "fzf mode",
+  messages = {
+    { SwitchModeCustom = "fzxplr" },
+  },
+}
+
+

Now let's try out the new xplr-fzf integration.

+

xplr-fzf.gif

+
+

Visit Awesome Plugins for more integration options.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + diff --git a/en/contribute.html b/en/contribute.html index 41834d4..4b13ed0 100644 --- a/en/contribute.html +++ b/en/contribute.html @@ -75,7 +75,7 @@ diff --git a/en/debug-key-bindings.html b/en/debug-key-bindings.html new file mode 100644 index 0000000..1092069 --- /dev/null +++ b/en/debug-key-bindings.html @@ -0,0 +1,272 @@ + + + + + + Debug Key Bindings - xplr book + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + +
+
+

Debug Key Bindings

+

If you need help debugging or understanding key bindings DYI way, you can +create a test.lua file with the following script, launch xplr with +xplr --extra-config text.lua, press # and play around.

+
xplr.config.modes.builtin.default.key_bindings.on_key["#"] = {
+  help = "test",
+  messages = {
+    "PopMode",
+    { SwitchModeCustom = "test" },
+  },
+}
+
+xplr.config.modes.custom.test = {
+  name = "test",
+  key_bindings = {
+    on_key = {
+      ["1"] = {
+        messages = {
+          { LogInfo = "on_key called" },
+        },
+      },
+      a = {
+        messages = {
+          { LogInfo = "on_key called" },
+        },
+      },
+      ["`"] = {
+        messages = {
+          { LogInfo = "on_key called" },
+        },
+      },
+      f1 = {
+        messages = {
+          { LogInfo = "on_key called" },
+        },
+      },
+      tab = {
+        messages = {
+          { LogInfo = "on_key called" },
+        },
+      },
+      esc = {
+        messages = {
+          "PopMode",
+        },
+      },
+      ["ctrl-c"] = {
+        messages = {
+          "Terminate",
+        },
+      },
+    },
+    on_alphabet = {
+      messages = {
+        { LogInfo = "on_alphabet called" },
+      },
+    },
+    on_number = {
+      messages = {
+        { LogInfo = "on_number called" },
+      },
+    },
+    -- on_alphanumeric = {
+    --   messages = {
+    --     { LogInfo = "on_alphanumeric called" },
+    --   },
+    -- },
+    on_special_character = {
+      messages = {
+        { LogInfo = "on_special_character called" },
+      },
+    },
+    -- on_character = {
+    --   messages = {
+    --     { LogInfo = "on_character called" },
+    --   },
+    -- },
+    on_navigation = {
+      messages = {
+        { LogInfo = "on_navigation called" },
+      },
+    },
+    default = {
+      messages = {
+        { LogInfo = "default called" },
+      },
+    },
+  },
+}
+
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + diff --git a/en/default-key-bindings.html b/en/default-key-bindings.html index 951dc38..2df693e 100644 --- a/en/default-key-bindings.html +++ b/en/default-key-bindings.html @@ -75,7 +75,7 @@ @@ -142,8 +142,8 @@

Default Key Bindings

The default key binding is inspired by vim and slightly -overlaps with nnn, but it's supposed to be -customized as per user requirements.

+overlaps with nnn, but it's supposed to be customized as per user +requirements.

When you press ? in default mode, you can see the complete list of modes and the key mappings for each mode.

default

@@ -183,7 +183,6 @@ of modes and the key mappings for each mode.

filter

- @@ -192,10 +191,7 @@ of modes and the key mappings for each mode.

keyremapsaction
Rrelative does not contain
backspaceremove last filter
ctrl-cterminate
ctrl-rreset filters
ctrl-uclear filters

number

- - - @@ -212,12 +208,9 @@ of modes and the key mappings for each mode.

keyremapsaction
backspaceremove last character
ctrl-cterminate
ctrl-uremove line
ctrl-wremove last word
downjto down
enterto index
esccancel
- - - @@ -253,28 +246,19 @@ of modes and the key mappings for each mode.

keyremapsaction
backspaceremove last character
ctrl-cterminate
ctrl-ndowndown
ctrl-pupup
ctrl-uremove line
ctrl-wremove last word
enterescfocus
leftback
rightenter

create file

- - -
keyremapsaction
backspaceremove last character
ctrl-cterminate
ctrl-uremove line
ctrl-wremove last word
entercreate file
esccancel

create directory

- - -
keyremapsaction
backspaceremove last character
ctrl-cterminate
ctrl-uremove line
ctrl-wremove last word
entercreate directory
esccancel

rename

- - -
keyremapsaction
backspaceremove last character
ctrl-cterminate
ctrl-uremove line
ctrl-wremove last word
enterrename
esccancel
@@ -307,7 +291,6 @@ of modes and the key mappings for each mode.

filter

- @@ -316,19 +299,13 @@ of modes and the key mappings for each mode.

keyremapsaction
Rrelative does not contain
backspaceremove last filter
ctrl-cterminate
ctrl-rreset filters
ctrl-uclear filters

relative path does contain

- - -
keyremapsaction
backspaceremove last character
ctrl-cterminate
ctrl-uremove line
ctrl-wremove last word
enterapply filter
esccancel

relative path does not contain

- - -
keyremapsaction
backspaceremove last character
ctrl-cterminate
ctrl-uremove line
ctrl-wremove last word
enterapply filter
esccancel
@@ -346,10 +323,10 @@ of modes and the key mappings for each mode.

diff --git a/en/node_types.html b/en/node_types.html index fb790f7..39f056b 100644 --- a/en/node_types.html +++ b/en/node_types.html @@ -75,7 +75,7 @@ diff --git a/en/plugin.html b/en/plugin.html index 3f8e34a..19e2a7b 100644 --- a/en/plugin.html +++ b/en/plugin.html @@ -75,7 +75,7 @@ @@ -153,7 +153,7 @@ extend xplr UI and functionalities.