vcom/internal/tui/keys/layout.go
vrubelroman 526ba9270f feat(tui): key registry with contexts, layout translation and chords (6.1.1)
ActionIDs bound per input context; Browse/Info table from design §8.1,
modal and viewer contexts. ЙЦУКЕН keys are translated for command
contexts only, text contexts pass everything but control keys through
(U-P1-5); chords (y y) use a per-context buffer; help and footer are
generated from the table (U-P1-16).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 08:55:59 +03:00

35 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package keys
import (
"unicode"
tea "github.com/charmbracelet/bubbletea"
)
// jcuken maps the Russian ЙЦУКЕН layout to the US QWERTY key in the same
// position (lower case; upper case is derived).
var jcuken = map[rune]rune{
'й': 'q', 'ц': 'w', 'у': 'e', 'к': 'r', 'е': 't', 'н': 'y', 'г': 'u', 'ш': 'i', 'щ': 'o', 'з': 'p',
'х': '[', 'ъ': ']', 'ф': 'a', 'ы': 's', 'в': 'd', 'а': 'f', 'п': 'g', 'р': 'h', 'о': 'j', 'л': 'k',
'д': 'l', 'ж': ';', 'э': '\'', 'я': 'z', 'ч': 'x', 'с': 'c', 'м': 'v', 'и': 'b', 'т': 'n', 'ь': 'm',
'б': ',', 'ю': '.', 'ё': '`',
}
// translate returns the QWERTY key name for a single Cyrillic rune key
// (with alt preserved). Only command contexts use it.
func translate(msg tea.KeyMsg) (string, bool) {
if msg.Type != tea.KeyRunes || len(msg.Runes) != 1 {
return "", false
}
r := msg.Runes[0]
upper := unicode.IsUpper(r)
q, ok := jcuken[unicode.ToLower(r)]
if !ok {
return "", false
}
if upper {
q = unicode.ToUpper(q)
}
k := tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{q}, Alt: msg.Alt}
return k.String(), true
}