Skip to content

Commit 472e78b

Browse files
committed
example(keyboard): show a pointer cursor when hovering keys
Declares cursor: "pointer" on each key and enables trackCursor, writing the returned OSC 22 bytes so the mouse pointer turns into a hand over the keys and reverts elsewhere.
1 parent 6f6e0be commit 472e78b

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

examples/keyboard/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,19 @@ await main(function* () {
137137
pointer.state = undefined;
138138
}
139139

140-
let { output, events } = term.render(keyboard(context), {
140+
let { output, events, cursor } = term.render(keyboard(context), {
141141
pointer: pointer.state,
142+
trackCursor: true,
142143
});
143144

144145
for (let event of events) {
145146
yield* pointer.events.send(event);
146147
}
147148

148149
writeStdout(output);
150+
if (cursor) {
151+
writeStdout(cursor);
152+
}
149153

150154
yield* each.next();
151155
}
@@ -229,6 +233,7 @@ function key(ops: Op[], k: KeyDef, ctx: AppContext): void {
229233
alignY: "center",
230234
},
231235
bg,
236+
cursor: "pointer",
232237
border: hover
233238
? { color: highlight, left: 1, right: 1, top: 1, bottom: 1 }
234239
: undefined,

0 commit comments

Comments
 (0)