diff --git a/Cargo.toml b/Cargo.toml index 1dc46d0bf..0c6c5e48f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,5 @@ +[workspace] + [package] authors = ["Wez Furlong "] name = "wezterm" @@ -12,9 +14,10 @@ libc = "0.2.36" mio = "0.6.12" resize = "0.3.0" servo-fontconfig = "0.4.0" -unicode-segmentation = "1.2.0" unicode-width = "0.1.4" -vte = "0.3.2" + +[dependencies.term] +path = "term" [dependencies.xcb] features = ["shm"] diff --git a/src/main.rs b/src/main.rs index ff40827a4..7874b26fc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,20 +1,15 @@ -#![feature(slice_patterns)] - #[macro_use] extern crate failure; -#[macro_use] -extern crate bitflags; extern crate unicode_width; -extern crate unicode_segmentation; extern crate harfbuzz_sys; #[cfg(not(target_os = "macos"))] extern crate fontconfig; // from servo-fontconfig #[cfg(not(target_os = "macos"))] extern crate freetype; extern crate resize; -extern crate vte; extern crate libc; extern crate mio; +extern crate term; #[macro_use] pub mod log; @@ -34,7 +29,6 @@ mod xkeysyms; mod font; use font::{Font, FontPattern, ftwrap}; -mod term; mod pty; mod sigchld; mod xwin; diff --git a/src/xkeysyms.rs b/src/xkeysyms.rs index 89f88e9ee..8673eae85 100644 --- a/src/xkeysyms.rs +++ b/src/xkeysyms.rs @@ -195,24 +195,22 @@ pub const XK_asciitilde: xcb_keysym_t = 0x007e; use term::KeyCode; use term::KeyModifiers; -impl From for KeyCode { - fn from(k: xcb_keysym_t) -> Self { - match k { - XK_space...XK_asciitilde => { - // This range overlaps with ascii - KeyCode::Char(k as u8 as char) - } - XK_BackSpace | XK_Tab | XK_Linefeed | XK_Return | XK_Escape => { - KeyCode::Char((k & 0xff) as u8 as char) - } - XK_Control_L | XK_Control_R => KeyCode::Control, - XK_Alt_L | XK_Alt_R => KeyCode::Alt, - XK_Meta_L | XK_Meta_R => KeyCode::Meta, - XK_Super_L | XK_Super_R => KeyCode::Super, - XK_Hyper_L | XK_Hyper_R => KeyCode::Hyper, - XK_Shift_L | XK_Shift_R => KeyCode::Shift, - _ => KeyCode::Unknown, +pub fn xcb_keysym_to_keycode(k: xcb_keysym_t) -> KeyCode { + match k { + XK_space...XK_asciitilde => { + // This range overlaps with ascii + KeyCode::Char(k as u8 as char) } + XK_BackSpace | XK_Tab | XK_Linefeed | XK_Return | XK_Escape => { + KeyCode::Char((k & 0xff) as u8 as char) + } + XK_Control_L | XK_Control_R => KeyCode::Control, + XK_Alt_L | XK_Alt_R => KeyCode::Alt, + XK_Meta_L | XK_Meta_R => KeyCode::Meta, + XK_Super_L | XK_Super_R => KeyCode::Super, + XK_Hyper_L | XK_Hyper_R => KeyCode::Hyper, + XK_Shift_L | XK_Shift_R => KeyCode::Shift, + _ => KeyCode::Unknown, } } diff --git a/src/xwin.rs b/src/xwin.rs index 9bceffe65..18fff220b 100644 --- a/src/xwin.rs +++ b/src/xwin.rs @@ -527,7 +527,7 @@ impl<'a> TerminalWindow<'a> { event, mods.contains(KeyModifiers::SHIFT), ); - (sym.into(), mods) + (xkeysyms::xcb_keysym_to_keycode(sym), mods) } pub fn key_down(&mut self, event: &xcb::KeyPressEvent) -> Result<(), Error> { diff --git a/term/Cargo.toml b/term/Cargo.toml new file mode 100644 index 000000000..19136b674 --- /dev/null +++ b/term/Cargo.toml @@ -0,0 +1,12 @@ +[package] +authors = ["Wez Furlong "] +name = "term" +version = "0.1.0" + +[dependencies] +bitflags = "1.0.1" +failure = "0.1.1" +unicode-segmentation = "1.2.0" +unicode-width = "0.1.4" +vte = "0.3.2" + diff --git a/src/term/color.rs b/term/src/color.rs similarity index 100% rename from src/term/color.rs rename to term/src/color.rs diff --git a/src/term/csi.rs b/term/src/csi.rs similarity index 100% rename from src/term/csi.rs rename to term/src/csi.rs diff --git a/term/src/debug.rs b/term/src/debug.rs new file mode 100644 index 000000000..f557e3e89 --- /dev/null +++ b/term/src/debug.rs @@ -0,0 +1,3 @@ +macro_rules! debug { + ($($arg:tt)*) => (if cfg!(debug_assertions) { println!($($arg)*) }) +} diff --git a/src/term/mod.rs b/term/src/lib.rs similarity index 99% rename from src/term/mod.rs rename to term/src/lib.rs index 2d27b80d1..dbb96b42f 100644 --- a/src/term/mod.rs +++ b/term/src/lib.rs @@ -1,10 +1,20 @@ //! Terminal model +#![feature(slice_patterns)] + +#[allow(unused_imports)] +#[macro_use] +extern crate failure; +#[macro_use] +extern crate bitflags; +extern crate unicode_width; +extern crate unicode_segmentation; +extern crate vte; use failure::Error; -use std; use std::ops::{Deref, DerefMut}; -use unicode_segmentation; -use vte; + +#[macro_use] +mod debug; pub mod color; mod csi; @@ -955,9 +965,9 @@ impl vte::Perform for TerminalState { (b'M', &[], &[]) => self.reverse_index(), // Enable alternate character set mode (smacs) - (b'0', &[b'('], &[]) => {}, + (b'0', &[b'('], &[]) => {} // Exit alternate character set mode (rmacs) - (b'B', &[b'('], &[]) => {}, + (b'B', &[b'('], &[]) => {} (..) => { println!( diff --git a/src/term/test/mod.rs b/term/src/test/mod.rs similarity index 100% rename from src/term/test/mod.rs rename to term/src/test/mod.rs