Compare commits
No commits in common. "4e839d4e2ce83dbc6047744ec6eedaf8c6094c0e" and "9139fa277634d148ec7309942cbdf3b464ad1467" have entirely different histories.
4e839d4e2c
...
9139fa2776
|
@ -667,7 +667,7 @@ dependencies = [
|
|||
"hashbrown 0.14.1",
|
||||
"lock_api",
|
||||
"once_cell",
|
||||
"parking_lot_core 0.9.9",
|
||||
"parking_lot_core 0.9.8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1034,7 +1034,7 @@ dependencies = [
|
|||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.38",
|
||||
"uuid 1.5.0",
|
||||
"uuid 1.4.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1206,16 +1206,16 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "iana-time-zone"
|
||||
version = "0.1.58"
|
||||
version = "0.1.57"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8326b86b6cff230b97d0d312a6c40a60726df3332e721f72a1b035f451663b20"
|
||||
checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613"
|
||||
dependencies = [
|
||||
"android_system_properties",
|
||||
"core-foundation-sys",
|
||||
"iana-time-zone-haiku",
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
"windows-core",
|
||||
"windows",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1378,9 +1378,9 @@ checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f"
|
|||
|
||||
[[package]]
|
||||
name = "lock_api"
|
||||
version = "0.4.11"
|
||||
version = "0.4.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45"
|
||||
checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"scopeguard",
|
||||
|
@ -1791,7 +1791,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
|
||||
dependencies = [
|
||||
"lock_api",
|
||||
"parking_lot_core 0.9.9",
|
||||
"parking_lot_core 0.9.8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1810,13 +1810,13 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "parking_lot_core"
|
||||
version = "0.9.9"
|
||||
version = "0.9.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e"
|
||||
checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"redox_syscall 0.4.1",
|
||||
"redox_syscall 0.3.5",
|
||||
"smallvec",
|
||||
"windows-targets",
|
||||
]
|
||||
|
@ -2074,15 +2074,6 @@ dependencies = [
|
|||
"bitflags 1.3.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_users"
|
||||
version = "0.4.3"
|
||||
|
@ -2096,9 +2087,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.10.2"
|
||||
version = "1.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343"
|
||||
checksum = "aaac441002f822bc9705a681810a4dd2963094b9ca0ddc41cb963a4c189189ea"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
|
@ -2108,9 +2099,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.3"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f"
|
||||
checksum = "5011c7e263a695dc8ca064cddb722af1be54e517a280b12a5356f98366899e5d"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
|
@ -2218,7 +2209,7 @@ dependencies = [
|
|||
"thiserror",
|
||||
"tracing",
|
||||
"url",
|
||||
"uuid 1.5.0",
|
||||
"uuid 1.4.1",
|
||||
"wildmatch",
|
||||
]
|
||||
|
||||
|
@ -2857,9 +2848,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "1.5.0"
|
||||
version = "1.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "88ad59a7560b41a70d191093a945f0b87bc1deeda46fb237479708a1d6b6cdfc"
|
||||
checksum = "79daa5ed5740825c40b389c5e50312b9c86df53fccd33f281df655642b43869d"
|
||||
dependencies = [
|
||||
"getrandom 0.2.10",
|
||||
"wasm-bindgen",
|
||||
|
@ -3045,10 +3036,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.51.1"
|
||||
name = "windows"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64"
|
||||
checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f"
|
||||
dependencies = [
|
||||
"windows-targets",
|
||||
]
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
-- create the required tables under `std`
|
||||
trinitrix.std = {keymaps = {}};
|
||||
|
||||
--- Add a new keymap. This is just a convenience function which registers the function
|
||||
--- and at the same time deals with the fact that the whole trinitrix api is async.
|
||||
-- and at the same time deals with the fact that the whole trinitrix api is async.
|
||||
---@param mode string
|
||||
---@param key string
|
||||
---@param callback function
|
||||
|
@ -24,6 +21,6 @@ trinitrix.std.keymaps.add("n", ":", trinitrix.api.ui.command_line_show)
|
|||
trinitrix.std.keymaps.add("n", "i", trinitrix.api.ui.set_mode_insert)
|
||||
|
||||
-- a simple test to prove that key chords work
|
||||
trinitrix.std.keymaps.add("ni", "jj", function() print("hi") end)
|
||||
trinitrix.std.keymaps.add("n", "jj", function() print("hi") end)
|
||||
|
||||
trinitrix.std.keymaps.add("n", "q", trinitrix.api.exit)
|
||||
|
|
12
flake.lock
12
flake.lock
|
@ -16,11 +16,11 @@
|
|||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1697648018,
|
||||
"narHash": "sha256-C7hHmozOpuG4G6/NAnd0/EE1osAzgIV+6eZbuRYtf5U=",
|
||||
"lastModified": 1697408734,
|
||||
"narHash": "sha256-OVC6KKdeBAfP8NQ+NyatWfuLZNxmrOe7KUB2Qnaes2Y=",
|
||||
"owner": "ipetkov",
|
||||
"repo": "crane",
|
||||
"rev": "bd2e69ee84552b2befe2594060513ea9e01bfeea",
|
||||
"rev": "d4bddd0a8c7c4b634f85d4fe415ee783ee135fd9",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -100,11 +100,11 @@
|
|||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1697595136,
|
||||
"narHash": "sha256-9honwiIeMbBKi7FzfEy89f1ShUiXz/gVxZSS048pKyc=",
|
||||
"lastModified": 1697422411,
|
||||
"narHash": "sha256-eCj20wEwATLm7Bd/+/wOIdbqq9jgvS6ZxMrxujX2DxU=",
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"rev": "a2ccfb2134622b28668a274e403ba6f075ae1223",
|
||||
"rev": "056256f2fcf3c5a652dbc3edba9ec1a956d41f56",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
|
@ -8,6 +8,6 @@ proc-macro = true
|
|||
|
||||
[dependencies]
|
||||
convert_case = "0.6.0"
|
||||
proc-macro2 = "1.0.69"
|
||||
quote = "1.0.33"
|
||||
syn = { version = "2.0.38", features = ["extra-traits", "full", "parsing"] }
|
||||
proc-macro2 = "1.0.64"
|
||||
quote = "1.0.29"
|
||||
syn = { version = "2.0.25", features = ["extra-traits", "full", "parsing"] }
|
||||
|
|
|
@ -12,25 +12,6 @@ use crate::app::{
|
|||
|
||||
pub async fn handle(app: &mut App<'_>, input_event: &CrosstermEvent) -> Result<EventStatus> {
|
||||
async fn default(converted_key: Key, app: &mut App<'_>, old_state: &State) -> Result<()> {
|
||||
info!(
|
||||
"No keymaps exist for key ('{}'), passing it along..",
|
||||
converted_key
|
||||
);
|
||||
if let State::KeyInputPending {
|
||||
old_state: _,
|
||||
pending_keys,
|
||||
} = app.status.state().clone()
|
||||
{
|
||||
for key in pending_keys {
|
||||
app.tx
|
||||
.send(Event::CommandEvent(
|
||||
Command::Trinitrix(Api(Raw(SendInputUnprocessed(key.to_string_repr())))),
|
||||
None,
|
||||
))
|
||||
.await?;
|
||||
}
|
||||
app.status.set_state(old_state.to_owned());
|
||||
}
|
||||
// Just let the input event slip through if no keymap matches
|
||||
app.tx
|
||||
.send(Event::CommandEvent(
|
||||
|
@ -40,6 +21,7 @@ pub async fn handle(app: &mut App<'_>, input_event: &CrosstermEvent) -> Result<E
|
|||
None,
|
||||
))
|
||||
.await?;
|
||||
app.status.set_state(old_state.to_owned());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -83,8 +65,7 @@ pub async fn handle(app: &mut App<'_>, input_event: &CrosstermEvent) -> Result<E
|
|||
if possible_key_maps.len() == 1 {
|
||||
let possible_key_map = possible_key_maps.get(0).expect("The len is 1");
|
||||
|
||||
if possible_key_map.is_child() && possible_key_map.is_terminal() && should_call
|
||||
{
|
||||
if possible_key_map.is_child() && possible_key_map.is_terminal() && should_call {
|
||||
let function = possible_key_map
|
||||
.value()
|
||||
.expect("This node is terminal and a child, it should have a value");
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
use std::{fmt::Display, str::FromStr};
|
||||
use std::{str::FromStr, fmt::Display};
|
||||
|
||||
use anyhow::{bail, Context};
|
||||
use cli_log::{debug, info};
|
||||
use crossterm::event::{Event, KeyCode, KeyEvent, KeyEventKind, KeyEventState, KeyModifiers};
|
||||
use crossterm::event::{Event, KeyEvent, KeyEventKind, KeyEventState, KeyModifiers};
|
||||
|
||||
use super::{Chars, KeyValue, Keys};
|
||||
|
||||
|
@ -237,33 +236,7 @@ impl Into<Event> for Key {
|
|||
}
|
||||
|
||||
let output = Event::Key(KeyEvent {
|
||||
code: {
|
||||
// We sorta hit a edge case here, if we have a shifted char we need to tell
|
||||
// crossterm about that. Thus we need to manually apply the shift modifier on the
|
||||
// value.
|
||||
if self.shift {
|
||||
if let Some(KeyValue::Char(char)) = self.value {
|
||||
let upper_case_char: char = {
|
||||
let chars = char.to_uppercase().collect::<Vec<char>>();
|
||||
if chars.len() != 1 {
|
||||
unimplemented!(
|
||||
"
|
||||
I have no idea how we handle this case,
|
||||
we'll just have to hope, that it never comes up.
|
||||
"
|
||||
);
|
||||
} else {
|
||||
*chars.first().expect("We checked the length")
|
||||
}
|
||||
};
|
||||
KeyCode::Char(upper_case_char)
|
||||
} else {
|
||||
self.value.unwrap_or(KeyValue::Null).into()
|
||||
}
|
||||
} else {
|
||||
self.value.unwrap_or(KeyValue::Null).into()
|
||||
}
|
||||
},
|
||||
code: self.value.unwrap_or(KeyValue::Null).into(),
|
||||
modifiers,
|
||||
kind: KeyEventKind::Press,
|
||||
state: KeyEventState::NONE,
|
||||
|
@ -293,41 +266,8 @@ impl TryFrom<&Event> for Key {
|
|||
|
||||
{
|
||||
let key_code = key_event.code;
|
||||
if output_key.shift {
|
||||
// We need to deal have an edge case for shift, as the value will be in the
|
||||
// shifted form (for example 'A'). If we left that, we would get "<S-A>" as
|
||||
// Key representation, which can't be parsed. So we simply unshift the 'A'
|
||||
// here, turning the representation into: "<S-a>"
|
||||
if let KeyCode::Char(char) = key_code {
|
||||
let lower_case_char: char = {
|
||||
let chars = char.to_lowercase().collect::<Vec<char>>();
|
||||
if chars.len() != 1 {
|
||||
unimplemented!(
|
||||
"
|
||||
I have no idea how we handle this case,
|
||||
we'll just have to hope, that it never comes up.
|
||||
"
|
||||
);
|
||||
} else {
|
||||
*chars.first().expect("We checked the length")
|
||||
}
|
||||
};
|
||||
info!(
|
||||
"Had to translate key ('{}') to it's lowercase variant ('{}')",
|
||||
char, lower_case_char
|
||||
);
|
||||
output_key.value = Some(KeyValue::Char(lower_case_char));
|
||||
} else {
|
||||
debug!(
|
||||
"Key ('{}') is shifted but not a character!",
|
||||
Into::<KeyValue>::into(key_code)
|
||||
);
|
||||
output_key.value = Some(key_code.into());
|
||||
}
|
||||
} else {
|
||||
output_key.value = Some(key_code.into());
|
||||
}
|
||||
}
|
||||
|
||||
Ok(output_key)
|
||||
}
|
||||
|
|
|
@ -45,21 +45,6 @@ mod test {
|
|||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_shift_a() {
|
||||
let keys: Keys = "<S-a>".parse().unwrap();
|
||||
assert_eq!(
|
||||
keys,
|
||||
Keys(vec![Key {
|
||||
alt: false,
|
||||
ctrl: false,
|
||||
meta: false,
|
||||
shift: true,
|
||||
value: Some(KeyValue::Char('a'))
|
||||
}])
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_string_repr() {
|
||||
let key = Key {
|
||||
|
|
|
@ -86,8 +86,8 @@ impl fmt::Display for State {
|
|||
Self::Setup => write!(f, "Setup (!! workaround !!)"),
|
||||
Self::KeyInputPending {
|
||||
old_state: _,
|
||||
pending_keys: keys,
|
||||
} => write!(f, "Key Input Pending: {}", keys),
|
||||
pending_keys: _,
|
||||
} => write!(f, "Key Input Pending"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Reference in New Issue