Alexandre Pasmantier a6a73c5bb3
refactor(shell): improve shell integration configuration syntax (#334)
Before:
```toml
[shell_integration.commands]
# Add your commands here. Each key is a command that will trigger tv with the
# corresponding channel as value.
# Example: say you want the following prompts to trigger the following channels
# when pressing <CTRL-T>:
#          `git checkout` should trigger the `git-branches` channel
#          `ls`           should trigger the `dirs` channel
#          `cat`          should trigger the `files` channel
#
# You would add the following to your configuration file:
# ```
# [shell_integration.commands]
# "git checkout" = "git-branch"
# "ls" = "dirs"
# "cat" = "files"
# ```

# environment variables
"export" = "env"
"unset" = "env"

# dirs channel
"cd" = "dirs"
"ls" = "dirs"
"rmdir" = "dirs"

# files channel
"cat" = "files"
"less" = "files"
"head" = "files"
"tail" = "files"
"vim" = "files"
"bat" = "files"

# git-diff channel
"git add" = "git-diff"

# git-branch channel
"git checkout" = "git-branch"
"git branch -d" = "git-branch"

# docker-images channel
"docker run" = "docker-images"

# gitrepos channel
"nvim" = "git-repos"

```

After

```toml
[shell_integration.channel_triggers]
# Add your channel triggers here. Each key is a channel that will be triggered
# by the corresponding commands.
# Example: say you want the following commands to trigger the following channels
# when pressing <CTRL-T>:
#          `git checkout`  should trigger the `git-branches` channel
#          `ls`            should trigger the `dirs` channel
#          `cat` and `cp`  should trigger the `files` channel
#
# You would add the following to your configuration file:
# ```
# [shell_integration.channel_triggers]
# "git-branches" = ["git checkout"]
# "dirs" = ["ls"]
# "files" = ["cat", "cp"]
# ```
"env" = ["export", "unset"]
"dirs" = ["cd", "ls", "rmdir"]
"files" = ["cat", "less", "head", "tail", "vim", "bat"]
"git-diff" = ["git add"]
"git-branch" = ["git checkout", "git branch -d"]
"docker-images" = ["docker run"]
"git-repos" = ["nvim"]
```
2025-02-03 00:03:09 +01:00

62 lines
2.2 KiB
Rust

use criterion::{black_box, Criterion};
use ratatui::backend::TestBackend;
use ratatui::layout::Rect;
use ratatui::Terminal;
use std::path::PathBuf;
use television::action::Action;
use television::channels::OnAir;
use television::channels::{files::Channel, TelevisionChannel};
use television::config::{Config, ConfigEnv};
use television::television::Television;
use tokio::runtime::Runtime;
fn draw(c: &mut Criterion) {
let width = 250;
let height = 80;
let rt = Runtime::new().unwrap();
c.bench_function("draw", |b| {
b.to_async(&rt).iter_batched(
// FIXME: this is kind of hacky
|| {
let config = Config::new(&ConfigEnv::init().unwrap()).unwrap();
let backend = TestBackend::new(width, height);
let terminal = Terminal::new(backend).unwrap();
let (tx, _) = tokio::sync::mpsc::unbounded_channel();
let mut channel =
TelevisionChannel::Files(Channel::new(vec![
PathBuf::from("."),
]));
channel.find("television");
// Wait for the channel to finish loading
let mut tv = Television::new(tx, channel, config, None);
for _ in 0..5 {
// tick the matcher
let _ = tv.channel.results(10, 0);
std::thread::sleep(std::time::Duration::from_millis(10));
}
tv.select_next_entry(10);
let _ = tv.update_preview_state(
&tv.get_selected_entry(None).unwrap(),
);
tv.update(&Action::Tick).unwrap();
(tv, terminal)
},
// Measurement
|(tv, mut terminal)| async move {
television::draw::draw(
black_box(&tv.dump_context()),
black_box(&mut terminal.get_frame()),
black_box(Rect::new(0, 0, width, height)),
)
.unwrap();
},
criterion::BatchSize::SmallInput,
);
});
}
criterion::criterion_group!(benches, draw);
criterion::criterion_main!(benches);