103 Commits

Author SHA1 Message Date
Michael Davis
bb5d2853d2 Release v0.1.1 v0.1.1 2025-09-12 10:05:10 -04:00
Michael Davis
0968b8a2e7 Add a test case showing cursor reset CSI encoding 2025-09-12 10:01:04 -04:00
Michael Davis
121b9675e7 Only compile select2 on macos, otherwise compile poll2
select2 is only used on macOS so there's no need to compile it in
non-macOS builds. Originally it was compiled for all builds with the
allowed dead-code just to make development easier (i.e. get compiler
diagnostics without switching OSes).
2025-09-12 09:59:39 -04:00
Michael Zeller
baf02dc76c Skip compiling select2 on Illumos (#13) 2025-09-12 08:57:41 -05:00
Austin Schey
db1005914e feat: expose parser (#12) 2025-09-10 08:55:15 -05:00
Austin Schey
1bc39a720f fix: prevent subtraction with overflow when extended mouse coordinates are disabled (#11) 2025-09-02 09:12:39 -05:00
Michael Davis
dea8b0ba32 Release v0.1.0 v0.1.0 2025-08-31 11:24:04 -04:00
Michael Davis
d80232c098 Loosen requirement on windows-sys 2025-08-31 11:24:04 -04:00
Michael Davis
b3d5a12cf9 unix: Fall back to reading LINES/COLUMNS in Terminal::get_dimensions
The ioctl to get the window size may fail silently by returning zeroed
rows/columns which are nonsensical and unusable by terminal
applications. In this case Vim falls back to attempting to read the
LINES and COLUMNS environment variables, and then attempts to read
dimensions from the terminfo. That fallback can be done in the calling
application however.

Also see <https://github.com/helix-editor/helix/issues/14101#issuecomment-3149628173>
2025-08-31 10:27:29 -04:00
Austin Schey
5d82d07f17 fix: ensure try_read always reads at least once (#10) 2025-07-19 17:38:47 -05:00
mariocala
3f861342e0 fix: remove trailing semicolon from sgr attributes when chunking (#8)
Co-authored-by: Calamario <git@calamar.io>
2025-07-05 10:09:49 -04:00
Austin Schey
a302bf2b6d fix: check if stdout is a tty before writing to it (#7) 2025-05-18 08:43:09 -05:00
Austin Schey
b7f6c327a6 feat: add window pixel width and height (#6) 2025-05-15 12:16:40 -04:00
Michael Davis
07cc87ef7a Add a WindowSize struct for the terminal dimensions
See <d14e5c51c6 (r156782395)>.
The tuple can be confusing, especially since it's reversed compared to
crossterm.

Also <https://github.com/helix-editor/termina/issues/5#issuecomment-2869972748>

Co-authored-by: museun <museun@users.noreply.github.com>
2025-05-11 12:47:19 -04:00
Michael Davis
d14e5c51c6 Windows: Fix zero/one-based handling of window resize events
There was a mistake with the WindowResized event on Windows from some
code inherited from crossterm. Crossterm adds one to the dimensions
returned from a window resize event because it overwrites the dimensions
in the event with ones from `GetConsoleScreenBufferInfo` (zero-based).
The rows and columns in the event are already one-based.

This change also re-types the dimensions with the `OneBased` helper from
termwiz. The `OneBased` type is moved from the `escape` module to the
crate root.

Fixes #5.
2025-05-11 12:03:50 -04:00
Michael Davis
bd391b13fa Windows: Borrow stdin/stdout when detected as a TTY
This matches the same code in the Unix terminal module and produces
better behavior in some edge cases like running an application into
a pipe like `hx | echo`.
2025-05-11 12:03:29 -04:00
Michael Davis
8ae1d58a29 CI: Run clippy with default and all features enabled
Since `event-stream` is optional we need Clippy to check that code
separately.
2025-05-04 09:25:40 -04:00
Michael Davis
d34387ca09 Type-erase the filter closure in EventStream
Instead of the filter closure being a type parameter we can erase its
type with `Arc<dyn Fn...>`. This means that the filter is executed with
dynamic dispatch instead of static but I doubt that it makes a
noticeable/significant difference. Erasing the type makes `EventStream`
easier to store on another struct since it's a hassle to specify
concrete type parameters for closures.

Also `EventReader::poll` and `read` are updated to use more specific
`FnMut` closures for the sake of flexibility. This is effectively the
same since `FnMut` is a supertrait of `Fn` but it enables mutating the
env of the closure.

Closes #3
2025-05-04 09:24:20 -04:00
Michael Davis
36ce4accfe Expose the EventReader, make EventStream optional
We can gate EventStream behind a feature flag to make the futures-core
dependency optional. You may wish to roll your own event stream to avoid
futures and async. This change replaces `Terminal::event_stream` with
`Terminal::event_reader` and makes the `EventReader` type `pub` instead
of `pub(crate)`.

This change also removes the `DummyEventSource` since it is easy to
write that type in the consuming application.
2025-05-03 09:51:17 -04:00
Michael Davis
3cf5b6083e Chunk CSI attributes to fit conservative Ps limits
See <https://redirect.github.com/helix-editor/helix/pull/13307#issuecomment-2813435388>.
Some terminals' VT parsers have conservative limits for the number of
parameters they will accept, sometimes as low as 10. For compatibility
with these terminals we should chunk the combined SGR attributes to fit
that limit. This is added as an option on `SgrAttributes` so that it can
be customized and changed dynamically. (As opposed to a constant.)
2025-05-03 09:22:53 -04:00
Michael Davis
c51aaac0a1 Add Terminal::set_panic_hook 2025-04-14 16:37:00 -04:00
Michael Davis
587c15ed92 CI: Run on pushes to any branch 2025-04-14 09:47:04 -04:00
Michael Davis
e8c27fb57c windows: Skip keyboard up and zero bytes in the parser 2025-04-10 16:05:01 -04:00
Michael Davis
6f4efc7331 Use semicolon syntax for foreground/background true color 2025-04-10 16:05:00 -04:00
Michael Davis
e9513d0c8d examples: Poll for features response 2025-04-10 16:05:00 -04:00
Michael Davis
dd23328fd9 Hardcode CP_UTF8 constant
In my testing with these commands (PowerShell):

    > cargo clean
    > Measure-Command { cargo b --example event-read }

I see the time fall from 4s111ms to 3s845ms. It's not much but there's
really no reason to have this flag enabled for one constant.
2025-04-10 16:04:59 -04:00
Michael Davis
32f414c9e1 Remove Terminal::reset_mode
This was a footgun since it isn't an opposite to `enter_raw_mode`. We
want to reset the mode in Helix when suspending but that only works on
Unix and on Unix it's the same thing to use `enter_cooked_mode`. On
Windows during Drop we want to reset the code pages (encoding) as well
but the code pages are not set in `enter_raw_mode`, they're set during
`WindowsTerminal::new`. This change removes `reset_mode` and moves its
code into `Drop for WindowsTerminal`.
2025-04-10 12:32:48 -04:00
Michael Davis
e0d38d7449 minor: Use SIGWINCH constant from signal-hook instead of rustix
I didn't realize signal-hook also exported a constant for this. This
change shaves off a fair percentage of compile time since we drop the
dependency on rustix's `process` feature flag:

    $ cargo clean
    $ time cargo b --release --example event-read

before

    Executed in    2.41 secs    fish           external
       usr time    6.78 secs    0.20 millis    6.78 secs
       sys time    1.42 secs    1.08 millis    1.42 secs

after

    Executed in    2.04 secs    fish           external
       usr time    6.10 secs    410.00 micros  6.10 secs
       sys time    1.45 secs    811.00 micros  1.44 secs
2025-04-09 17:02:04 -04:00
Michael Davis
33066d7226 Clean up window-title example, use SetIconNameAndWindowTitle
decset/decreset macros only had one caller each. Since we're pushing and
popping the icon and window title we should set the icon and window
title.
2025-04-09 16:18:38 -04:00
Michael Davis
6a6bc32518 Add a CI workflow 2025-04-09 11:27:47 -04:00
Michael Davis
ee7c65776c Support title and window manipulation, add an example 2025-04-09 10:35:19 -04:00
Michael Davis
cdc5e334da docs: Clarify how popping Kitty keyboard flags works with the alt screen 2025-04-08 16:01:47 -04:00
Michael Davis
00086ec9d2 minor: Clean up event-read example comments and filter fn 2025-04-08 14:06:11 -04:00
Michael Davis
65643447f9 Include Crossterm & TermWiz licenses in the README 2025-04-08 12:27:28 -04:00
Michael Davis
bfc9fc55e7 Add SgrAttributes::is_empty, remove '0' from SGR reset v0.1.0-beta.1 2025-04-08 11:05:39 -04:00
Michael Davis
13a7d01f2d Add types for merging multiple SGR escapes into one
This new `SgrAttributes` type can contain all of the common `Sgr`
attributes together. It's like a `Vec<Sgr>` but flattened into a struct.
When displayed, all SGR updates are made at once. See the example in
the docs for the type: we can emit a change to set the foreground as
green and bold as 'CSI 32 ; 1 m' instead of two separate 'CSI 32 m' plus
'CSI 1 m' escapes. This is equivalent when writing exactly one SGR but
is a savings of two bytes (add one for ';', subtract three for CSI and
'm') per extra change made in the SGR.

A similar change in crossterm reportedly boosted FPS of an application
that sets a combined foreground+backgrouond SGR for every cell by
15-25%: <https://redirect.github.com/crossterm-rs/crossterm/pull/879>.
This type takes that change a step further and supports all SGR
attributes.
2025-04-08 10:41:20 -04:00
Michael Davis
cac0aea6c6 Add back Drop glue for terminal types
It's somewhat catastrophic to not reset console mode and code pages on
Windows - it seems to really mess up the terminal and can cause a crash
- so I think it's fine to reset mode automatically on drop. While we're
at it we might as well flush the writer buffers.
2025-04-08 09:48:24 -04:00
Michael Davis
6c129f5b45 Fix cargo docs warnings 2025-04-07 18:35:43 -04:00
Michael Davis
9ed3ffcd69 Clean up the event-read example with decset/decreset macros 2025-04-07 18:05:04 -04:00
Michael Davis
2f1f1eff23 Set the version at v0.1.0-beta.1 for an initial release 2025-04-07 18:05:04 -04:00
Michael Davis
2c87f3b582 Rewrite README focusing on crossterm, termwiz, credit and licensing 2025-04-07 18:05:04 -04:00
Michael Davis
40d6558064 Add credit comments pointing back to original code 2025-04-07 16:02:59 -04:00
Michael Davis
86a3be0a47 Document reading VT sequences on Windows 2025-04-07 14:34:43 -04:00
Michael Davis
fca131f25c examples: Call Terminal::reset_mode instead of relying on Drop
At some point recently I got rid of the Drop stuff. We need to reset the
mode or else Windows powershell crashes for me when trying to claim
CONIN$ twice. (Run an example before this commit and then run regular
`hx`).
2025-04-07 14:29:21 -04:00
Michael Davis
c2333d3df5 examples: Match all synchronized output events 2025-04-07 14:29:21 -04:00
Michael Davis
b562dc4dc9 Fix compilation errors on Windows 2025-04-07 14:29:20 -04:00
Michael Davis
7c9ff64a0a minor: Remove TODO comment in Unix terminal 2025-04-07 12:29:50 -04:00
Michael Davis
93a4104699 Fold Contour theme mode VT extension into Csi::Mode 2025-04-07 12:22:47 -04:00
Michael Davis
6fc32c81d1 Add DECRQSS/DECRPSS for cursor style
Testing manually this doesn't seem to be well supported...
2025-04-07 11:43:08 -04:00
Michael Davis
659a993859 Add a dummy event stream type for testing 2025-04-07 11:11:26 -04:00