Remove 2 suffix for collab, rope, settings, menu
Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
parent
177e3028a9
commit
0cf65223ce
234 changed files with 3765 additions and 42229 deletions
|
@ -1,130 +1,12 @@
|
|||
use alacritty_terminal::{ansi::Color as AnsiColor, term::color::Rgb as AlacRgb};
|
||||
use gpui::color::Color;
|
||||
use theme::TerminalStyle;
|
||||
use alacritty_terminal::term::color::Rgb as AlacRgb;
|
||||
|
||||
///Converts a 2, 8, or 24 bit color ANSI color to the GPUI equivalent
|
||||
pub fn convert_color(alac_color: &AnsiColor, style: &TerminalStyle) -> Color {
|
||||
match alac_color {
|
||||
//Named and theme defined colors
|
||||
alacritty_terminal::ansi::Color::Named(n) => match n {
|
||||
alacritty_terminal::ansi::NamedColor::Black => style.black,
|
||||
alacritty_terminal::ansi::NamedColor::Red => style.red,
|
||||
alacritty_terminal::ansi::NamedColor::Green => style.green,
|
||||
alacritty_terminal::ansi::NamedColor::Yellow => style.yellow,
|
||||
alacritty_terminal::ansi::NamedColor::Blue => style.blue,
|
||||
alacritty_terminal::ansi::NamedColor::Magenta => style.magenta,
|
||||
alacritty_terminal::ansi::NamedColor::Cyan => style.cyan,
|
||||
alacritty_terminal::ansi::NamedColor::White => style.white,
|
||||
alacritty_terminal::ansi::NamedColor::BrightBlack => style.bright_black,
|
||||
alacritty_terminal::ansi::NamedColor::BrightRed => style.bright_red,
|
||||
alacritty_terminal::ansi::NamedColor::BrightGreen => style.bright_green,
|
||||
alacritty_terminal::ansi::NamedColor::BrightYellow => style.bright_yellow,
|
||||
alacritty_terminal::ansi::NamedColor::BrightBlue => style.bright_blue,
|
||||
alacritty_terminal::ansi::NamedColor::BrightMagenta => style.bright_magenta,
|
||||
alacritty_terminal::ansi::NamedColor::BrightCyan => style.bright_cyan,
|
||||
alacritty_terminal::ansi::NamedColor::BrightWhite => style.bright_white,
|
||||
alacritty_terminal::ansi::NamedColor::Foreground => style.foreground,
|
||||
alacritty_terminal::ansi::NamedColor::Background => style.background,
|
||||
alacritty_terminal::ansi::NamedColor::Cursor => style.cursor,
|
||||
alacritty_terminal::ansi::NamedColor::DimBlack => style.dim_black,
|
||||
alacritty_terminal::ansi::NamedColor::DimRed => style.dim_red,
|
||||
alacritty_terminal::ansi::NamedColor::DimGreen => style.dim_green,
|
||||
alacritty_terminal::ansi::NamedColor::DimYellow => style.dim_yellow,
|
||||
alacritty_terminal::ansi::NamedColor::DimBlue => style.dim_blue,
|
||||
alacritty_terminal::ansi::NamedColor::DimMagenta => style.dim_magenta,
|
||||
alacritty_terminal::ansi::NamedColor::DimCyan => style.dim_cyan,
|
||||
alacritty_terminal::ansi::NamedColor::DimWhite => style.dim_white,
|
||||
alacritty_terminal::ansi::NamedColor::BrightForeground => style.bright_foreground,
|
||||
alacritty_terminal::ansi::NamedColor::DimForeground => style.dim_foreground,
|
||||
},
|
||||
//'True' colors
|
||||
alacritty_terminal::ansi::Color::Spec(rgb) => Color::new(rgb.r, rgb.g, rgb.b, u8::MAX),
|
||||
//8 bit, indexed colors
|
||||
alacritty_terminal::ansi::Color::Indexed(i) => get_color_at_index(&(*i as usize), style),
|
||||
}
|
||||
}
|
||||
|
||||
///Converts an 8 bit ANSI color to it's GPUI equivalent.
|
||||
///Accepts usize for compatibility with the alacritty::Colors interface,
|
||||
///Other than that use case, should only be called with values in the [0,255] range
|
||||
pub fn get_color_at_index(index: &usize, style: &TerminalStyle) -> Color {
|
||||
match index {
|
||||
//0-15 are the same as the named colors above
|
||||
0 => style.black,
|
||||
1 => style.red,
|
||||
2 => style.green,
|
||||
3 => style.yellow,
|
||||
4 => style.blue,
|
||||
5 => style.magenta,
|
||||
6 => style.cyan,
|
||||
7 => style.white,
|
||||
8 => style.bright_black,
|
||||
9 => style.bright_red,
|
||||
10 => style.bright_green,
|
||||
11 => style.bright_yellow,
|
||||
12 => style.bright_blue,
|
||||
13 => style.bright_magenta,
|
||||
14 => style.bright_cyan,
|
||||
15 => style.bright_white,
|
||||
//16-231 are mapped to their RGB colors on a 0-5 range per channel
|
||||
16..=231 => {
|
||||
let (r, g, b) = rgb_for_index(&(*index as u8)); //Split the index into it's ANSI-RGB components
|
||||
let step = (u8::MAX as f32 / 5.).floor() as u8; //Split the RGB range into 5 chunks, with floor so no overflow
|
||||
Color::new(r * step, g * step, b * step, u8::MAX) //Map the ANSI-RGB components to an RGB color
|
||||
}
|
||||
//232-255 are a 24 step grayscale from black to white
|
||||
232..=255 => {
|
||||
let i = *index as u8 - 232; //Align index to 0..24
|
||||
let step = (u8::MAX as f32 / 24.).floor() as u8; //Split the RGB grayscale values into 24 chunks
|
||||
Color::new(i * step, i * step, i * step, u8::MAX) //Map the ANSI-grayscale components to the RGB-grayscale
|
||||
}
|
||||
//For compatibility with the alacritty::Colors interface
|
||||
256 => style.foreground,
|
||||
257 => style.background,
|
||||
258 => style.cursor,
|
||||
259 => style.dim_black,
|
||||
260 => style.dim_red,
|
||||
261 => style.dim_green,
|
||||
262 => style.dim_yellow,
|
||||
263 => style.dim_blue,
|
||||
264 => style.dim_magenta,
|
||||
265 => style.dim_cyan,
|
||||
266 => style.dim_white,
|
||||
267 => style.bright_foreground,
|
||||
268 => style.black, //'Dim Background', non-standard color
|
||||
_ => Color::new(0, 0, 0, 255),
|
||||
}
|
||||
}
|
||||
///Generates the rgb channels in [0, 5] for a given index into the 6x6x6 ANSI color cube
|
||||
///See: [8 bit ansi color](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit).
|
||||
///
|
||||
///Wikipedia gives a formula for calculating the index for a given color:
|
||||
///
|
||||
///index = 16 + 36 × r + 6 × g + b (0 ≤ r, g, b ≤ 5)
|
||||
///
|
||||
///This function does the reverse, calculating the r, g, and b components from a given index.
|
||||
fn rgb_for_index(i: &u8) -> (u8, u8, u8) {
|
||||
debug_assert!((&16..=&231).contains(&i));
|
||||
let i = i - 16;
|
||||
let r = (i - (i % 36)) / 36;
|
||||
let g = ((i % 36) - (i % 6)) / 6;
|
||||
let b = (i % 36) % 6;
|
||||
(r, g, b)
|
||||
}
|
||||
use gpui::Rgba;
|
||||
|
||||
//Convenience method to convert from a GPUI color to an alacritty Rgb
|
||||
pub fn to_alac_rgb(color: Color) -> AlacRgb {
|
||||
AlacRgb::new(color.r, color.g, color.g)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn test_rgb_for_index() {
|
||||
//Test every possible value in the color cube
|
||||
for i in 16..=231 {
|
||||
let (r, g, b) = crate::mappings::colors::rgb_for_index(&(i as u8));
|
||||
assert_eq!(i, 16 + 36 * r + 6 * g + b);
|
||||
}
|
||||
}
|
||||
pub fn to_alac_rgb(color: impl Into<Rgba>) -> AlacRgb {
|
||||
let color = color.into();
|
||||
let r = ((color.r * color.a) * 255.) as u8;
|
||||
let g = ((color.g * color.a) * 255.) as u8;
|
||||
let b = ((color.b * color.a) * 255.) as u8;
|
||||
AlacRgb::new(r, g, b)
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
/// The mappings defined in this file where created from reading the alacritty source
|
||||
use alacritty_terminal::term::TermMode;
|
||||
use gpui::keymap_matcher::Keystroke;
|
||||
use gpui::Keystroke;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum Modifiers {
|
||||
enum AlacModifiers {
|
||||
None,
|
||||
Alt,
|
||||
Ctrl,
|
||||
|
@ -12,179 +12,184 @@ pub enum Modifiers {
|
|||
Other,
|
||||
}
|
||||
|
||||
impl Modifiers {
|
||||
impl AlacModifiers {
|
||||
fn new(ks: &Keystroke) -> Self {
|
||||
match (ks.alt, ks.ctrl, ks.shift, ks.cmd) {
|
||||
(false, false, false, false) => Modifiers::None,
|
||||
(true, false, false, false) => Modifiers::Alt,
|
||||
(false, true, false, false) => Modifiers::Ctrl,
|
||||
(false, false, true, false) => Modifiers::Shift,
|
||||
(false, true, true, false) => Modifiers::CtrlShift,
|
||||
_ => Modifiers::Other,
|
||||
match (
|
||||
ks.modifiers.alt,
|
||||
ks.modifiers.control,
|
||||
ks.modifiers.shift,
|
||||
ks.modifiers.command,
|
||||
) {
|
||||
(false, false, false, false) => AlacModifiers::None,
|
||||
(true, false, false, false) => AlacModifiers::Alt,
|
||||
(false, true, false, false) => AlacModifiers::Ctrl,
|
||||
(false, false, true, false) => AlacModifiers::Shift,
|
||||
(false, true, true, false) => AlacModifiers::CtrlShift,
|
||||
_ => AlacModifiers::Other,
|
||||
}
|
||||
}
|
||||
|
||||
fn any(&self) -> bool {
|
||||
match &self {
|
||||
Modifiers::None => false,
|
||||
Modifiers::Alt => true,
|
||||
Modifiers::Ctrl => true,
|
||||
Modifiers::Shift => true,
|
||||
Modifiers::CtrlShift => true,
|
||||
Modifiers::Other => true,
|
||||
AlacModifiers::None => false,
|
||||
AlacModifiers::Alt => true,
|
||||
AlacModifiers::Ctrl => true,
|
||||
AlacModifiers::Shift => true,
|
||||
AlacModifiers::CtrlShift => true,
|
||||
AlacModifiers::Other => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_esc_str(keystroke: &Keystroke, mode: &TermMode, alt_is_meta: bool) -> Option<String> {
|
||||
let modifiers = Modifiers::new(keystroke);
|
||||
let modifiers = AlacModifiers::new(keystroke);
|
||||
|
||||
// Manual Bindings including modifiers
|
||||
let manual_esc_str = match (keystroke.key.as_ref(), &modifiers) {
|
||||
//Basic special keys
|
||||
("tab", Modifiers::None) => Some("\x09".to_string()),
|
||||
("escape", Modifiers::None) => Some("\x1b".to_string()),
|
||||
("enter", Modifiers::None) => Some("\x0d".to_string()),
|
||||
("enter", Modifiers::Shift) => Some("\x0d".to_string()),
|
||||
("backspace", Modifiers::None) => Some("\x7f".to_string()),
|
||||
("tab", AlacModifiers::None) => Some("\x09".to_string()),
|
||||
("escape", AlacModifiers::None) => Some("\x1b".to_string()),
|
||||
("enter", AlacModifiers::None) => Some("\x0d".to_string()),
|
||||
("enter", AlacModifiers::Shift) => Some("\x0d".to_string()),
|
||||
("backspace", AlacModifiers::None) => Some("\x7f".to_string()),
|
||||
//Interesting escape codes
|
||||
("tab", Modifiers::Shift) => Some("\x1b[Z".to_string()),
|
||||
("backspace", Modifiers::Alt) => Some("\x1b\x7f".to_string()),
|
||||
("backspace", Modifiers::Shift) => Some("\x7f".to_string()),
|
||||
("home", Modifiers::Shift) if mode.contains(TermMode::ALT_SCREEN) => {
|
||||
("tab", AlacModifiers::Shift) => Some("\x1b[Z".to_string()),
|
||||
("backspace", AlacModifiers::Alt) => Some("\x1b\x7f".to_string()),
|
||||
("backspace", AlacModifiers::Shift) => Some("\x7f".to_string()),
|
||||
("home", AlacModifiers::Shift) if mode.contains(TermMode::ALT_SCREEN) => {
|
||||
Some("\x1b[1;2H".to_string())
|
||||
}
|
||||
("end", Modifiers::Shift) if mode.contains(TermMode::ALT_SCREEN) => {
|
||||
("end", AlacModifiers::Shift) if mode.contains(TermMode::ALT_SCREEN) => {
|
||||
Some("\x1b[1;2F".to_string())
|
||||
}
|
||||
("pageup", Modifiers::Shift) if mode.contains(TermMode::ALT_SCREEN) => {
|
||||
("pageup", AlacModifiers::Shift) if mode.contains(TermMode::ALT_SCREEN) => {
|
||||
Some("\x1b[5;2~".to_string())
|
||||
}
|
||||
("pagedown", Modifiers::Shift) if mode.contains(TermMode::ALT_SCREEN) => {
|
||||
("pagedown", AlacModifiers::Shift) if mode.contains(TermMode::ALT_SCREEN) => {
|
||||
Some("\x1b[6;2~".to_string())
|
||||
}
|
||||
("home", Modifiers::None) if mode.contains(TermMode::APP_CURSOR) => {
|
||||
("home", AlacModifiers::None) if mode.contains(TermMode::APP_CURSOR) => {
|
||||
Some("\x1bOH".to_string())
|
||||
}
|
||||
("home", Modifiers::None) if !mode.contains(TermMode::APP_CURSOR) => {
|
||||
("home", AlacModifiers::None) if !mode.contains(TermMode::APP_CURSOR) => {
|
||||
Some("\x1b[H".to_string())
|
||||
}
|
||||
("end", Modifiers::None) if mode.contains(TermMode::APP_CURSOR) => {
|
||||
("end", AlacModifiers::None) if mode.contains(TermMode::APP_CURSOR) => {
|
||||
Some("\x1bOF".to_string())
|
||||
}
|
||||
("end", Modifiers::None) if !mode.contains(TermMode::APP_CURSOR) => {
|
||||
("end", AlacModifiers::None) if !mode.contains(TermMode::APP_CURSOR) => {
|
||||
Some("\x1b[F".to_string())
|
||||
}
|
||||
("up", Modifiers::None) if mode.contains(TermMode::APP_CURSOR) => {
|
||||
("up", AlacModifiers::None) if mode.contains(TermMode::APP_CURSOR) => {
|
||||
Some("\x1bOA".to_string())
|
||||
}
|
||||
("up", Modifiers::None) if !mode.contains(TermMode::APP_CURSOR) => {
|
||||
("up", AlacModifiers::None) if !mode.contains(TermMode::APP_CURSOR) => {
|
||||
Some("\x1b[A".to_string())
|
||||
}
|
||||
("down", Modifiers::None) if mode.contains(TermMode::APP_CURSOR) => {
|
||||
("down", AlacModifiers::None) if mode.contains(TermMode::APP_CURSOR) => {
|
||||
Some("\x1bOB".to_string())
|
||||
}
|
||||
("down", Modifiers::None) if !mode.contains(TermMode::APP_CURSOR) => {
|
||||
("down", AlacModifiers::None) if !mode.contains(TermMode::APP_CURSOR) => {
|
||||
Some("\x1b[B".to_string())
|
||||
}
|
||||
("right", Modifiers::None) if mode.contains(TermMode::APP_CURSOR) => {
|
||||
("right", AlacModifiers::None) if mode.contains(TermMode::APP_CURSOR) => {
|
||||
Some("\x1bOC".to_string())
|
||||
}
|
||||
("right", Modifiers::None) if !mode.contains(TermMode::APP_CURSOR) => {
|
||||
("right", AlacModifiers::None) if !mode.contains(TermMode::APP_CURSOR) => {
|
||||
Some("\x1b[C".to_string())
|
||||
}
|
||||
("left", Modifiers::None) if mode.contains(TermMode::APP_CURSOR) => {
|
||||
("left", AlacModifiers::None) if mode.contains(TermMode::APP_CURSOR) => {
|
||||
Some("\x1bOD".to_string())
|
||||
}
|
||||
("left", Modifiers::None) if !mode.contains(TermMode::APP_CURSOR) => {
|
||||
("left", AlacModifiers::None) if !mode.contains(TermMode::APP_CURSOR) => {
|
||||
Some("\x1b[D".to_string())
|
||||
}
|
||||
("back", Modifiers::None) => Some("\x7f".to_string()),
|
||||
("insert", Modifiers::None) => Some("\x1b[2~".to_string()),
|
||||
("delete", Modifiers::None) => Some("\x1b[3~".to_string()),
|
||||
("pageup", Modifiers::None) => Some("\x1b[5~".to_string()),
|
||||
("pagedown", Modifiers::None) => Some("\x1b[6~".to_string()),
|
||||
("f1", Modifiers::None) => Some("\x1bOP".to_string()),
|
||||
("f2", Modifiers::None) => Some("\x1bOQ".to_string()),
|
||||
("f3", Modifiers::None) => Some("\x1bOR".to_string()),
|
||||
("f4", Modifiers::None) => Some("\x1bOS".to_string()),
|
||||
("f5", Modifiers::None) => Some("\x1b[15~".to_string()),
|
||||
("f6", Modifiers::None) => Some("\x1b[17~".to_string()),
|
||||
("f7", Modifiers::None) => Some("\x1b[18~".to_string()),
|
||||
("f8", Modifiers::None) => Some("\x1b[19~".to_string()),
|
||||
("f9", Modifiers::None) => Some("\x1b[20~".to_string()),
|
||||
("f10", Modifiers::None) => Some("\x1b[21~".to_string()),
|
||||
("f11", Modifiers::None) => Some("\x1b[23~".to_string()),
|
||||
("f12", Modifiers::None) => Some("\x1b[24~".to_string()),
|
||||
("f13", Modifiers::None) => Some("\x1b[25~".to_string()),
|
||||
("f14", Modifiers::None) => Some("\x1b[26~".to_string()),
|
||||
("f15", Modifiers::None) => Some("\x1b[28~".to_string()),
|
||||
("f16", Modifiers::None) => Some("\x1b[29~".to_string()),
|
||||
("f17", Modifiers::None) => Some("\x1b[31~".to_string()),
|
||||
("f18", Modifiers::None) => Some("\x1b[32~".to_string()),
|
||||
("f19", Modifiers::None) => Some("\x1b[33~".to_string()),
|
||||
("f20", Modifiers::None) => Some("\x1b[34~".to_string()),
|
||||
("back", AlacModifiers::None) => Some("\x7f".to_string()),
|
||||
("insert", AlacModifiers::None) => Some("\x1b[2~".to_string()),
|
||||
("delete", AlacModifiers::None) => Some("\x1b[3~".to_string()),
|
||||
("pageup", AlacModifiers::None) => Some("\x1b[5~".to_string()),
|
||||
("pagedown", AlacModifiers::None) => Some("\x1b[6~".to_string()),
|
||||
("f1", AlacModifiers::None) => Some("\x1bOP".to_string()),
|
||||
("f2", AlacModifiers::None) => Some("\x1bOQ".to_string()),
|
||||
("f3", AlacModifiers::None) => Some("\x1bOR".to_string()),
|
||||
("f4", AlacModifiers::None) => Some("\x1bOS".to_string()),
|
||||
("f5", AlacModifiers::None) => Some("\x1b[15~".to_string()),
|
||||
("f6", AlacModifiers::None) => Some("\x1b[17~".to_string()),
|
||||
("f7", AlacModifiers::None) => Some("\x1b[18~".to_string()),
|
||||
("f8", AlacModifiers::None) => Some("\x1b[19~".to_string()),
|
||||
("f9", AlacModifiers::None) => Some("\x1b[20~".to_string()),
|
||||
("f10", AlacModifiers::None) => Some("\x1b[21~".to_string()),
|
||||
("f11", AlacModifiers::None) => Some("\x1b[23~".to_string()),
|
||||
("f12", AlacModifiers::None) => Some("\x1b[24~".to_string()),
|
||||
("f13", AlacModifiers::None) => Some("\x1b[25~".to_string()),
|
||||
("f14", AlacModifiers::None) => Some("\x1b[26~".to_string()),
|
||||
("f15", AlacModifiers::None) => Some("\x1b[28~".to_string()),
|
||||
("f16", AlacModifiers::None) => Some("\x1b[29~".to_string()),
|
||||
("f17", AlacModifiers::None) => Some("\x1b[31~".to_string()),
|
||||
("f18", AlacModifiers::None) => Some("\x1b[32~".to_string()),
|
||||
("f19", AlacModifiers::None) => Some("\x1b[33~".to_string()),
|
||||
("f20", AlacModifiers::None) => Some("\x1b[34~".to_string()),
|
||||
// NumpadEnter, Action::Esc("\n".into());
|
||||
//Mappings for caret notation keys
|
||||
("a", Modifiers::Ctrl) => Some("\x01".to_string()), //1
|
||||
("A", Modifiers::CtrlShift) => Some("\x01".to_string()), //1
|
||||
("b", Modifiers::Ctrl) => Some("\x02".to_string()), //2
|
||||
("B", Modifiers::CtrlShift) => Some("\x02".to_string()), //2
|
||||
("c", Modifiers::Ctrl) => Some("\x03".to_string()), //3
|
||||
("C", Modifiers::CtrlShift) => Some("\x03".to_string()), //3
|
||||
("d", Modifiers::Ctrl) => Some("\x04".to_string()), //4
|
||||
("D", Modifiers::CtrlShift) => Some("\x04".to_string()), //4
|
||||
("e", Modifiers::Ctrl) => Some("\x05".to_string()), //5
|
||||
("E", Modifiers::CtrlShift) => Some("\x05".to_string()), //5
|
||||
("f", Modifiers::Ctrl) => Some("\x06".to_string()), //6
|
||||
("F", Modifiers::CtrlShift) => Some("\x06".to_string()), //6
|
||||
("g", Modifiers::Ctrl) => Some("\x07".to_string()), //7
|
||||
("G", Modifiers::CtrlShift) => Some("\x07".to_string()), //7
|
||||
("h", Modifiers::Ctrl) => Some("\x08".to_string()), //8
|
||||
("H", Modifiers::CtrlShift) => Some("\x08".to_string()), //8
|
||||
("i", Modifiers::Ctrl) => Some("\x09".to_string()), //9
|
||||
("I", Modifiers::CtrlShift) => Some("\x09".to_string()), //9
|
||||
("j", Modifiers::Ctrl) => Some("\x0a".to_string()), //10
|
||||
("J", Modifiers::CtrlShift) => Some("\x0a".to_string()), //10
|
||||
("k", Modifiers::Ctrl) => Some("\x0b".to_string()), //11
|
||||
("K", Modifiers::CtrlShift) => Some("\x0b".to_string()), //11
|
||||
("l", Modifiers::Ctrl) => Some("\x0c".to_string()), //12
|
||||
("L", Modifiers::CtrlShift) => Some("\x0c".to_string()), //12
|
||||
("m", Modifiers::Ctrl) => Some("\x0d".to_string()), //13
|
||||
("M", Modifiers::CtrlShift) => Some("\x0d".to_string()), //13
|
||||
("n", Modifiers::Ctrl) => Some("\x0e".to_string()), //14
|
||||
("N", Modifiers::CtrlShift) => Some("\x0e".to_string()), //14
|
||||
("o", Modifiers::Ctrl) => Some("\x0f".to_string()), //15
|
||||
("O", Modifiers::CtrlShift) => Some("\x0f".to_string()), //15
|
||||
("p", Modifiers::Ctrl) => Some("\x10".to_string()), //16
|
||||
("P", Modifiers::CtrlShift) => Some("\x10".to_string()), //16
|
||||
("q", Modifiers::Ctrl) => Some("\x11".to_string()), //17
|
||||
("Q", Modifiers::CtrlShift) => Some("\x11".to_string()), //17
|
||||
("r", Modifiers::Ctrl) => Some("\x12".to_string()), //18
|
||||
("R", Modifiers::CtrlShift) => Some("\x12".to_string()), //18
|
||||
("s", Modifiers::Ctrl) => Some("\x13".to_string()), //19
|
||||
("S", Modifiers::CtrlShift) => Some("\x13".to_string()), //19
|
||||
("t", Modifiers::Ctrl) => Some("\x14".to_string()), //20
|
||||
("T", Modifiers::CtrlShift) => Some("\x14".to_string()), //20
|
||||
("u", Modifiers::Ctrl) => Some("\x15".to_string()), //21
|
||||
("U", Modifiers::CtrlShift) => Some("\x15".to_string()), //21
|
||||
("v", Modifiers::Ctrl) => Some("\x16".to_string()), //22
|
||||
("V", Modifiers::CtrlShift) => Some("\x16".to_string()), //22
|
||||
("w", Modifiers::Ctrl) => Some("\x17".to_string()), //23
|
||||
("W", Modifiers::CtrlShift) => Some("\x17".to_string()), //23
|
||||
("x", Modifiers::Ctrl) => Some("\x18".to_string()), //24
|
||||
("X", Modifiers::CtrlShift) => Some("\x18".to_string()), //24
|
||||
("y", Modifiers::Ctrl) => Some("\x19".to_string()), //25
|
||||
("Y", Modifiers::CtrlShift) => Some("\x19".to_string()), //25
|
||||
("z", Modifiers::Ctrl) => Some("\x1a".to_string()), //26
|
||||
("Z", Modifiers::CtrlShift) => Some("\x1a".to_string()), //26
|
||||
("@", Modifiers::Ctrl) => Some("\x00".to_string()), //0
|
||||
("[", Modifiers::Ctrl) => Some("\x1b".to_string()), //27
|
||||
("\\", Modifiers::Ctrl) => Some("\x1c".to_string()), //28
|
||||
("]", Modifiers::Ctrl) => Some("\x1d".to_string()), //29
|
||||
("^", Modifiers::Ctrl) => Some("\x1e".to_string()), //30
|
||||
("_", Modifiers::Ctrl) => Some("\x1f".to_string()), //31
|
||||
("?", Modifiers::Ctrl) => Some("\x7f".to_string()), //127
|
||||
("a", AlacModifiers::Ctrl) => Some("\x01".to_string()), //1
|
||||
("A", AlacModifiers::CtrlShift) => Some("\x01".to_string()), //1
|
||||
("b", AlacModifiers::Ctrl) => Some("\x02".to_string()), //2
|
||||
("B", AlacModifiers::CtrlShift) => Some("\x02".to_string()), //2
|
||||
("c", AlacModifiers::Ctrl) => Some("\x03".to_string()), //3
|
||||
("C", AlacModifiers::CtrlShift) => Some("\x03".to_string()), //3
|
||||
("d", AlacModifiers::Ctrl) => Some("\x04".to_string()), //4
|
||||
("D", AlacModifiers::CtrlShift) => Some("\x04".to_string()), //4
|
||||
("e", AlacModifiers::Ctrl) => Some("\x05".to_string()), //5
|
||||
("E", AlacModifiers::CtrlShift) => Some("\x05".to_string()), //5
|
||||
("f", AlacModifiers::Ctrl) => Some("\x06".to_string()), //6
|
||||
("F", AlacModifiers::CtrlShift) => Some("\x06".to_string()), //6
|
||||
("g", AlacModifiers::Ctrl) => Some("\x07".to_string()), //7
|
||||
("G", AlacModifiers::CtrlShift) => Some("\x07".to_string()), //7
|
||||
("h", AlacModifiers::Ctrl) => Some("\x08".to_string()), //8
|
||||
("H", AlacModifiers::CtrlShift) => Some("\x08".to_string()), //8
|
||||
("i", AlacModifiers::Ctrl) => Some("\x09".to_string()), //9
|
||||
("I", AlacModifiers::CtrlShift) => Some("\x09".to_string()), //9
|
||||
("j", AlacModifiers::Ctrl) => Some("\x0a".to_string()), //10
|
||||
("J", AlacModifiers::CtrlShift) => Some("\x0a".to_string()), //10
|
||||
("k", AlacModifiers::Ctrl) => Some("\x0b".to_string()), //11
|
||||
("K", AlacModifiers::CtrlShift) => Some("\x0b".to_string()), //11
|
||||
("l", AlacModifiers::Ctrl) => Some("\x0c".to_string()), //12
|
||||
("L", AlacModifiers::CtrlShift) => Some("\x0c".to_string()), //12
|
||||
("m", AlacModifiers::Ctrl) => Some("\x0d".to_string()), //13
|
||||
("M", AlacModifiers::CtrlShift) => Some("\x0d".to_string()), //13
|
||||
("n", AlacModifiers::Ctrl) => Some("\x0e".to_string()), //14
|
||||
("N", AlacModifiers::CtrlShift) => Some("\x0e".to_string()), //14
|
||||
("o", AlacModifiers::Ctrl) => Some("\x0f".to_string()), //15
|
||||
("O", AlacModifiers::CtrlShift) => Some("\x0f".to_string()), //15
|
||||
("p", AlacModifiers::Ctrl) => Some("\x10".to_string()), //16
|
||||
("P", AlacModifiers::CtrlShift) => Some("\x10".to_string()), //16
|
||||
("q", AlacModifiers::Ctrl) => Some("\x11".to_string()), //17
|
||||
("Q", AlacModifiers::CtrlShift) => Some("\x11".to_string()), //17
|
||||
("r", AlacModifiers::Ctrl) => Some("\x12".to_string()), //18
|
||||
("R", AlacModifiers::CtrlShift) => Some("\x12".to_string()), //18
|
||||
("s", AlacModifiers::Ctrl) => Some("\x13".to_string()), //19
|
||||
("S", AlacModifiers::CtrlShift) => Some("\x13".to_string()), //19
|
||||
("t", AlacModifiers::Ctrl) => Some("\x14".to_string()), //20
|
||||
("T", AlacModifiers::CtrlShift) => Some("\x14".to_string()), //20
|
||||
("u", AlacModifiers::Ctrl) => Some("\x15".to_string()), //21
|
||||
("U", AlacModifiers::CtrlShift) => Some("\x15".to_string()), //21
|
||||
("v", AlacModifiers::Ctrl) => Some("\x16".to_string()), //22
|
||||
("V", AlacModifiers::CtrlShift) => Some("\x16".to_string()), //22
|
||||
("w", AlacModifiers::Ctrl) => Some("\x17".to_string()), //23
|
||||
("W", AlacModifiers::CtrlShift) => Some("\x17".to_string()), //23
|
||||
("x", AlacModifiers::Ctrl) => Some("\x18".to_string()), //24
|
||||
("X", AlacModifiers::CtrlShift) => Some("\x18".to_string()), //24
|
||||
("y", AlacModifiers::Ctrl) => Some("\x19".to_string()), //25
|
||||
("Y", AlacModifiers::CtrlShift) => Some("\x19".to_string()), //25
|
||||
("z", AlacModifiers::Ctrl) => Some("\x1a".to_string()), //26
|
||||
("Z", AlacModifiers::CtrlShift) => Some("\x1a".to_string()), //26
|
||||
("@", AlacModifiers::Ctrl) => Some("\x00".to_string()), //0
|
||||
("[", AlacModifiers::Ctrl) => Some("\x1b".to_string()), //27
|
||||
("\\", AlacModifiers::Ctrl) => Some("\x1c".to_string()), //28
|
||||
("]", AlacModifiers::Ctrl) => Some("\x1d".to_string()), //29
|
||||
("^", AlacModifiers::Ctrl) => Some("\x1e".to_string()), //30
|
||||
("_", AlacModifiers::Ctrl) => Some("\x1f".to_string()), //31
|
||||
("?", AlacModifiers::Ctrl) => Some("\x7f".to_string()), //127
|
||||
_ => None,
|
||||
};
|
||||
if manual_esc_str.is_some() {
|
||||
|
@ -232,12 +237,12 @@ pub fn to_esc_str(keystroke: &Keystroke, mode: &TermMode, alt_is_meta: bool) ->
|
|||
}
|
||||
}
|
||||
|
||||
let alt_meta_binding = if alt_is_meta && modifiers == Modifiers::Alt && keystroke.key.is_ascii()
|
||||
{
|
||||
Some(format!("\x1b{}", keystroke.key))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let alt_meta_binding =
|
||||
if alt_is_meta && modifiers == AlacModifiers::Alt && keystroke.key.is_ascii() {
|
||||
Some(format!("\x1b{}", keystroke.key))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
if alt_meta_binding.is_some() {
|
||||
return alt_meta_binding;
|
||||
|
@ -259,13 +264,13 @@ pub fn to_esc_str(keystroke: &Keystroke, mode: &TermMode, alt_is_meta: bool) ->
|
|||
/// from: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-PC-Style-Function-Keys
|
||||
fn modifier_code(keystroke: &Keystroke) -> u32 {
|
||||
let mut modifier_code = 0;
|
||||
if keystroke.shift {
|
||||
if keystroke.modifiers.shift {
|
||||
modifier_code |= 1;
|
||||
}
|
||||
if keystroke.alt {
|
||||
if keystroke.modifiers.alt {
|
||||
modifier_code |= 1 << 1;
|
||||
}
|
||||
if keystroke.ctrl {
|
||||
if keystroke.modifiers.control {
|
||||
modifier_code |= 1 << 2;
|
||||
}
|
||||
modifier_code + 1
|
||||
|
@ -273,7 +278,7 @@ fn modifier_code(keystroke: &Keystroke) -> u32 {
|
|||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use gpui::keymap_matcher::Keystroke;
|
||||
use gpui::Modifiers;
|
||||
|
||||
use super::*;
|
||||
|
||||
|
@ -327,11 +332,13 @@ mod test {
|
|||
#[test]
|
||||
fn test_plain_inputs() {
|
||||
let ks = Keystroke {
|
||||
ctrl: false,
|
||||
alt: false,
|
||||
shift: false,
|
||||
cmd: false,
|
||||
function: false,
|
||||
modifiers: Modifiers {
|
||||
control: false,
|
||||
alt: false,
|
||||
shift: false,
|
||||
command: false,
|
||||
function: false,
|
||||
},
|
||||
key: "🖖🏻".to_string(), //2 char string
|
||||
ime_key: None,
|
||||
};
|
||||
|
|
|
@ -1,52 +1,15 @@
|
|||
use std::cmp::{max, min};
|
||||
use std::cmp::{self, max, min};
|
||||
use std::iter::repeat;
|
||||
|
||||
use alacritty_terminal::grid::Dimensions;
|
||||
/// Most of the code, and specifically the constants, in this are copied from Alacritty,
|
||||
/// with modifications for our circumstances
|
||||
use alacritty_terminal::index::{Column as GridCol, Line as GridLine, Point, Side};
|
||||
use alacritty_terminal::index::{Column as GridCol, Line as GridLine, Point as AlacPoint, Side};
|
||||
use alacritty_terminal::term::TermMode;
|
||||
use gpui::platform;
|
||||
use gpui::scene::MouseScrollWheel;
|
||||
use gpui::{
|
||||
geometry::vector::Vector2F,
|
||||
platform::{MouseButtonEvent, MouseMovedEvent, ScrollWheelEvent},
|
||||
};
|
||||
use gpui::{px, Modifiers, MouseButton, MouseMoveEvent, Pixels, Point, ScrollWheelEvent};
|
||||
|
||||
use crate::TerminalSize;
|
||||
|
||||
struct Modifiers {
|
||||
ctrl: bool,
|
||||
shift: bool,
|
||||
alt: bool,
|
||||
}
|
||||
|
||||
impl Modifiers {
|
||||
fn from_moved(e: &MouseMovedEvent) -> Self {
|
||||
Modifiers {
|
||||
ctrl: e.ctrl,
|
||||
shift: e.shift,
|
||||
alt: e.alt,
|
||||
}
|
||||
}
|
||||
|
||||
fn from_button(e: &MouseButtonEvent) -> Self {
|
||||
Modifiers {
|
||||
ctrl: e.ctrl,
|
||||
shift: e.shift,
|
||||
alt: e.alt,
|
||||
}
|
||||
}
|
||||
|
||||
fn from_scroll(scroll: &ScrollWheelEvent) -> Self {
|
||||
Modifiers {
|
||||
ctrl: scroll.ctrl,
|
||||
shift: scroll.shift,
|
||||
alt: scroll.alt,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum MouseFormat {
|
||||
SGR,
|
||||
Normal(bool),
|
||||
|
@ -65,7 +28,7 @@ impl MouseFormat {
|
|||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum MouseButton {
|
||||
enum AlacMouseButton {
|
||||
LeftButton = 0,
|
||||
MiddleButton = 1,
|
||||
RightButton = 2,
|
||||
|
@ -78,56 +41,61 @@ enum MouseButton {
|
|||
Other = 99,
|
||||
}
|
||||
|
||||
impl MouseButton {
|
||||
fn from_move(e: &MouseMovedEvent) -> Self {
|
||||
impl AlacMouseButton {
|
||||
fn from_move(e: &MouseMoveEvent) -> Self {
|
||||
match e.pressed_button {
|
||||
Some(b) => match b {
|
||||
platform::MouseButton::Left => MouseButton::LeftMove,
|
||||
platform::MouseButton::Middle => MouseButton::MiddleMove,
|
||||
platform::MouseButton::Right => MouseButton::RightMove,
|
||||
platform::MouseButton::Navigate(_) => MouseButton::Other,
|
||||
gpui::MouseButton::Left => AlacMouseButton::LeftMove,
|
||||
gpui::MouseButton::Middle => AlacMouseButton::MiddleMove,
|
||||
gpui::MouseButton::Right => AlacMouseButton::RightMove,
|
||||
gpui::MouseButton::Navigate(_) => AlacMouseButton::Other,
|
||||
},
|
||||
None => MouseButton::NoneMove,
|
||||
None => AlacMouseButton::NoneMove,
|
||||
}
|
||||
}
|
||||
|
||||
fn from_button(e: &MouseButtonEvent) -> Self {
|
||||
match e.button {
|
||||
platform::MouseButton::Left => MouseButton::LeftButton,
|
||||
platform::MouseButton::Right => MouseButton::MiddleButton,
|
||||
platform::MouseButton::Middle => MouseButton::RightButton,
|
||||
platform::MouseButton::Navigate(_) => MouseButton::Other,
|
||||
fn from_button(e: MouseButton) -> Self {
|
||||
match e {
|
||||
gpui::MouseButton::Left => AlacMouseButton::LeftButton,
|
||||
gpui::MouseButton::Right => AlacMouseButton::MiddleButton,
|
||||
gpui::MouseButton::Middle => AlacMouseButton::RightButton,
|
||||
gpui::MouseButton::Navigate(_) => AlacMouseButton::Other,
|
||||
}
|
||||
}
|
||||
|
||||
fn from_scroll(e: &ScrollWheelEvent) -> Self {
|
||||
if e.delta.raw().y() > 0. {
|
||||
MouseButton::ScrollUp
|
||||
let is_positive = match e.delta {
|
||||
gpui::ScrollDelta::Pixels(pixels) => pixels.y > px(0.),
|
||||
gpui::ScrollDelta::Lines(lines) => lines.y > 0.,
|
||||
};
|
||||
|
||||
if is_positive {
|
||||
AlacMouseButton::ScrollUp
|
||||
} else {
|
||||
MouseButton::ScrollDown
|
||||
AlacMouseButton::ScrollDown
|
||||
}
|
||||
}
|
||||
|
||||
fn is_other(&self) -> bool {
|
||||
match self {
|
||||
MouseButton::Other => true,
|
||||
AlacMouseButton::Other => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn scroll_report(
|
||||
point: Point,
|
||||
point: AlacPoint,
|
||||
scroll_lines: i32,
|
||||
e: &MouseScrollWheel,
|
||||
e: &ScrollWheelEvent,
|
||||
mode: TermMode,
|
||||
) -> Option<impl Iterator<Item = Vec<u8>>> {
|
||||
if mode.intersects(TermMode::MOUSE_MODE) {
|
||||
mouse_report(
|
||||
point,
|
||||
MouseButton::from_scroll(e),
|
||||
AlacMouseButton::from_scroll(e),
|
||||
true,
|
||||
Modifiers::from_scroll(e),
|
||||
e.modifiers,
|
||||
MouseFormat::from_mode(mode),
|
||||
)
|
||||
.map(|report| repeat(report).take(max(scroll_lines, 1) as usize))
|
||||
|
@ -149,18 +117,19 @@ pub fn alt_scroll(scroll_lines: i32) -> Vec<u8> {
|
|||
}
|
||||
|
||||
pub fn mouse_button_report(
|
||||
point: Point,
|
||||
e: &MouseButtonEvent,
|
||||
point: AlacPoint,
|
||||
button: gpui::MouseButton,
|
||||
modifiers: Modifiers,
|
||||
pressed: bool,
|
||||
mode: TermMode,
|
||||
) -> Option<Vec<u8>> {
|
||||
let button = MouseButton::from_button(e);
|
||||
let button = AlacMouseButton::from_button(button);
|
||||
if !button.is_other() && mode.intersects(TermMode::MOUSE_MODE) {
|
||||
mouse_report(
|
||||
point,
|
||||
button,
|
||||
pressed,
|
||||
Modifiers::from_button(e),
|
||||
modifiers,
|
||||
MouseFormat::from_mode(mode),
|
||||
)
|
||||
} else {
|
||||
|
@ -168,19 +137,19 @@ pub fn mouse_button_report(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn mouse_moved_report(point: Point, e: &MouseMovedEvent, mode: TermMode) -> Option<Vec<u8>> {
|
||||
let button = MouseButton::from_move(e);
|
||||
pub fn mouse_moved_report(point: AlacPoint, e: &MouseMoveEvent, mode: TermMode) -> Option<Vec<u8>> {
|
||||
let button = AlacMouseButton::from_move(e);
|
||||
|
||||
if !button.is_other() && mode.intersects(TermMode::MOUSE_MOTION | TermMode::MOUSE_DRAG) {
|
||||
//Only drags are reported in drag mode, so block NoneMove.
|
||||
if mode.contains(TermMode::MOUSE_DRAG) && matches!(button, MouseButton::NoneMove) {
|
||||
if mode.contains(TermMode::MOUSE_DRAG) && matches!(button, AlacMouseButton::NoneMove) {
|
||||
None
|
||||
} else {
|
||||
mouse_report(
|
||||
point,
|
||||
button,
|
||||
true,
|
||||
Modifiers::from_moved(e),
|
||||
e.modifiers,
|
||||
MouseFormat::from_mode(mode),
|
||||
)
|
||||
}
|
||||
|
@ -189,19 +158,26 @@ pub fn mouse_moved_report(point: Point, e: &MouseMovedEvent, mode: TermMode) ->
|
|||
}
|
||||
}
|
||||
|
||||
pub fn mouse_side(pos: Vector2F, cur_size: TerminalSize) -> alacritty_terminal::index::Direction {
|
||||
if cur_size.cell_width as usize == 0 {
|
||||
pub fn mouse_side(
|
||||
pos: Point<Pixels>,
|
||||
cur_size: TerminalSize,
|
||||
) -> alacritty_terminal::index::Direction {
|
||||
let cell_width = cur_size.cell_width.floor();
|
||||
if cell_width == px(0.) {
|
||||
return Side::Right;
|
||||
}
|
||||
let x = pos.0.x() as usize;
|
||||
let cell_x = x.saturating_sub(cur_size.cell_width as usize) % cur_size.cell_width as usize;
|
||||
let half_cell_width = (cur_size.cell_width / 2.0) as usize;
|
||||
|
||||
let x = pos.x.floor();
|
||||
|
||||
let cell_x = cmp::max(px(0.), x - cell_width) % cell_width;
|
||||
let half_cell_width = (cur_size.cell_width / 2.0).floor();
|
||||
let additional_padding = (cur_size.width() - cur_size.cell_width * 2.) % cur_size.cell_width;
|
||||
let end_of_grid = cur_size.width() - cur_size.cell_width - additional_padding;
|
||||
|
||||
//Width: Pixels or columns?
|
||||
if cell_x > half_cell_width
|
||||
// Edge case when mouse leaves the window.
|
||||
|| x as f32 >= end_of_grid
|
||||
|| x >= end_of_grid
|
||||
{
|
||||
Side::Right
|
||||
} else {
|
||||
|
@ -209,18 +185,18 @@ pub fn mouse_side(pos: Vector2F, cur_size: TerminalSize) -> alacritty_terminal::
|
|||
}
|
||||
}
|
||||
|
||||
pub fn grid_point(pos: Vector2F, cur_size: TerminalSize, display_offset: usize) -> Point {
|
||||
let col = pos.x() / cur_size.cell_width;
|
||||
let col = min(GridCol(col as usize), cur_size.last_column());
|
||||
let line = pos.y() / cur_size.line_height;
|
||||
let line = min(line as i32, cur_size.bottommost_line().0);
|
||||
Point::new(GridLine(line - display_offset as i32), col)
|
||||
pub fn grid_point(pos: Point<Pixels>, cur_size: TerminalSize, display_offset: usize) -> AlacPoint {
|
||||
let col = GridCol((pos.x / cur_size.cell_width) as usize);
|
||||
let col = min(col, cur_size.last_column());
|
||||
let line = (pos.y / cur_size.line_height) as i32;
|
||||
let line = min(line, cur_size.bottommost_line().0);
|
||||
AlacPoint::new(GridLine(line - display_offset as i32), col)
|
||||
}
|
||||
|
||||
///Generate the bytes to send to the terminal, from the cell location, a mouse event, and the terminal mode
|
||||
fn mouse_report(
|
||||
point: Point,
|
||||
button: MouseButton,
|
||||
point: AlacPoint,
|
||||
button: AlacMouseButton,
|
||||
pressed: bool,
|
||||
modifiers: Modifiers,
|
||||
format: MouseFormat,
|
||||
|
@ -236,7 +212,7 @@ fn mouse_report(
|
|||
if modifiers.alt {
|
||||
mods += 8;
|
||||
}
|
||||
if modifiers.ctrl {
|
||||
if modifiers.control {
|
||||
mods += 16;
|
||||
}
|
||||
|
||||
|
@ -254,8 +230,8 @@ fn mouse_report(
|
|||
}
|
||||
}
|
||||
|
||||
fn normal_mouse_report(point: Point, button: u8, utf8: bool) -> Option<Vec<u8>> {
|
||||
let Point { line, column } = point;
|
||||
fn normal_mouse_report(point: AlacPoint, button: u8, utf8: bool) -> Option<Vec<u8>> {
|
||||
let AlacPoint { line, column } = point;
|
||||
let max_point = if utf8 { 2015 } else { 223 };
|
||||
|
||||
if line >= max_point || column >= max_point {
|
||||
|
@ -286,7 +262,7 @@ fn normal_mouse_report(point: Point, button: u8, utf8: bool) -> Option<Vec<u8>>
|
|||
Some(msg)
|
||||
}
|
||||
|
||||
fn sgr_mouse_report(point: Point, button: u8, pressed: bool) -> String {
|
||||
fn sgr_mouse_report(point: AlacPoint, button: u8, pressed: bool) -> String {
|
||||
let c = if pressed { 'M' } else { 'm' };
|
||||
|
||||
let msg = format!(
|
||||
|
@ -299,38 +275,3 @@ fn sgr_mouse_report(point: Point, button: u8, pressed: bool) -> String {
|
|||
|
||||
msg
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::mappings::mouse::grid_point;
|
||||
|
||||
#[test]
|
||||
fn test_mouse_to_selection() {
|
||||
let term_width = 100.;
|
||||
let term_height = 200.;
|
||||
let cell_width = 10.;
|
||||
let line_height = 20.;
|
||||
let mouse_pos_x = 100.; //Window relative
|
||||
let mouse_pos_y = 100.; //Window relative
|
||||
let origin_x = 10.;
|
||||
let origin_y = 20.;
|
||||
|
||||
let cur_size = crate::TerminalSize::new(
|
||||
line_height,
|
||||
cell_width,
|
||||
gpui::geometry::vector::vec2f(term_width, term_height),
|
||||
);
|
||||
|
||||
let mouse_pos = gpui::geometry::vector::vec2f(mouse_pos_x, mouse_pos_y);
|
||||
let origin = gpui::geometry::vector::vec2f(origin_x, origin_y); //Position of terminal window, 1 'cell' in
|
||||
let mouse_pos = mouse_pos - origin;
|
||||
let point = grid_point(mouse_pos, cur_size, 0);
|
||||
assert_eq!(
|
||||
point,
|
||||
alacritty_terminal::index::Point::new(
|
||||
alacritty_terminal::index::Line(((mouse_pos_y - origin_y) / line_height) as i32),
|
||||
alacritty_terminal::index::Column(((mouse_pos_x - origin_x) / cell_width) as usize),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue