1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-27 02:25:28 +03:00

add canonicalize_pasted_newlines config option

refs: #1213
This commit is contained in:
Wez Furlong 2021-10-17 13:14:16 -07:00
parent 3b12aa1038
commit 24875004f6
6 changed files with 59 additions and 2 deletions

View File

@ -1237,9 +1237,16 @@ pub struct Config {
#[serde(default)]
pub audible_bell: AudibleBell,
#[serde(default = "default_canonicalize_pasted_newlines")]
pub canonicalize_pasted_newlines: bool,
}
impl_lua_conversion!(Config);
fn default_canonicalize_pasted_newlines() -> bool {
cfg!(windows)
}
fn default_mux_env_remove() -> Vec<String> {
vec![
"SSH_AUTH_SOCK".to_string(),

View File

@ -70,4 +70,8 @@ impl wezterm_term::TerminalConfiguration for TermConfig {
fn enable_kitty_graphics(&self) -> bool {
self.configuration().enable_kitty_graphics
}
fn canonicalize_pasted_newlines(&self) -> bool {
self.configuration().canonicalize_pasted_newlines
}
}

View File

@ -25,6 +25,7 @@ As features stabilize some brief notes about them will accumulate here.
* BSDish systems now support [toast notifications](https://github.com/wez/wezterm/issues/489)
* [wezterm.background_child_process](config/lua/wezterm/background_child_process.md) function to spawn a process without waiting.
* [mux_env_remove](config/lua/config/mux_env_remove.md) setting to control which environment variables should be cleared prior to spawning processes in the multiplexer server [#1225](https://github.com/wez/wezterm/issues/1225)
* [canonicalize_pasted_newlines](config/lua/config/canonicalize_pasted_newlines.md) option to help Windows users manage newlines in pastes [#1213](https://github.com/wez/wezterm/issues/1213)
#### Changed

View File

@ -0,0 +1,40 @@
# canonicalize_pasted_newlines
*Since: nightly builds only*
Controls whether pasted text will have newlines normalized to CRLF form.
In general wezterm tries to stick with unix line endings as the one-true
representation because using canonical CRLF can result in excess blank lines
during a paste operation.
On Windows we're in a bit of a frustrating situation: pasting into
Windows console programs requires CRLF otherwise there is no newline
at all, but when in WSL, pasting with CRLF gives excess blank lines.
By default, when `canonicalize_pasted_newlines` is not set in your
configuration, if wezterm is running as a native Windows application, then the
effective value of this setting will be `true`, otherwise it will be false.
The behavior of this setting is:
* If bracketed paste mode is enabled by the application, this configuration has no effect on the pasted text
* Otherwise, if `canonicalize_line_endings == true`, then the line endings will be converted to `CRLF` form
In practice, the default setting means that unix shells and vim will get the
unix newlines in their pastes (which is the UX most users will want) and
cmd.exe will get CRLF.
However, it is an imperfect world: some users take great pains to only run
unixy programs from their Windows wezterm, which means that they end up with
CRLFs in places where they don't want them. Those users will likely wish to
set their configuration like this:
```lua
return {
-- I only ever run unix programs, even on my Windows system, so I always
-- want my pastes to use unix newlines.
canonicalize_pasted_newlines = false,
}
```

View File

@ -69,6 +69,10 @@ pub trait TerminalConfiguration: std::fmt::Debug {
cfg!(windows)
}
fn canonicalize_pasted_newlines(&self) -> bool {
cfg!(windows)
}
fn alternate_buffer_wheel_scroll_speed(&self) -> u8 {
3
}

View File

@ -644,7 +644,7 @@ impl TerminalState {
// This is a bit horrible; in general we try to stick with unix line
// endings as the one-true representation because using canonical
// CRLF can result is excess blank lines during a paste operation.
// CRLF can result in excess blank lines during a paste operation.
// On Windows we're in a bit of a frustrating situation: pasting into
// Windows console programs requires CRLF otherwise there is no newline
// at all, but when in WSL, pasting with CRLF gives excess blank lines.
@ -657,7 +657,8 @@ impl TerminalState {
// In practice this means that unix shells and vim will get the
// unix newlines in their pastes (which is the UX I want) and
// cmd.exe will get CRLF.
let canonicalize_line_endings = cfg!(windows) && !self.bracketed_paste;
let canonicalize_line_endings =
self.config.canonicalize_pasted_newlines() && !self.bracketed_paste;
if canonicalize_line_endings {
// Convert (\r|\n) -> \r\n, but not if it is \r\n anyway.