Skip to content

Commit

Permalink
Add clipboard provider configuration (#10839)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlfGalf authored Nov 20, 2024
1 parent b6e555a commit 68ee876
Show file tree
Hide file tree
Showing 6 changed files with 488 additions and 359 deletions.
24 changes: 24 additions & 0 deletions book/src/editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,30 @@
| `indent-heuristic` | How the indentation for a newly inserted line is computed: `simple` just copies the indentation level from the previous line, `tree-sitter` computes the indentation based on the syntax tree and `hybrid` combines both approaches. If the chosen heuristic is not available, a different one will be used as a fallback (the fallback order being `hybrid` -> `tree-sitter` -> `simple`). | `hybrid`
| `jump-label-alphabet` | The characters that are used to generate two character jump labels. Characters at the start of the alphabet are used first. | `"abcdefghijklmnopqrstuvwxyz"`
| `end-of-line-diagnostics` | Minimum severity of diagnostics to render at the end of the line. Set to `disable` to disable entirely. Refer to the setting about `inline-diagnostics` for more details | "disable"
| `clipboard-provider` | Which API to use for clipboard interaction. One of `pasteboard` (MacOS), `wayland`, `x-clip`, `x-sel`, `win-32-yank`, `termux`, `tmux`, `windows`, `termcode`, `none`, or a custom command set. | Platform and environment specific. |

### `[editor.clipboard-provider]` Section

Helix can be configured wither to use a builtin clipboard configuration or to use
a provided command.

For instance, setting it to use OSC 52 termcodes, the configuration would be:
```toml
[editor]
clipboard-provider = "termcode"
```

Alternatively, Helix can be configured to use arbitary commands for clipboard integration:

```toml
[editor.clipboard-provider.custom]
yank = { command = "cat", args = ["test.txt"] }
paste = { command = "tee", args = ["test.txt"] }
primary-yank = { command = "cat", args = ["test-primary.txt"] } # optional
primary-paste = { command = "tee", args = ["test-primary.txt"] } # optional
```

For custom commands the contents of the yank/paste is communicated over stdin/stdout.

### `[editor.statusline]` Section

Expand Down
2 changes: 1 addition & 1 deletion helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ fn show_clipboard_provider(
}

cx.editor
.set_status(cx.editor.registers.clipboard_provider_name().to_string());
.set_status(cx.editor.registers.clipboard_provider_name());
Ok(())
}

Expand Down
19 changes: 14 additions & 5 deletions helix-term/src/health.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::config::{Config, ConfigLoadError};
use crossterm::{
style::{Color, Print, Stylize},
tty::IsTty,
};
use helix_core::config::{default_lang_config, user_lang_config};
use helix_loader::grammar::load_runtime_file;
use helix_view::clipboard::get_clipboard_provider;
use std::io::Write;

#[derive(Copy, Clone)]
Expand Down Expand Up @@ -53,7 +53,6 @@ pub fn general() -> std::io::Result<()> {
let lang_file = helix_loader::lang_config_file();
let log_file = helix_loader::log_file();
let rt_dirs = helix_loader::runtime_dirs();
let clipboard_provider = get_clipboard_provider();

if config_file.exists() {
writeln!(stdout, "Config file: {}", config_file.display())?;
Expand Down Expand Up @@ -92,7 +91,6 @@ pub fn general() -> std::io::Result<()> {
writeln!(stdout, "{}", msg.yellow())?;
}
}
writeln!(stdout, "Clipboard provider: {}", clipboard_provider.name())?;

Ok(())
}
Expand All @@ -101,8 +99,19 @@ pub fn clipboard() -> std::io::Result<()> {
let stdout = std::io::stdout();
let mut stdout = stdout.lock();

let board = get_clipboard_provider();
match board.name().as_ref() {
let config = match Config::load_default() {
Ok(config) => config,
Err(ConfigLoadError::Error(err)) if err.kind() == std::io::ErrorKind::NotFound => {
Config::default()
}
Err(err) => {
writeln!(stdout, "{}", "Configuration file malformed".red())?;
writeln!(stdout, "{}", err)?;
return Ok(());
}
};

match config.editor.clipboard_provider.name().as_ref() {
"none" => {
writeln!(
stdout,
Expand Down
Loading

0 comments on commit 68ee876

Please sign in to comment.