Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions README.md

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This got reformatted by markdown lint. I usually use 100 char lines and align tables. Hope that's ok here. It generally edits easier that way. (Easier diffs in github etc.). Happy to revert that part as I know it's fairly subjective choice.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah I'd prefer to keep the style of the README mostly unchanged. I like to avoid hard wrapping in markdown. Making the table slimmer seems alright though, it's very wide right now. Maybe we can say "terminal dependent" and have a footnote or cross/star symbol that says that it depends on Kitty keyboard support below the table.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 05b5fe7

Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,22 @@ This means there is no single answer for which protocol to use - it depends on y

See feature comparison below.

| | VTE Mode | Legacy Console Mode |
| ------------------------------------------------------------ | --------------------------------------------------------- | ------------------- |
| **Kitty Keyboard Protocol** | ✓ | ✕ |
| **Extended key events** | terminal-dependent (must support Kitty Keyboard Protocol) | ✓ |
| **Bracketed paste** | ✓ | ✕ |
| **[AltGr](https://en.wikipedia.org/wiki/AltGr_key) Support** | ✓ | ✕ |
| | VTE Mode | Legacy Console Mode |
| --------------------------- | ------------------- | ------------------- |
| **Kitty Keyboard Protocol** | ✓ | ✕ |
| **Extended key events** | terminal-dependent* | ✓ |
| **Bracketed paste** | ✓ | ✕ |
| **[AltGr] Support** | ✓ | ✕ |

* VTE mode depends on Kitty Keyboard Protocol support for extended key events.

[AltGr]: https://en.wikipedia.org/wiki/AltGr_key

The legacy input reader can be used by enabling the `windows-legacy` feature. See the `event-read` example for usage.

## Credit

Termina contains significant code sourced and/or modified from other projects, especially Crossterm and TermWiz. See "CREDIT" comments in the source for details on what was copied and what modifications were made. Since all copied code is licensed under MIT, Termina is offered under the MIT license as well at your option.
Termina contains significant code sourced and/or modified from other projects, especially Crossterm and TermWiz. Credits for various implementations are marked in implementation notes sections. Since all copied code is licensed under MIT, Termina is offered under the MIT license as well at your option.

<details><summary>Crossterm license...</summary>

Expand Down
63 changes: 58 additions & 5 deletions src/escape.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,70 @@
//! ANSI escape sequences.

// CREDIT: this tree of modules is mostly yanked from the equivalents in TermWiz with some
// stylistic edits and additions/subtractions of some escape sequences.
//! Typed ANSI escape-sequence helpers.
//!
//! Termina models Control Sequence Introducer (CSI), Device Control String (DCS), and Operating
//! System Command (OSC) sequences it knows how to emit so callers can compose terminal control
//! payloads through [`Display`] instead of hand-written byte strings.
//!
//! # Examples
//!
//! ```
//! use termina::{
//! escape::{
//! csi::{Csi, Cursor},
//! CSI,
//! },
//! OneBased,
//! };
//!
//! let cursor_home = Csi::Cursor(Cursor::Position {
//! line: OneBased::new(1).unwrap(),
//! col: OneBased::new(1).unwrap(),
//! });
//!
//! assert_eq!(cursor_home.to_string(), format!("{CSI}1;1H"));
//! ```
//!
//! # Implementation Notes
//!
//! This module tree is adapted from [termwiz escape helpers]. It was originally yanked from TermWiz
//! equivalents and then trimmed into the set of escape sequences Termina needs. Most differences
//! are stylistic edits plus additions and subtractions in the modeled sequence set.
//!
//! [termwiz escape helpers]: https://docs.rs/termwiz/latest/termwiz/escape/index.html
//! [`Display`]: std::fmt::Display

pub mod csi;
pub mod dcs;
pub mod osc;

// Originally yanked from <https://github.com/wezterm/wezterm/blob/a87358516004a652ad840bc1661bdf65ffc89b43/term/src/lib.rs#L131-L135>
/// Control Sequence Introducer (`ESC [`), the prefix for parameterized terminal control functions.
///
/// CSI sequences carry numeric parameters and a final byte. Termina models the supported CSI
/// families in [`csi::Csi`].
pub const CSI: &str = "\x1b[";

/// Operating System Command introducer (`ESC ]`), used for terminal integration commands.
///
/// OSC sequences are commonly used for window titles, clipboard integration, and color queries.
/// Termina models the supported commands in [`osc::Osc`].
pub const OSC: &str = "\x1b]";

/// String Terminator (`ESC \`), used to end OSC and DCS string controls.
///
/// Most modern terminal string controls may also be terminated by [`BEL`], but Termina emits the
/// explicit string terminator form for the sequences it formats.
pub const ST: &str = "\x1b\\";

/// Single Shift 3 (`ESC O`), the prefix used by SS3 key sequences.
///
/// Application-keypad and function-key encodings commonly use this prefix instead of [`CSI`].
pub const SS3: &str = "\x1bO";

/// Device Control String introducer (`ESC P`), used for structured terminal queries.
///
/// Termina models the supported request and response forms in [`dcs::Dcs`].
pub const DCS: &str = "\x1bP";

/// Bell control character (`BEL`, `0x07`).
///
/// BEL can ring the terminal bell and is also accepted by many terminals as an OSC terminator.
pub const BEL: &str = "\x07";
Loading
Loading