Skip to content

Commit

Permalink
Add SCP control support
Browse files Browse the repository at this point in the history
Modern usage of this control function comes from the BiDi draft
proposal:

https://terminal-wg.pages.freedesktop.org/bidi/recommendation/escape-sequences.html

The draft slightly extends the definition in ECMA-48.

Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
  • Loading branch information
MoSal authored Apr 1, 2024
1 parent ed51aa1 commit a971e86
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/ansi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,9 @@ pub trait Handler {
///
/// The output is of form `CSI > 4 ; mode m`.
fn report_modify_other_keys(&mut self) {}

// Set SCP control.
fn set_scp(&mut self, _char_path: ScpCharPath, _update_mode: ScpUpdateMode) {}
}

bitflags! {
Expand Down Expand Up @@ -1195,6 +1198,32 @@ impl StandardCharset {
}
}

/// SCP control's first parameter which determines character path.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ScpCharPath {
/// SCP's first parameter value of 0. Behavior is implementation defined.
Default,
/// SCP's first parameter value of 1 which sets character path to LEFT-TO-RIGHT.
LTR,
/// SCP's first parameter value of 2 which sets character path to RIGHT-TO-LEFT.
RTL,
}

/// SCP control's second parameter which determines update mode/direction between components.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ScpUpdateMode {
/// SCP's second parameter value of 0 (the default). Implementation dependant update.
ImplementationDependant,
/// SCP's second parameter value of 1.
///
/// Reflect data component changes in the presentation component.
DataToPresentation,
/// SCP's second parameter value of 2.
///
/// Reflect presentation component changes in the data component.
PresentationToData,
}

impl<'a, H, T> crate::Perform for Performer<'a, H, T>
where
H: Handler + 'a,
Expand Down Expand Up @@ -1551,6 +1580,30 @@ where

handler.clear_line(mode);
},
('k', [b' ']) => {
// SCP control.
let char_path = match next_param_or(0) {
0 => ScpCharPath::Default,
1 => ScpCharPath::LTR,
2 => ScpCharPath::RTL,
_ => {
unhandled!();
return;
},
};

let update_mode = match next_param_or(0) {
0 => ScpUpdateMode::ImplementationDependant,
1 => ScpUpdateMode::DataToPresentation,
2 => ScpUpdateMode::PresentationToData,
_ => {
unhandled!();
return;
},
};

handler.set_scp(char_path, update_mode);
},
('L', []) => handler.insert_blank_lines(next_param_or(1) as usize),
('l', []) => {
for param in params_iter.map(|param| param[0]) {
Expand Down

0 comments on commit a971e86

Please sign in to comment.