[READ-ONLY] Mirror of https://github.com/bombshell-dev/tty. Platform independent 2D layout engine for terminal applications based on Clay
5

Configure Feed

Select the types of activity you want to include in your feed.

Add ability to capture mouse events

Charles Lowell (Mar 30, 2026, 12:15 PM -0500) d6bef782 8a4aa01e

+33 -3
+33 -3
demo/keyboard.ts
··· 380 380 close(), 381 381 text(` ${badgeHint}`, { color: dim }), 382 382 close(), 383 + open("box", { layout: { height: fixed(1) } }), 384 + close(), 385 + ); 386 + 387 + // mouse capture badge 388 + let mouseBg = ctx["Capture mouse events"] ? rgba(40, 180, 80) : rgba(80, 80, 80); 389 + let mouseLabel = ctx["Capture mouse events"] ? "capture" : "system"; 390 + ops.push( 391 + open("box", { layout: { direction: "ltr", height: fixed(1), padding: { bottom: 1 } } }), 392 + open("box", { layout: { padding: { left: 1, right: 1 } }, bg: rgba(60, 60, 60) }), 393 + text("mouse", { color: rgba(220, 220, 220) }), 394 + close(), 395 + open("box", { layout: { padding: { left: 1, right: 1 } }, bg: mouseBg }), 396 + text(mouseLabel, { color: rgba(255, 255, 255) }), 397 + close(), 398 + text(" Ctrl+X Ctrl+M to toggle", { color: dim }), 399 + close(), 383 400 ); 384 401 385 402 // toggles right-aligned above keyboard ··· 442 459 if (ctx["Report alternate keys"]) bits |= 4; 443 460 if (ctx["Report all keys as escapes"]) bits |= 8; 444 461 if (ctx["Report associated text"]) bits |= 16; 445 - return encoder.encode(`\x1b[<u\x1b[>${bits}u`); 462 + let mouse = ctx["Capture mouse events"] 463 + ? "\x1b[?1003h\x1b[?1006h" 464 + : "\x1b[?1003l\x1b[?1006l"; 465 + return encoder.encode(`\x1b[<u\x1b[>${bits}u${mouse}`); 446 466 } 447 467 448 468 await main(function* () { ··· 459 479 460 480 esc("\x1b[?1049h\x1b[?25l\x1b[>3u"); 461 481 yield* ensure(() => { 462 - esc("\x1b[<u\x1b[?25h\x1b[?1049l"); 482 + esc("\x1b[?1003l\x1b[?1006l\x1b[<u\x1b[?25h\x1b[?1049l"); 463 483 }); 464 484 465 485 let modality = recognizer(); ··· 491 511 "Report alternate keys": false, 492 512 "Report all keys as escapes": false, 493 513 "Report associated text": false, 514 + "Capture mouse events": false, 494 515 event: null, 495 516 }; 496 517 ··· 522 543 ...context, 523 544 event: null, 524 545 }); 546 + } else if (next.key === "m" && next.ctrl) { 547 + context = { 548 + ...context, 549 + "Capture mouse events": !context["Capture mouse events"], 550 + event: null, 551 + }; 552 + event = yield context; 553 + continue; 525 554 } 526 555 } 527 556 event = yield context; ··· 566 595 567 596 type AppContext = { 568 597 mode: "input" | "config"; 569 - event: InputEvent | null; 598 + event: InputEvent | null; 570 599 ["Disambiguate escape codes"]: boolean; 571 600 ["Report event types"]: boolean; 572 601 ["Report alternate keys"]: boolean; 573 602 ["Report all keys as escapes"]: boolean; 574 603 ["Report associated text"]: boolean; 604 + ["Capture mouse events"]: boolean; 575 605 }; 576 606