733 Commits

Author SHA1 Message Date
nick42d
922e951723
Implement Ord for Event and sub-types (#951) 2025-04-15 10:55:14 -07:00
Timon
36d95b26a2
0.29 (#984)
* 0.29
* deps upgrade
0.29
2025-04-05 17:21:04 +02:00
Johannes Agricola
7da7e31596
Add copying to clipboard using OSC52 (#974)
Many terminal emulators support copying text to clipboard using
ANSI OSC Ps; PT ST with Ps = 5 2, see
https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands

This enables copying even through SSH and terminal multiplexers.

Co-authored-by: Naseschwarz <naseschwarz@0x53a.de>
2025-04-05 16:38:59 +02:00
Wind
eb3be0fe1c
update rustix to 1.0 (#982) 2025-04-02 21:34:41 -07:00
Michael Davis
9824270d57
CI: Add missing continue-on-error annotation (#981) 2025-03-28 18:31:43 -07:00
gaesa
b6562fe5e3
refactor: use is_key_* helpers for consistency in key event methods (#980) 2025-03-25 01:14:34 -07:00
Flokkq
2d3f3f5636
fix: KeyModifiers Display impl (#979)
The KeyModifiers Display implementation incorrectly formatted modifier keys, causing the output to be concatenated without + separators. This is now corrected.
2025-03-22 15:41:25 -07:00
Johannes Agricola
69249c88fe
Run clippy on all features (#978)
Fixes lints and some doc comment formatting
Fixes a write() call which should be write_all()
Picked up by <https://rust-lang.github.io/rust-clippy/master/index.html#unused_io_amount>
2025-03-20 06:30:52 -07:00
Johannes Agricola
cb08b4db7f
Fix clippy lint (operator precedence) (#976) 2025-03-15 18:33:50 -07:00
Michael Davis
12f36ec316
Add a feature flag for derive_more impls (#970)
This adds a feature flag to allow opting out of the `derive_more`
dependency and derivations added in e063091. `derive_more` brings in
heavy proc macro dependencies and isn't crucial for the core functioning
of crossterm, so it should be possible for a crossterm dependent to opt
out of bringing in the transitive dependency.
2025-02-16 19:20:28 +01:00
Austin Schey
2c18768d2c
fix: fmt (#969) 2025-02-04 21:37:16 -08:00
Josh McKinney
e063091312
Add is_* and as_* methods to the event enums (#949)
* Add is_ and as_ methods to the event enums

Often application code only cares about a small subset of possible
events. These methods make it simpler to write code which checks whether
an event is a particular event type or converts events into the specific
type (returning an Option).

This can help simplify some nested match blocks. E.g.:

```rust
match event {
    Event::Key(key) if key.kind == KeyEventKind::Press => { ... }
}
```

becomes:

```rust
if let Some(key) = event.as_key_press() { ... }
```

Similar flexible methods are aded across all the event enums:

- `Event::is_focus_gained()`
- `Event::is_focus_lost()`
- `Event::is_key()`
- `Event::is_mouse()`
- `Event::is_paste()`
- `Event::is_resize()`
- `Event::is_key_press()`
- `Event::as_key_press() -> Option<&KeyEvent>`
- `MouseEventKind::is_*()`
- `MouseButton::is_*()`
- `KeyEventKind::is_*()`
- `KeyEvent::is_press()`
- `KeyEvent::is_release()`
- `KeyEvent::is_repeat()`
- `KeyCode::is_*()`
- `KeyCode::is_function_key(n)`
- `KeyCode::is_char(c)`
- `KeyCode::as_char() -> Option<char>`
- `KeyCode::is_media_key(media)`
- `KeyCode::is_modifier(modifier)`
- add is_key_release() and is_key_repeat() checks
- add as_key_event()
- rename as_key_press() to as_key_press_event()
- add as_key_repeat_event()
- add as_key_release_event()
- add as_mouse_event()
- add as_paste_event()
- more tests
- update event-match and key-display examples
2025-02-02 11:31:10 +01:00
Austin Schey
1bcfa9729c
Fix build failure with event-stream, rustix, and use-dev-tty (#955) 2025-02-02 11:15:45 +01:00
Hanggang Zhu
fe96fefd41
fix: event-read-char-line double read error & auto enter (#954) 2025-02-02 11:12:35 +01:00
Michael Davis
1e7622c1dc
Add query_keyboard_enhancement_flags to read enabled flags (#958)
This is mostly a refactor of `supports_keyboard_enhancement` and its
helper functions. We previously discarded the response to the `CSI ? u`
query but this returns the currently active flags. This response value
can be useful for a client to know which flags to emit to disable the
keyboard enhancement protocol or to know which flags a terminal supports
(after the client has pushed flags).
2025-02-02 11:04:35 +01:00
三咲雅 · Misaki Masa
6d6d3cb849
fix: Update rustix to fix the enable_raw_mode() error on WSL/Android (#926)
Fixes: #912
Co-authored-by: Josh McKinney <joshka@users.noreply.github.com>
2025-01-26 13:58:06 -08:00
rosew0od
e104a7cb40
Chanage Wikipedia SGR link to have the proper fragment identifier. (#959) 2024-12-16 21:40:29 -08:00
Josh McKinney
fc8f977938
Document feature flags in lib.rs (#947)
* Autoformat Cargo.toml

Uses VSCode Even Better TOML plugin for opinionated formatting

* Document feature flags

Use the document-features crate to automatically add documentation about the features to the crate documentation at the crate level.
2024-11-22 15:16:55 -08:00
maciek50322
56ee252fe1
fix windows panic on -1 size (#946) 2024-11-22 14:39:48 -08:00
Josh McKinney
31b3998d91
Fix warnings and clippy lints (#943)
* Move InternalEventFilter into tests mod

This is only used in test code, so should be defined there

* Remove winapi feature flag checks

These checks were impossible to trigger as there is no separate feature
flag for winapi and crossterm_winapi. The windows feature flag
automatically enables these dependencies.

* Fix clippy lints for byte char slices

https://rust-lang.github.io/rust-clippy/master/index.html\#byte_char_slices
2024-11-21 16:52:25 -08:00
Ken Micklas
45498314a5
Update tui-rs link to point to ratatui (#938) 2024-11-07 18:10:56 -08:00
linrongbin16
b056370038
feat(cursor): Derive standard traits for "SetCursorStyle" (#909) 2024-08-09 00:18:38 -07:00
TimonPost
492b764f9f 0.28.1 2024-08-01 20:33:26 +02:00
Timon
4712ff5619
Fix mio and signalhook broken build (#907)
* Upgrade to mio 1.0
2024-08-01 20:30:12 +02:00
Alexandre Bury
8d1f0cc603
Require rustix/process when use-dev-tty is enabled (#906) 2024-08-01 20:12:05 +02:00
Timon
5d50d8da62
Minor upgrade to crossterm 0.28 (#898) 0.28 2024-07-31 19:41:00 +02:00
rustco
25e14782e3
Fix some comments (#899) 2024-07-31 18:56:39 +02:00
Tim Straubinger
33b4e37223
Fix duplicate bit masks for caps lock and num lock (#863) 2024-06-16 15:04:33 +02:00
illiteratewriter
61ff5ae1ce
docs: update docs for focus change event (#784) (#864)
* docs: update docs for focus change event (#784)

* docs: update example to include execute command

- add space between links
2024-06-16 15:00:25 +02:00
Heath Stewart
080f06494a
Improve color detection across platforms (#885)
Fixes #882 by improving `style::available_color_count()`:
- Checks ANSI support on Windows.
- Uses the COLORTERM environment variable and falls back to the TERM environment variable.
- Supports "xterm-24bit" and "truecolor" values which return `u16::MAX`.
2024-06-16 14:58:31 +02:00
Josh McKinney
fe440284bf
Use rustix instead of libc (additive only approach) (#892)
* use rustix instead of libc

* make rustix the default feature

* bump msrv to 1.63.0

* fix remaining libc issues

- use rustix version of sigwinch signal
- add a lifetime to FileDesc and replace FileDesc::Static to
  FileDesc::Borrowed. This made it necessary to either add a lifetime to
  the libc version of FileDesc or replace all the callers with multiple
  paths (libc, rustix). Changing FileDesc was more straightforward.
  There are no usages of FileDesc found in any repo on github, so this
  change should be reasonably safe.

* add changelog entry for rustix / filedesc change
2024-06-16 14:56:13 +02:00
Austin Schey
be8cb8ce8e
fix: remove extra command (#894) 2024-06-16 14:44:34 +02:00
Josh McKinney
fce58c879a
fix: broken build issues (#888)
Co-authored-by: gwenn <gtreguier@gmail.com>
2024-05-05 18:47:20 +02:00
Rein Fernhout
6d20946dfe
Mark alacritty as supporting kitty protocol (#851) 2024-05-03 19:32:04 +02:00
Martin von Zweigbergk
6fde55416b
Remove unsafe and unnecessary size argument from FileDesc::read() (#821)
The `size` argument to `FileDesc::read()` is not checked against the
length of the buffer, so `libc::read()` could end up writing past the
buffer if we passed a size that's too large. However, we always pass
exactly the size of the buffer, so that doesn't happen. Let's just
remove the argument since it's not currently needed, thereby removing
the risk of bugs if the function is used incorrectly by future
callers.

This came up in review of `unsafe` Rust code at my company.
2024-05-03 19:30:15 +02:00
linrongbin16
f54e937a33
Add tested platforms to documentation (#872) 2024-05-03 19:26:10 +02:00
ken
2545954076
Fix cargo clippy warning and error (#877) 2024-05-03 19:23:50 +02:00
Josh McKinney
39ef1e42ba
Implement Display for KeyCode and KeyModifiers (#862)
Partially addresses #792
* Implement Display for KeyCode and KeyModifiers
* Add demo for Display implementation
2024-05-03 19:23:07 +02:00
Josh McKinney
7efe19da28
perf: speed up SetColors by ~15-25% (#879)
The SetColors command was executing SetForegroundColor and then
SetBackgroundColor, which writes 2 extra characters per cell compared to
writing both colors in one command. This resulted in about 15-25% more
FPS (19->24 fps) on a fullscreen (171x51) app that writes every cell
with a different foreground and background color, compared to separately
using the SetForegroundColor and SetBackgroundColor commands (iTerm2, M2
Macbook Pro).

The app is the colors_rgb example in Ratatui, which writes every cell
with a different foreground and background color in a loop. The
CrosstermBackend was changed to use SetColors instead of
SetForegroundColor and SetBackgroundColor.
2024-05-03 18:53:06 +02:00
breno
99fe255f33
Update README getting started snippets (#859)
Theres no Result trait in crossterm
2024-01-28 10:59:41 +01:00
Kier Davis
0935196d5a
Add functions to allow constructing Attributes in a const context (#817)
Previously, the only ways to construct new `Attributes` values were
`Attributes::default()` or `Attributes::from(_)`, neither of can be
made `const fn` due to limitations of these standard library traits.
2024-01-06 13:03:59 +01:00
Przemek Pawlas
94fdd586e6
(De)serialize Reset color (#824) 2024-01-06 13:02:38 +01:00
Stephen Hunt
cd1780c2d8
Capture double click mouse events (#826)
When double clicking on Windows, the crossterm_winapi emits the first
click with `EventFlags::PressOrRelease` and the second click with
`EventFlags::DoubleClick`. Previously this code explicitly ignored mouse
events with `EventFlags::DoubleClick` because "double click not
supported by unix terminals." This change captures the double click and
surfaces them as normal click events.
2024-01-06 13:01:07 +01:00
Charles German
6d6bed9c2c
Update Cargo.toml snippets (#811)
The snippets show version 0.26, but the latest version is 0.27
2024-01-06 12:54:40 +01:00
Dheepak Krishnamurthy
b565646f27
Fix typo in CHANGELOG.md (#816) 2024-01-06 12:54:15 +01:00
Dheepak Krishnamurthy
a2b0e6a537
Fix typo in BeginSynchronizedUpdate docstring (#833) 2024-01-06 12:53:45 +01:00
Valerii Petryniak
0914f2d91e
Update README.md: fix typo (#832) 2024-01-06 12:53:21 +01:00
javaLux
7ef45a6991
Add MacOs monterey to tested terminals (#846) 2024-01-06 12:52:53 +01:00
Pedro Mendes
544ac19c41
Remove redundant docs and broken anchor (#845) 2024-01-06 12:52:00 +01:00
jumbledFox
dc09c6a057
Fix minor formatting mistake (#852) 2024-01-06 12:50:50 +01:00