# terminal: Match trait bounds with terminal input \(\#31441\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/8ab7d44d514e904df743dfe50be7bba725dc67ae)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 8ab7d44d514e904df743dfe50be7bba725dc67ae

Requested commit: 8ab7d44d514e904df743dfe50be7bba725dc67ae

Commit: 8ab7d44d514e904df743dfe50be7bba725dc67ae

Tree: 286bc86900286d6ce4eaf383ccdadcb77a561796

Author: tidely

Committer: GitHub

## Message

````
terminal: Match trait bounds with terminal input (#31441)

The core change here is the following:

```rust
fn write_to_pty(&self, input: impl Into<Vec<u8>>);

// into
fn write_to_pty(&self, input: impl Into<Cow<'static, [u8]>>);
```

This matches the trait bounds that's used by the Alacritty crate. We are
now allowed to effectively pass `&'static str` instead of always needing
a `String`.

The main benefit comes from making the `to_esc_str` function return a
`Cow<'static, str>` instead of `String`. We save an allocation in the
following instances:

- When the user presses any special key that isn't alphanumerical (in
the terminal)
- When the uses presses any key while a modifier is active (in the
terminal)
- When focusing/un-focusing the terminal
- When completing or undoing a terminal transaction
- When starting a terminal assist

This basically saves us an allocation on **every key** press in the
terminal.

NOTE: This same optimization can be done for **nearly all** keypresses
in the entirety of Zed by changing the signature of the `Keystroke`
struct in gpui. If the Zed team is interested in a PR for it, let me
know.

Release Notes:

- N/A
````

## Parents

- [56d4c0af9fb591aa2db5ecf39143d23b9465dd14](https://git.cafe/gitcafe/zed/commit/56d4c0af9fb591aa2db5ecf39143d23b9465dd14?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/8ab7d44d514e904df743dfe50be7bba725dc67ae?format=markdown)
