@teaui/core
Version:
A high-level terminal UI library for Node
39 lines • 1.04 kB
JavaScript
import { View } from '../View.js';
import { Size } from '../geometry.js';
import { toHotKeyDef, } from '../events/index.js';
export class HotKey extends View {
#hotKey = { char: '' };
#label;
#onPress;
constructor(props) {
super(props);
this.#update(props);
}
update(props) {
this.#update(props);
super.update(props);
}
#update({ hotKey, label, onPress }) {
this.#hotKey = hotKey;
this.#label = label;
this.#onPress = onPress;
}
get hotKey() {
return this.#hotKey;
}
get label() {
return this.#label;
}
naturalSize(_available) {
return Size.zero;
}
receiveKey(event) {
this.#onPress?.(event);
}
render(viewport) {
// Always register the hotkey — HotKey is non-visual (naturalSize is zero),
// so the viewport will always be empty, but we still need to register.
viewport.registerHotKey(toHotKeyDef(this.#hotKey));
}
}
//# sourceMappingURL=HotKey.js.map