1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-04 14:26:46 +00:00

Re-enable vim directional keys

This commit is contained in:
Tw93
2025-12-11 16:34:10 +08:00
parent f515a95c66
commit 0d4bbb54dc
2 changed files with 50 additions and 0 deletions

View File

@@ -55,6 +55,10 @@ read_key() {
'm' | 'M') echo "MORE" ;;
'u' | 'U') echo "UPDATE" ;;
't' | 'T') echo "TOUCHID" ;;
'j' | 'J') echo "DOWN" ;;
'k' | 'K') echo "UP" ;;
'h' | 'H') echo "LEFT" ;;
'l' | 'L') echo "RIGHT" ;;
$'\x03') echo "QUIT" ;;
$'\x7f' | $'\x08') echo "DELETE" ;;
$'\x1b')

46
tests/ui_input.bats Normal file
View File

@@ -0,0 +1,46 @@
#!/usr/bin/env bats
setup_file() {
PROJECT_ROOT="$(cd "${BATS_TEST_DIRNAME}/.." && pwd)"
export PROJECT_ROOT
}
setup() {
export MOLE_BASE_LOADED=1 # mock base loaded
# Mocking base functions used in ui.sh if any (mostly spinner/logging stuff, unlikely to affect read_key)
}
@test "read_key maps j/k/h/l to navigation" {
# Source the UI library
source "$PROJECT_ROOT/lib/core/ui.sh"
# Test j -> DOWN
run bash -c "source '$PROJECT_ROOT/lib/core/ui.sh'; echo -n 'j' | read_key"
[ "$output" = "DOWN" ]
# Test k -> UP
run bash -c "source '$PROJECT_ROOT/lib/core/ui.sh'; echo -n 'k' | read_key"
[ "$output" = "UP" ]
# Test h -> LEFT
run bash -c "source '$PROJECT_ROOT/lib/core/ui.sh'; echo -n 'h' | read_key"
[ "$output" = "LEFT" ]
# Test l -> RIGHT
run bash -c "source '$PROJECT_ROOT/lib/core/ui.sh'; echo -n 'l' | read_key"
[ "$output" = "RIGHT" ]
}
@test "read_key maps uppercase J/K/H/L to navigation" {
run bash -c "source '$PROJECT_ROOT/lib/core/ui.sh'; echo -n 'J' | read_key"
[ "$output" = "DOWN" ]
run bash -c "source '$PROJECT_ROOT/lib/core/ui.sh'; echo -n 'K' | read_key"
[ "$output" = "UP" ]
}
@test "read_key respects MOLE_READ_KEY_FORCE_CHAR" {
# When force char is on, j should return CHAR:j
run bash -c "export MOLE_READ_KEY_FORCE_CHAR=1; source '$PROJECT_ROOT/lib/core/ui.sh'; echo -n 'j' | read_key"
[ "$output" = "CHAR:j" ]
}