Replies: 13 comments 8 replies
-
|
we could implement a parser like the one in |
Beta Was this translation helpful? Give feedback.
-
|
I think this is already implemented, unless I'm missing the point 🤔 tv -k 'toggle_status_bar="ctrl-s"'Screencast.From.2025-07-08.13-27-05.mp4 |
Beta Was this translation helpful? Give feedback.
-
|
I'm proposing an extension of the current system Let's assume we expose these events and actions to the new system EventsActionsNavigation ActionsSelection ActionsPreview ActionsUI Transformation ActionsCommand Execution ActionsExamplesSyntax to be defined, using # Move cursor to the last item and select all items
seq 1000 | tv --bind "start:last+select-all"
# Change the prompt to "loaded" when the input stream is complete
(seq 10; sleep 1; seq 11 20) | tv --input-header "Loading" --bind "load:change-input-header:Done" |
Beta Was this translation helpful? Give feedback.
-
|
put together a pest parser and it looks something like this |
Beta Was this translation helpful? Give feedback.
-
|
quick update: I have a working implementation of how it should look like, didn't add any new feature it's just parity with what we currently have. Will put more details later. |
Beta Was this translation helpful? Give feedback.
-
KeybindingsTelevision supports two keybinding configuration formats:
Both formats are fully supported and can be used together. Default KeybindingsDefault keybindings are as follows:
These keybindings are all configurable via tv's configuration file (see Configuration). Configuration FormatsTOML FormatThe traditional TOML format maps actions to lists of keys: [keybindings]
quit = ["esc", "ctrl-c"]
select_next_entry = ["down", "ctrl-n", "ctrl-j"]
select_prev_entry = ["up", "ctrl-p", "ctrl-k"]
toggle_selection_down = "tab"
toggle_selection_up = "backtab"
confirm_selection = "enter"
toggle_remote_control = "ctrl-t"
toggle_preview = "ctrl-o"
toggle_help = "ctrl-h"
toggle_status_bar = "f12"Binding SyntaxThe new binding syntax is more expressive and readable, using a key/event-to-action mapping: bindings {
// === APPLICATION CONTROL ===
esc => quit;
ctrl-c => quit;
// === NAVIGATION AND SELECTION ===
down => select_next_entry;
ctrl-n => select_next_entry;
ctrl-j => select_next_entry;
up => select_prev_entry;
ctrl-p => select_prev_entry;
ctrl-k => select_prev_entry;
// === SELECTION ===
tab => toggle_selection_down;
backtab => toggle_selection_up;
enter => confirm_selection;
// === UI FEATURES ===
ctrl-t => toggle_remote_control;
ctrl-o => toggle_preview;
ctrl-h => toggle_help;
f12 => toggle_status_bar;
}CommentsFull comment support with both single-line and multi-line comments: bindings {
// Single-line comments
j => select_next_entry; // Vim-style navigation
k => select_prev_entry; // Vim-style navigation
/* Multi-line comments
are also supported */
enter => confirm_selection;
}Action BlocksExecute multiple actions in sequence with a single key press: bindings {
// Move to next entry and select the next two items
f5 => {
select_next_entry;
toggle_selection_down;
toggle_selection_down;
};
// Reload and toggle help panel in one action
f6 => {
reload_source;
toggle_help;
};
}
Event BindingsRespond to application events automatically: bindings {
// Triggered when input stream is complete
@load => reload_source;
// Triggered when filtering is complete
@result => toggle_status_bar;
// Triggered when multi-selection changes
@selection-change => copy_entry_to_clipboard;
// Triggered when there's only one match
@one => select_and_exit;
// Triggered when there's no match
@zero => quit;
}Parameterized Actions (Planned)Some actions are designed to accept parameters but this feature is not yet implemented: // Planned feature - not yet available
bindings {
enter => execute("less {}");
f1 => switch_to_channel("files");
}Key SpecificationsBasic Keys
Character Keys
Modified Keys
Special Keys
Available ActionsNavigation
Selection
Input Navigation
Preview Control
Application Control
Feature Toggles
Data Operations
Event SystemEvents allow you to automatically trigger actions when certain application events occur. Available Events
Migration GuideFrom TOML to New SyntaxTOML format: [keybindings]
quit = ["esc", "ctrl-c"]
select_next_entry = ["down", "ctrl-j"]
toggle_preview = "ctrl-o"New syntax equivalent: bindings {
esc => quit;
ctrl-c => quit;
down => select_next_entry;
ctrl-j => select_next_entry;
ctrl-o => toggle_preview;
}Using Both FormatsYou can use both formats together by creating a Create: bindings {
j => select_next_entry;
k => select_prev_entry;
ctrl-c => quit;
enter => confirm_selection;
}Keep your existing: [ui]
theme = "default"
[keybindings]
copy_entry_to_clipboard = "ctrl-y"Television automatically loads and merges both formats. The binding syntax takes precedence over TOML for conflicting bindings. Error HandlingThe binding syntax parser provides detailed error messages: Common errors:
|
Beta Was this translation helpful? Give feedback.
-
Binding System ArchitectureOverviewThe Television binding system maps keys and events to actions using a dual-format parser (TOML + DSL) built on Pest. graph TD
A[Configuration Input] --> B{Parser Selection}
B -->|Binding System| C1
B -->|TOML| D1
subgraph primary[" "]
C1[parse_bindings]
C2[Pest Grammar Processing]
C3[Television AST Generation]
C1 --> C2 --> C3
end
subgraph secondary[" "]
D1[parse_toml_bindings]
D2[TOML Grammar Processing]
D3[TOML to AST Conversion]
D1 --> D2 --> D3
end
C3 --> E[Unified AST]
D3 --> E
E --> F[Converter Layer]
F --> G[Television Bindings]
G --> H[Runtime Execution]
B -->|Both Fail| I[Parse Error]
Grammar DefinitionCore Grammar StructureKey Grammar ComponentsHierarchical Configuration Merginggraph TB
A["Embedded Defaults"] --> B["User Config"]
B --> C["Channel Configs"]
subgraph ABS["Additional Bindings Sources"]
D1["Explicit Files<br/>--bindings-file FILENAME"]
D2["Custom Directory<br/>--bindings-dir DIRNAME"]
D3["Default Directory<br/>$CONFIG/bindings.tvb<br/>$CONFIG/keybindings.toml"]
end
C --> D1
C --> D2
C --> D3
E["Merge Bindings"] --> F["Final Configuration"]
D1 --> E
D2 --> E
D3 --> E
Action Block State ManagementstateDiagram-v2
[*] --> Received: ActionBlock arrives
Received --> HashCheck: Calculate hash
HashCheck --> Processed: Hash not found
HashCheck --> Skipped: Hash exists
Processed --> Queued: Mark hash, queue actions
Queued --> [*]: Actions sent to channel
Skipped --> [*]: Duplicate prevention
note right of HashCheck
Hash-based deduplication
using FxHashSet<u64>
end note
note right of Queued
Individual actions sent
via action_tx channel
end note
File StructureGrammar Extensions (not Implemented)
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
Sorry for the late reply. This looks awesome 👍🏻 👍🏻 👍🏻 The only thing that bothers me after reading the whole thing is I don't think we want two keybindings configuration systems (and formats) because it puts extra work on users to figure out how to configure the app and it's always more difficult to maintain in the long term. Which makes me wonder: Could the pest grammar you defined be expressed using TOML instead? That would be awesome since it would allow to include keybindings in the |
Beta Was this translation helpful? Give feedback.
-
|
closing this one we can continue in PR #659 |
Beta Was this translation helpful? Give feedback.
-
|
reopening again, considering using only toml instead of pest. TOML-Only Binding SystemCurrent Status AnalysisPest-based Television Syntax Feature Set1. Key Specifications// Basic keys
enter => confirm_selection;
esc => quit;
tab => toggle_selection_down;
backtab => toggle_selection_up;
space => select_entry;
backspace => delete_prev_char;
delete => delete_next_char;
// Arrow keys
up => select_prev_entry;
down => select_next_entry;
left => go_to_prev_char;
right => go_to_next_char;
// Navigation keys
home => go_to_input_start;
end => go_to_input_end;
pageup => select_prev_page;
pagedown => select_next_page;
// Function keys
f1 => toggle_help;
f2 => reload_source;
// ... f1 through f12
// Modified keys
ctrl-a => go_to_input_start;
ctrl-e => go_to_input_end;
ctrl-c => quit;
// Mouse events
mouse-scroll-up => scroll_preview_up;
mouse-scroll-down => scroll_preview_down;
// Character keys (a-z, 0-9, symbols)
j => select_next_entry;
k => select_prev_entry;2. Action Targets// Single action
esc => quit;
// Action block (sequential execution)
f5 => {
reload_source;
toggle_preview;
};
// Action array (alternative syntax)
f6 => [reload_source, toggle_status_bar];
// Parameterized actions
f7 => execute("custom_command");
f8 => switch_to_channel("files");3. Event Bindings// Application lifecycle events
@start => toggle_help; // Application startup
@load => reload_source; // Channel data loaded
@result => toggle_status_bar; // Search filtering complete
@resize => refresh_ui; // Terminal resize
// Search result events
@one => select_and_exit; // Exactly one match
@zero => quit; // No matches
// User interaction events
@selection-change => copy_entry_to_clipboard; // Multi-selection changed4. Channel-Specific Bindings// Exact channel match
channel "files" {
f8 => toggle_preview;
f7 => copy_entry_to_clipboard;
@load => auto_preview_first;
}
// Pattern-based matching
for_channels("files") {
f1 => toggle_help;
f5 => reload_source;
}
// Multiple patterns
for_channels("files", "dirs", "git_*") {
ctrl-g => git_status;
ctrl-r => reload_source;
}5. Commentsbindings {
// Single-line comments
ctrl-c => quit; // Inline comments also supported
/* Multi-line comments
spanning multiple lines */
enter => confirm_selection;
}Current TOML Format Limitations[keybindings]
# Only supports simple action-to-keys mapping
quit = ["esc", "ctrl-c"]
select_next_entry = ["down", "ctrl-n", "ctrl-j"]
toggle_preview = "ctrl-o"
# Cannot express:
# - Action blocks/sequences
# - Event bindings
# - Parameterized actionsAlternative proposal using only TOML1. Basic Key BindingsTelevision Syntax: esc => quit;
enter => confirm_selection;TOML Equivalent: [keybindings]
esc = "quit"
enter = "confirm_selection"2. Multiple Keys to Single ActionTelevision Syntax: esc => quit;
ctrl-c => quit;TOML Equivalent: [keybindings]
quit = ["esc", "ctrl-c"]3. Action Blocks (Sequential Execution)Television Syntax: f5 => {
select_next_entry;
toggle_selection_down;
toggle_selection_down;
};TOML Equivalent: [keybindings]
f5 = ["select_next_entry", "toggle_selection_down", "toggle_selection_down"]4. Event BindingsTelevision Syntax: @load => reload_source;
@result => toggle_status_bar;
@selection-change => copy_entry_to_clipboard;
@one => select_and_exit;
@zero => quit;TOML Equivalent: [events]
load = "reload_source"
result = "toggle_status_bar"
selection-change = "copy_entry_to_clipboard"
one = "select_and_exit"
zero = "quit"5. Event Bindings with Action SequencesTelevision Syntax: @load => {
reload_source;
toggle_status_bar;
select_first_entry;
};TOML Equivalent: [events]
load = ["reload_source", "toggle_status_bar", "select_first_entry"]6. Channel-Specific BindingsTelevision Syntax: channel "files" {
f8 => toggle_preview;
f7 => copy_entry_to_clipboard;
@load => auto_preview_first;
}Note: this is for defining specific mappings from global side, if done from channel side then it's the normal syntax mentioned above TOML Equivalent (Option A - Nested Tables): [channels.files.keybindings]
f8 = "toggle_preview"
f7 = "copy_entry_to_clipboard"
[channels.files.events]
load = "auto_preview_first"TOML Equivalent (Option B - Inline Tables): [channels]
files = {
keybindings = { f8 = "toggle_preview", f7 = "copy_entry_to_clipboard" },
events = { load = "auto_preview_first" }
}7. Pattern-Based Bindings (for_channels)Note: Do we really need it? Television Syntax: for_channels("files") {
f1 => toggle_help;
f5 => reload_source;
}
for_channels("files", "dirs", "git_*") {
g => git_status;
r => reload_source;
}8. Parameterized ActionsTelevision Syntax: f7 => execute("custom_command");
f8 => switch_to_channel("files");TOML Equivalent (Option A - Inline Parameters): [keybindings]
f7 = "execute(custom_command)"
f8 = "switch_to_channel(files)"
f9 = "select(0,2)"TOML Equivalent (Option B - Structured Parameters): [keybindings]
f7 = { execute = "custom_command" }
f8 = { switch_to_channel = "files" }
f9 = { select = [0, 2] }TOML Equivalent (Option C - Named Parameters): [keybindings]
f7 = { execute = { commad = "custom_command" } }
f8 = { switch_to_channel = { channel = "files" } }
f9 = { select = { start = 0, end = 2, inclusive = true } }9. Unbinding (nil action)Television Syntax: esc => nil; // Unbind esc from any existing actionTOML Equivalent (Option A - nil action): [keybindings]
esc = false # toml doesn't have a nil/none value so we could use anything hereTOML Equivalent (Option B - explicit unbinding): [unbind]
keys = ["esc"]Complete Configuration Example# Global keybindings (base layer)
[keybindings]
esc = "quit"
ctrl-c = "quit"
enter = "confirm_selection"
down = "select_next_entry"
up = "select_prev_entry"
tab = "toggle_selection_down"
backtab = "toggle_selection_up"
ctrl-y = "copy_entry_to_clipboard"
ctrl-o = "toggle_preview"
ctrl-h = "toggle_help"
# Action sequences
f5 = ["select_next_entry", "toggle_selection_down", "toggle_selection_down"]
f6 = ["reload_source", "toggle_status_bar"]
# Event-driven bindings
[events]
load = "reload_source"
result = "toggle_status_bar"
selection-change = "copy_entry_to_clipboard"
one = ["toggle_section_down", "confirm_selection"]
zero = "quit"
# Channel-specific overrides
[channels.files.keybindings]
f8 = "toggle_preview"
f7 = "copy_entry_to_clipboard"
f1 = "toggle_selection_down"
[channels.files.events]
load = "toggle_help"
[channels.dirs.keybindings]
f5 = "reload_source"
enter = ["toggle_selection_down", "execute(something)"]EDIT: added full example |
Beta Was this translation helpful? Give feedback.







Uh oh!
There was an error while loading. Please reload this page.
-
Perhaps
televisioncould benefit from the possibility to trigger change(s) on the UI/source/matcher/etc, in response to an action (much likefzf --bind)@alexpasmantier what are your thoughts on this?
Beta Was this translation helpful? Give feedback.
All reactions