Skip to content

Commit

Permalink
Respond to DECRQM 2027 - grapheme clustering
Browse files Browse the repository at this point in the history
closes: #4320
  • Loading branch information
wez committed Sep 20, 2023
1 parent bf545f1 commit 33e727b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
31 changes: 31 additions & 0 deletions term/src/terminalstate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,22 @@ impl TerminalState {
}
}

/// Indicates that mode is permanently enabled
fn decqrm_response_permanent(&mut self, mode: Mode) {
let (is_dec, number) = match &mode {
Mode::QueryDecPrivateMode(DecPrivateMode::Code(code)) => (true, code.to_u16().unwrap()),
Mode::QueryDecPrivateMode(DecPrivateMode::Unspecified(code)) => (true, *code),
Mode::QueryMode(TerminalMode::Code(code)) => (false, code.to_u16().unwrap()),
Mode::QueryMode(TerminalMode::Unspecified(code)) => (false, *code),
_ => unreachable!(),
};

let prefix = if is_dec { "?" } else { "" };

write!(self.writer, "\x1b[{prefix}{number};3$y").ok();
self.writer.flush().ok();
}

fn decqrm_response(&mut self, mode: Mode, mut recognized: bool, enabled: bool) {
let (is_dec, number) = match &mode {
Mode::QueryDecPrivateMode(DecPrivateMode::Code(code)) => (true, code.to_u16().unwrap()),
Expand Down Expand Up @@ -1449,6 +1465,21 @@ impl TerminalState {
self.decqrm_response(mode, true, self.left_and_right_margin_mode);
}

Mode::SetDecPrivateMode(DecPrivateMode::Code(
DecPrivateModeCode::GraphemeClustering,
))
| Mode::ResetDecPrivateMode(DecPrivateMode::Code(
DecPrivateModeCode::GraphemeClustering,
)) => {
// Permanently enabled
}

Mode::QueryDecPrivateMode(DecPrivateMode::Code(
DecPrivateModeCode::GraphemeClustering,
)) => {
self.decqrm_response_permanent(mode);
}

Mode::SetDecPrivateMode(DecPrivateMode::Code(DecPrivateModeCode::SaveCursor)) => {
self.dec_save_cursor();
}
Expand Down
5 changes: 5 additions & 0 deletions termwiz/src/escape/csi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,11 @@ pub enum DecPrivateModeCode {
EnableAlternateScreen = 47,
OptEnableAlternateScreen = 1047,
BracketedPaste = 2004,

/// <https://github.com/contour-terminal/terminal-unicode-core/>
/// Grapheme clustering mode
GraphemeClustering = 2027,

/// Applies to sixel and regis modes
UsePrivateColorRegistersForEachGraphic = 1070,

Expand Down

0 comments on commit 33e727b

Please sign in to comment.