remove termion: inhouse key parsing
replace blake2 with sha512, fix C and D in romono, minor terminal and audio player fixes
This commit is contained in:
@@ -8,7 +8,5 @@ edition = "2021"
|
||||
[dependencies]
|
||||
ming-wm-lib = { path = "../ming-wm-lib" }
|
||||
linux = { path = "linux" }
|
||||
blake2 = { version = "0.10.6", default-features = false }
|
||||
termion = { version = "4.0.3" }
|
||||
bitcoin_hashes = { version = "0.16.0", default-features = false }
|
||||
bmp-rust = "0.5.0"
|
||||
|
||||
|
||||
@@ -1 +1,89 @@
|
||||
//
|
||||
use std::io::{ Read, Stdin };
|
||||
use std::sync::mpsc::{ channel, Receiver };
|
||||
use std::thread;
|
||||
|
||||
//includes a section on reading keys
|
||||
//https://viewsourcecode.org/snaptoken/kilo/02.enteringRawMode.html
|
||||
|
||||
const ALPHABET: [char; 26] = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
|
||||
|
||||
pub enum Key {
|
||||
Char(char),
|
||||
Alt(char),
|
||||
Ctrl(char),
|
||||
Backspace,
|
||||
Esc,
|
||||
ArrowUp,
|
||||
ArrowDown,
|
||||
ArrowLeft,
|
||||
ArrowRight,
|
||||
Other(u8), //we don't get about anything else, lmao
|
||||
}
|
||||
|
||||
pub struct RawStdin {
|
||||
//bytes: Peekable<Bytes<StdinLock<'a>>>,
|
||||
receiver: Receiver<u8>,
|
||||
}
|
||||
|
||||
impl RawStdin {
|
||||
pub fn new(stdin: Stdin) -> Self {
|
||||
let (sender, receiver) = channel();
|
||||
thread::spawn(move || {
|
||||
let bytes = stdin.lock().bytes();
|
||||
for b in bytes {
|
||||
sender.send(b.unwrap()).unwrap();
|
||||
}
|
||||
});
|
||||
RawStdin {
|
||||
//bytes: stdin.lock().bytes().peekable(),
|
||||
receiver,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Iterator for RawStdin {
|
||||
type Item = Key;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let first = self.receiver.recv().unwrap();
|
||||
Some(match first {
|
||||
1..=26 => {
|
||||
//ctrl
|
||||
if first == 9 {
|
||||
Key::Char('\t')
|
||||
} else if first == 13 {
|
||||
//ctrl+m and enter give the same thing
|
||||
Key::Char('\n')
|
||||
} else {
|
||||
Key::Ctrl(ALPHABET[first as usize - 1])
|
||||
}
|
||||
},
|
||||
27 => {
|
||||
//escape sequence
|
||||
//not handling escape sequences that are 3+ bytes is probably going to come back to bite us
|
||||
let n = self.receiver.try_recv();
|
||||
if let Ok(b'[') = n {
|
||||
let n = self.receiver.recv().unwrap();
|
||||
match n {
|
||||
b'A' => Key::ArrowUp,
|
||||
b'B' => Key::ArrowDown,
|
||||
b'C' => Key::ArrowRight,
|
||||
b'D' => Key::ArrowLeft,
|
||||
_ => Key::Other(n),
|
||||
}
|
||||
} else if n.is_ok() {
|
||||
//Alt+<char> sends Esc+<char>
|
||||
Key::Alt(char::from(n.unwrap()))
|
||||
} else {
|
||||
Key::Esc
|
||||
}
|
||||
},
|
||||
127 => {
|
||||
Key::Backspace
|
||||
},
|
||||
_ => {
|
||||
Key::Char(char::from(first))
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
pub mod fb;
|
||||
pub mod raw;
|
||||
pub mod keys;
|
||||
|
||||
@@ -5,7 +5,7 @@ use ming_wm_lib::framebuffer_types::Dimensions;
|
||||
use ming_wm_lib::themes::ThemeInfo;
|
||||
use ming_wm_lib::messages::{ WindowMessage, WindowMessageResponse, WindowManagerRequest };
|
||||
use ming_wm_lib::window_manager_types::{ DrawInstructions, WindowLike, WindowLikeType };
|
||||
use blake2::{ Blake2b512, Digest };
|
||||
use bitcoin_hashes::Sha512;
|
||||
|
||||
//const PASSWORD_HASH: [u8; 64] = [220, 88, 183, 188, 240, 27, 107, 181, 58, 191, 198, 170, 114, 38, 7, 148, 6, 179, 75, 128, 231, 171, 172, 220, 85, 38, 36, 113, 116, 146, 70, 197, 163, 179, 158, 192, 130, 53, 247, 48, 47, 209, 95, 96, 179, 211, 4, 122, 254, 127, 21, 165, 139, 199, 151, 226, 216, 176, 123, 41, 194, 221, 58, 69];
|
||||
|
||||
@@ -25,9 +25,7 @@ impl WindowLike for LockScreen {
|
||||
WindowMessage::KeyPress(key_press) => {
|
||||
if key_press.is_enter() {
|
||||
//check password
|
||||
let mut hasher = Blake2b512::new();
|
||||
hasher.update((self.input_password.clone() + "salt?sorrycryptographers").as_bytes());
|
||||
if hasher.finalize() == self.password_hash.into() {
|
||||
if Sha512::hash((self.input_password.clone() + "salt?sorrycryptographers!1!").as_bytes()).to_byte_array() == self.password_hash {
|
||||
WindowMessageResponse::Request(WindowManagerRequest::Unlock)
|
||||
} else {
|
||||
self.input_password = String::new();
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
pub use linux;
|
||||
pub use termion;
|
||||
|
||||
pub mod framebuffer;
|
||||
pub mod window_manager;
|
||||
|
||||
Reference in New Issue
Block a user