Cleaner modifier calculation
This commit is contained in:
parent
44424c0108
commit
e5692cd902
1 changed files with 23 additions and 37 deletions
|
|
@ -1077,49 +1077,35 @@ impl operation::Focusable for State {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
2 | Shift
|
shift 0b1 (1)
|
||||||
3 | Alt
|
alt 0b10 (2)
|
||||||
4 | Shift + Alt
|
ctrl 0b100 (4)
|
||||||
5 | Control
|
super 0b1000 (8)
|
||||||
6 | Shift + Control
|
hyper 0b10000 (16)
|
||||||
7 | Alt + Control
|
meta 0b100000 (32)
|
||||||
8 | Shift + Alt + Control
|
caps_lock 0b1000000 (64)
|
||||||
9 | Meta
|
num_lock 0b10000000 (128)
|
||||||
10 | Meta + Shift
|
|
||||||
11 | Meta + Alt
|
|
||||||
12 | Meta + Alt + Shift
|
|
||||||
13 | Meta + Ctrl
|
|
||||||
14 | Meta + Ctrl + Shift
|
|
||||||
15 | Meta + Ctrl + Alt
|
|
||||||
16 | Meta + Ctrl + Alt + Shift
|
|
||||||
*/
|
*/
|
||||||
fn calculate_modifier_number(state: &mut State) -> u8 {
|
fn calculate_modifier_number(state: &mut State) -> u8 {
|
||||||
match (
|
let mut mod_no = 0;
|
||||||
state.modifiers.control(),
|
if state.modifiers.shift() {
|
||||||
state.modifiers.alt(),
|
mod_no |= 1;
|
||||||
state.modifiers.shift(),
|
|
||||||
) {
|
|
||||||
// 8 | Shift + Alt + Control
|
|
||||||
(true, true, true) => 8,
|
|
||||||
// 7 | Alt + Control
|
|
||||||
(true, true, false) => 7,
|
|
||||||
// 6 | Shift + Control
|
|
||||||
(true, false, true) => 6,
|
|
||||||
// 5 | Control
|
|
||||||
(true, false, false) => 5,
|
|
||||||
// 4 | Shift + Alt
|
|
||||||
(false, true, true) => 4,
|
|
||||||
// 3 | Alt
|
|
||||||
(false, true, false) => 3,
|
|
||||||
(false, false, true) => 2,
|
|
||||||
// 2 | Shift
|
|
||||||
(false, false, false) => 0,
|
|
||||||
}
|
}
|
||||||
|
if state.modifiers.alt() {
|
||||||
|
mod_no |= 2;
|
||||||
|
}
|
||||||
|
if state.modifiers.control() {
|
||||||
|
mod_no |= 4;
|
||||||
|
}
|
||||||
|
if state.modifiers.logo() {
|
||||||
|
mod_no |= 8;
|
||||||
|
}
|
||||||
|
mod_no + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn csi(code: &str, modifiers: u8) -> Option<Vec<u8>> {
|
fn csi(code: &str, modifiers: u8) -> Option<Vec<u8>> {
|
||||||
if modifiers == 0 {
|
if modifiers == 1 {
|
||||||
Some(format!("\x1B[{}~", code).as_bytes().to_vec())
|
Some(format!("\x1B[{}~", code).as_bytes().to_vec())
|
||||||
} else {
|
} else {
|
||||||
Some(format!("\x1B[{};{}~", code, modifiers).as_bytes().to_vec())
|
Some(format!("\x1B[{};{}~", code, modifiers).as_bytes().to_vec())
|
||||||
|
|
@ -1128,7 +1114,7 @@ fn csi(code: &str, modifiers: u8) -> Option<Vec<u8>> {
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn ss3(code: &str, modifiers: u8) -> Option<Vec<u8>> {
|
fn ss3(code: &str, modifiers: u8) -> Option<Vec<u8>> {
|
||||||
if modifiers == 0 {
|
if modifiers == 1 {
|
||||||
Some(format!("\x1B\x4F{}", code).as_bytes().to_vec())
|
Some(format!("\x1B\x4F{}", code).as_bytes().to_vec())
|
||||||
} else {
|
} else {
|
||||||
Some(format!("\x1B[1;{}{}", modifiers, code).as_bytes().to_vec())
|
Some(format!("\x1B[1;{}{}", modifiers, code).as_bytes().to_vec())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue