Scoop API

scoop:scoop.terminal:0.1.0

src/event/modifiers.scoop

Selected production source · src/event/modifiers.scoop

1package scoop.terminal.event
3/**
4 * A modifier active while a key or mouse event was generated.
5 */
6public enum KeyModifier {
7 /**
8 * The Shift modifier was active for this event.
9 */
10 Shift,
11 /**
12 * The Alt modifier was active for this event.
13 */
14 Alt,
15 /**
16 * The Control modifier was active for this event.
17 */
18 Control,
19 /**
20 * The Super modifier was active for this event.
21 */
22 Super,
23 /**
24 * The Hyper modifier was active for this event.
25 */
26 Hyper,
27 /**
28 * The Meta modifier was active for this event.
29 */
30 Meta
32 internal val mask: UInt get() = when (this) {
33 case Shift -> 1u; case Alt -> 2u; case Control -> 4u
34 case Super -> 8u; case Hyper -> 16u; case Meta -> 32u
35 }
38/**
39 * An immutable bit set of active key modifiers.
40 */
41public struct KeyModifiers(val bits: UInt = 0u) {
42 /**
43 * Whether no bits are set.
44 */
45 public val isEmpty: Boolean get() = bits == 0u
46 /**
47 * Tests whether the selected flag is present.
48 */
49 public fun has(modifier: KeyModifier): Boolean = (bits and modifier.mask) != 0u
50 /**
51 * Returns a copy with the selected flag included.
52 */
53 public fun with(modifier: KeyModifier): KeyModifiers = KeyModifiers(bits or modifier.mask)
54 /**
55 * Returns a copy with the selected flag removed.
56 */
57 public fun without(modifier: KeyModifier): KeyModifiers = KeyModifiers(bits and modifier.mask.inv())
60/**
61 * Additional lock and keypad state reported by an enhanced keyboard protocol.
62 */
63public enum KeyState {
64 /**
65 * The key came from the numeric keypad.
66 */
67 Keypad,
68 /**
69 * Caps Lock was active.
70 */
71 CapsLock,
72 /**
73 * Num Lock was active.
74 */
75 NumLock
77 internal val mask: UInt get() = when (this) {
78 case Keypad -> 1u; case CapsLock -> 2u; case NumLock -> 4u
79 }
82/**
83 * An immutable bit set of additional lock/keypad state.
84 */
85public struct KeyEventState(val bits: UInt = 0u) {
86 /**
87 * Whether no bits are set.
88 */
89 public val isEmpty: Boolean get() = bits == 0u
90 /**
91 * Tests whether the selected flag is present.
92 */
93 public fun has(state: KeyState): Boolean = (bits and state.mask) != 0u
94 /**
95 * Returns a copy with the selected flag included.
96 */
97 public fun with(state: KeyState): KeyEventState = KeyEventState(bits or state.mask)
98 /**
99 * Returns a copy with the selected flag removed.
100 */
101 public fun without(state: KeyState): KeyEventState = KeyEventState(bits and state.mask.inv())