is this macro at all necessary

probably not
parse-tree
Jordan Orelli 2 years ago
parent 592ebf6e3a
commit cd494d0f76

2
.gitignore vendored

@ -1 +1 @@
/target
target

5
Cargo.lock generated

@ -23,6 +23,10 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "macros"
version = "0.0.0"
[[package]]
name = "proc-macro2"
version = "1.0.51"
@ -84,6 +88,7 @@ version = "0.1.0"
dependencies = [
"anyhow",
"log",
"macros",
"thiserror",
"windows",
]

@ -2,12 +2,17 @@
name = "wash"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
# [workspace]
# members = [
# "macros"
# ]
[dependencies]
anyhow = "1.0"
thiserror = "1.0"
macros = { path = "macros" }
log = "0.4"

7
macros/Cargo.lock generated

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "macros"
version = "0.0.0"

@ -0,0 +1,7 @@
[package]
name = "macros"
version = "0.0.0"
edition = "2021"
[lib]
proc-macro = true

@ -0,0 +1,36 @@
use proc_macro::{
TokenStream,
TokenTree::{self, Ident, Literal},
};
fn next_pair<I: Iterator<Item=TokenTree>>(tokens: &mut I) -> Option<(TokenTree, TokenTree)> {
match (tokens.next(), tokens.next()) {
(Some(a), Some(b)) => Some((a, b)),
_ => None,
}
}
struct Escape {
sequence: String,
name: String,
}
#[proc_macro]
pub fn escapes(tokens: TokenStream) -> TokenStream {
let mut it = tokens.into_iter();
let mut pairs: Vec<Escape> = Vec::new();
while let Some(pair) = next_pair(&mut it) {
match (pair.0, pair.1) {
(Literal(seq), Ident(ident)) => {
pairs.push(Escape{
sequence: seq.to_string(),
name: ident.to_string(),
})
},
_ => panic!("bad escapes"),
}
}
TokenStream::new()
}

@ -2,6 +2,7 @@ use crate::{error::Error, key, log::*};
use anyhow::{Context, Result};
use windows::Win32::Foundation::HANDLE;
use windows::Win32::System::Console;
use macros::escapes;
#[allow(dead_code)]
fn log_input_mode(mode: Console::CONSOLE_MODE) {
@ -102,6 +103,8 @@ pub struct Reader {
buf_len: u32,
// the position of our current indexer into the input record buffer
buf_idx: usize,
ctrl: bool,
}
impl Reader {
@ -111,6 +114,7 @@ impl Reader {
buf_len: 0,
buf_idx: 0,
input: stdin_handle()?,
ctrl: false,
};
v.reset()?;
Ok(v)
@ -155,6 +159,10 @@ impl Reader {
if event.wVirtualKeyCode == 0 && event.uChar.UnicodeChar == 27 {
return Ok(self.next_escape_sequence()?);
}
if event.wVirtualKeyCode == 17 {
self.ctrl = event.bKeyDown.as_bool();
debug!("ctrl {}", event.bKeyDown.as_bool());
}
}
}
Ok(rec.into())
@ -372,3 +380,41 @@ impl From<Console::INPUT_RECORD> for Event {
}
}
}
escapes! {
"[A" Up
"[B" Down
"[C" Right
"[D" Left
"[H" Home
"[F" End
"[3~" Delete
"[5~" PageUp
"[6~" PageDown
"[13;2u" Shift_Enter
"[13;5u" Ctrl_Enter
"[13;6u" Ctrl_Shift_Enter
"[1;2P" Shift_F1
"[1;2Q" Shift_F2
"[1;5P" Ctrl_F1
"[1;6P" Ctrl_Shift_F1
"[1;3P" Alt_F1
"[1;4P" Shift_Alt_F1
"OP" F1
"OQ" F2
"OR" F3
"OS" F4
"[15~" F5
"[15;2~" Shift_F5
"[17~" F6
"[18~" F7
"[19~" F8
"[24~" F12
"[53;5u" Ctrl_Shift_5
}
/*
*/

Loading…
Cancel
Save