Skip to content

Emoji and Wide Unicode Char Support (i.e. Asian characters) - #6

Merged
mitchellh merged 16 commits into
mainfrom
emoji
Aug 21, 2022
Merged

mitchellh merged 16 commits into
mainfrom
emoji

Conversation

@mitchellh

Copy link
Copy Markdown
Contributor

Many changes to support emoji and wide chars:

  • Freetype built with libpng support (some emoji font use pngs)
  • Introduced font.FallbackSet structure for looking for glyphs in multiple fonts so we can find emojis
  • Texture atlas supports 3 and 4 channel colors (RGB/RGBA, although emojis are in BGRA)
  • font.Face supports loading colored fonts and glyphs
  • font.Face supports fonts that do not support variable pixel sizes
  • Shader supports two textures (greyscale and colored)
  • Shader will downsample glyphs that don't fit into the cell size because some fixed size emoji fonts are large
  • Shader supports wide (2x) cells across all types: cursor, fg, bg, underline
  • Terminal state supports detecting and managing wide (2x) chars by looking them up in the Unicode EastAsianWidth database and populating "spacer" cells.
  • Selection (and clipboard ops) support wide chars
CleanShot.2022-08-20.at.17.21.52.mp4

@mitchellh
mitchellh merged commit 235146c into main Aug 21, 2022
@mitchellh
mitchellh deleted the emoji branch August 21, 2022 00:34
mitchellh added a commit that referenced this pull request Feb 18, 2026
This PR introduces unit tests and a supporting Mock NSView for testing
the SplitTree implementation in Swift. It includes 51 tests which
achieve approximately 93.13% (949/1019) coverage of SplitTree.swift's
branches.

<details>
  <summary>Coverage</summary>
  <pre>
./ghostty/macos/Sources/Features/Splits/SplitTree.swift 93.13%
(949/1019)
SplitTree.Path.isEmpty.getter 100.00% (1/1)
SplitTree.isEmpty.getter 100.00% (3/3)
SplitTree.isSplit.getter 100.00% (3/3)
SplitTree.init() 100.00% (3/3)
SplitTree.init(view:) 100.00% (3/3)
SplitTree.contains(_:) 100.00% (4/4)
SplitTree.inserting(view:at:direction:) 100.00% (6/6)
SplitTree.find(id:) 100.00% (4/4)
SplitTree.removing(_:) 93.75% (15/16)
SplitTree.replacing(node:with:) 93.75% (15/16)
SplitTree.focusTarget(for:from:) 82.14% (46/56)
closure #1 in SplitTree.focusTarget(for:from:) 100.00% (1/1)
closure #2 in SplitTree.focusTarget(for:from:) 100.00% (1/1)
closure #3 in SplitTree.focusTarget(for:from:) 100.00% (3/3)
implicit closure #1 in SplitTree.focusTarget(for:from:) 0.00% (0/1)
SplitTree.equalized() 100.00% (5/5)
SplitTree.resizing(node:by:in:with:) 92.00% (69/75)
closure #1 in SplitTree.resizing(node:by:in:with:) 100.00% (1/1)
SplitTree.viewBounds() 100.00% (4/4)
SplitTree.init(from:) 76.00% (19/25)
SplitTree.encode(to:) 100.00% (15/15)
SplitTree.Node.find(id:) 100.00% (13/13)
SplitTree.Node.node(view:) 88.89% (16/18)
SplitTree.Node.path(to:) 100.00% (32/32)
search #1 <A>(_:) in SplitTree.Node.path(to:) 100.00% (27/27)
SplitTree.Node.node(at:) 89.47% (17/19)
SplitTree.Node.inserting(view:at:direction:) 86.84% (33/38)
SplitTree.Node.replacingNode(at:with:) 100.00% (43/43)
replaceInner #1 <A>(current:pathOffset:) in
SplitTree.Node.replacingNode(at:with:) 96.67% (29/30)
SplitTree.Node.remove(_:) 70.27% (26/37)
implicit closure #1 in SplitTree.Node.remove(_:) 100.00% (1/1)
SplitTree.Node.resizing(to:) 100.00% (16/16)
SplitTree.Node.leftmostLeaf() 87.50% (7/8)
SplitTree.Node.rightmostLeaf() 87.50% (7/8)
SplitTree.Node.equalize() 100.00% (4/4)
SplitTree.Node.equalizeWithWeight() 100.00% (30/30)
SplitTree.Node.weightForDirection(_:) 83.33% (10/12)
SplitTree.Node.calculateViewBounds(in:) 100.00% (50/50)
SplitTree.Node.viewBounds() 100.00% (26/26)
SplitTree.Node.spatial(within:) 100.00% (18/18)
SplitTree.Node.dimensions() 80.77% (21/26)
SplitTree.Node.spatialSlots(in:) 100.00% (53/53)
SplitTree.Spatial.slots(in:from:) 100.00% (47/47)
closure #1 in SplitTree.Spatial.slots(in:from:) 100.00% (1/1)
distance #1 <A>(from:to:) in SplitTree.Spatial.slots(in:from:) 100.00%
(6/6)
closure #2 in SplitTree.Spatial.slots(in:from:) 100.00% (3/3)
implicit closure #1 in closure #2 in SplitTree.Spatial.slots(in:from:)
100.00% (1/1)
closure #3 in SplitTree.Spatial.slots(in:from:) 100.00% (3/3)
closure #4 in SplitTree.Spatial.slots(in:from:) 100.00% (3/3)
implicit closure #1 in closure #4 in SplitTree.Spatial.slots(in:from:)
100.00% (1/1)
closure #5 in SplitTree.Spatial.slots(in:from:) 100.00% (3/3)
closure #6 in SplitTree.Spatial.slots(in:from:) 100.00% (3/3)
implicit closure #1 in closure #6 in SplitTree.Spatial.slots(in:from:)
100.00% (1/1)
closure #7 in SplitTree.Spatial.slots(in:from:) 100.00% (3/3)
closure #8 in SplitTree.Spatial.slots(in:from:) 100.00% (3/3)
implicit closure #1 in closure #8 in SplitTree.Spatial.slots(in:from:)
100.00% (1/1)
closure #9 in SplitTree.Spatial.slots(in:from:) 100.00% (3/3)
SplitTree.Spatial.doesBorder(side:from:) 100.00% (20/20)
closure #1 in SplitTree.Spatial.doesBorder(side:from:) 100.00% (1/1)
closure #2 in SplitTree.Spatial.doesBorder(side:from:) 100.00% (3/3)
static SplitTree.Node.== infix(_:_:) 100.00% (13/13)
SplitTree.Node.init(from:) 66.67% (12/18)
SplitTree.Node.encode(to:) 100.00% (11/11)
SplitTree.Node.leaves() 100.00% (9/9)
SplitTree.makeIterator() 100.00% (3/3)
implicit closure #1 in SplitTree.makeIterator() 100.00% (1/1)
SplitTree.Node.makeIterator() 0.00% (0/3)
SplitTree.startIndex.getter 100.00% (3/3)
SplitTree.endIndex.getter 100.00% (3/3)
implicit closure #1 in SplitTree.endIndex.getter 100.00% (1/1)
SplitTree.subscript.getter 100.00% (5/5)
implicit closure #1 in SplitTree.subscript.getter 100.00% (1/1)
implicit closure #2 in implicit closure #1 in SplitTree.subscript.getter
100.00% (1/1)
implicit closure #3 in SplitTree.subscript.getter 0.00% (0/1)
implicit closure #4 in SplitTree.subscript.getter 0.00% (0/1)
SplitTree.index(after:) 100.00% (4/4)
implicit closure #1 in SplitTree.index(after:) 100.00% (1/1)
implicit closure #2 in SplitTree.index(after:) 0.00% (0/1)
SplitTree.Node.structuralIdentity.getter 100.00% (3/3)
SplitTree.Node.StructuralIdentity.init(_:) 100.00% (3/3)
static SplitTree.Node.StructuralIdentity.== infix(_:_:) 100.00% (3/3)
SplitTree.Node.StructuralIdentity.hash(into:) 100.00% (3/3)
SplitTree.Node.isStructurallyEqual(to:) 100.00% (18/18)
implicit closure #1 in SplitTree.Node.isStructurallyEqual(to:) 100.00%
(1/1)
implicit closure #2 in SplitTree.Node.isStructurallyEqual(to:) 100.00%
(1/1)
SplitTree.Node.hashStructure(into:) 100.00% (14/14)
SplitTree.structuralIdentity.getter 100.00% (3/3)
SplitTree.StructuralIdentity.init(_:) 100.00% (4/4)
static SplitTree.StructuralIdentity.== infix(_:_:) 100.00% (4/4)
implicit closure #1 in static SplitTree.StructuralIdentity.==
infix(_:_:) 100.00% (1/1)
SplitTree.StructuralIdentity.hash(into:) 80.00% (8/10)
static SplitTree.StructuralIdentity.areNodesStructurallyEqual(_:_:)
90.00% (9/10)
  </pre>
</details>

I chose this as a good place to start contributing to Ghostty because I
was curious about the macOS implementation, and there was a specific
request for help with testing (#7879).

My process for writing the tests was basically reading
[SplitTree.swift](./macos/Sources/Features/Splits/SplitTree.swift) to
understand it, then writing tests for each high-level method and
checking against code coverage to capture all the code paths:

## Running
```bash
rm -rf /tmp/ghostty-test.xcresult
xcodebuild -project macos/Ghostty.xcodeproj \
    -scheme GhosttyTest \
    -configuration Debug \
    test \
    -destination 'platform=macOS' \
    -enableCodeCoverage YES \
    -resultBundlePath /tmp/ghostty-test.xcresult \
    -only-testing:GhosttyTests/SplitTreeTests \
    2>&1 | xcbeautify
```

## Coverage
```bash
xcrun xccov view --report /tmp/ghostty-test.xcresult | grep 'SplitTree\.'
```

This was originally implemented in [~38
commits](https://github.com/pouwerkerk/ghostty/pull/1/commits), but I
squashed them down to 1 commit for easier review.

## AI Disclosure
The tests were written by me, but I used Opus 4.6 to explain some parts
of the code, and then finally to provide feedback on the tests. It
suggested tests for `nodeStructuralIdentityInSet` and
`nodeStructuralIdentityDistinguishesLeaves` as well as [the
Parameterized
test](pouwerkerk@6a0bca4),
`resizingAdjustsRatio`, which seemed like a clever way to collapse 12
individual tests into 3 parameterized ones that still run 12 cases
total. I didn't know this feature existed, and it seems like a great way
to write tests that are more maintainable. I read this relatively new
feature in the [Swift
Docs](https://developer.apple.com/documentation/testing/parameterizedtesting).
I find this to be a particularly useful feature of Claude/related
agents, where it can suggest better ways of writing something in a more
idiomatic way, and it taught me something new, which is always fun.

I'm more than happy to continue work on tests for #7879 and always
welcome to any feedback you have.
kkilchrist pushed a commit to kkilchrist/ghostty-applescript that referenced this pull request Mar 3, 2026
Add "Display session time" setting to Worktrunk
billxc added a commit to billxc/ghostty that referenced this pull request Apr 30, 2026
…session persistence, claude-resume)

- Add sections 2.15-2.18: Quick Commands editor, tab drag reorder,
  reuseTab, Claude session persistence
- Update stats: 85 commits, 44 files, +5016/-57
- Add new files to file list (ClaudeSessionPersistence, QuickCommandDefaults,
  QuickCommandsEditor, claude-resume)
- Add technical decisions 4.6 (shellIsIdle) and 4.7 (save timing)
- Add known limitation ghostty-org#6 (24h session timeout)
ren18161849172-byte added a commit to ren18161849172-byte/ghostty that referenced this pull request May 7, 2026
Wire Win32 keyboard events to CoreSurface.keyCallback via
WM_KEYDOWN/WM_KEYUP with ToUnicode for text translation and
full VK-to-Key mapping (letters, digits, F-keys, arrows, numpad,
OEM symbols). Skip TranslateMessage for keyboard messages to
preserve dead key state.

Also adds WM_SIZE -> sizeCallback for terminal resize, focus
callbacks (WM_SETFOCUS/WM_KILLFOCUS), window title updates via
set_title action, and close/exit handling for child process exit.
ren18161849172-byte added a commit to ren18161849172-byte/ghostty that referenced this pull request May 7, 2026
When the window is minimized, WM_SIZE sends width=0, height=0.
Passing zero dimensions through the resize pipeline would cause
ResizePseudoConsole(0, 0) and glViewport(0, 0) — both invalid.

The resize pipeline (WM_SIZE → viewport → sizeCallback → renderer resize →
ConPTY resize) was already wired from issues ghostty-org#5 and ghostty-org#6. This fix adds the
minimize guard that prevents corruption on minimize/restore.

Resolves: ghostty-org#7
DAmesberger added a commit to DAmesberger/ghostty that referenced this pull request May 22, 2026
Four open items from the consolidated reviewer brief.

Issue ghostty-org#1 (MUST FIX) — broadcastConnectionState lock-nesting
SshConnectionManager.zig:720 nested listener_mutex inside surfaces_mutex
even though both the design and the commit message documented them as
independent. Scope-block the surface fan-out so its defer releases
surfaces_mutex before listener_mutex is acquired. Also adopt the
stricter posture: dupe the listeners slice under listener_mutex and
release the lock BEFORE invoking callbacks — listeners that re-enter
the listener API from inside on_state (e.g. an embedder that
unregisters from its own callback) would otherwise deadlock.
Allocation-failure fallback iterates under the lock with the deadlock
risk documented inline.

Issue ghostty-org#2 (MUST FIX) — ssh_listeners leak in SshConnectionManager.release
The Entry-teardown path on `release` (last ref dropped) destroyed the
Entry without deinit'ing ssh_listeners — only Manager.deinit at app
shutdown cleaned them up. Long-running session-manager processes
leaked the ArrayListUnmanaged backing buffer once per Entry. Added
the deinit call immediately before entry destroy.

Issue ghostty-org#3 (MUST FIX) — translateState dangling password.host pointer
The password_required prong was returning a State whose host pointer
referenced the switch-prong local's stack frame, which is dead as
soon as translateState returns. The fix:

  * translateState's password_required branch now returns
    `host = ""` (no dangling pointer, exhaustive testing still passes).
  * New helper SshHandle.emitStateFromConnectionState() runs
    translateState, then for password_required copies the host
    bytes from the ConnectionState argument (whose lifetime extends
    through the broadcast call) into a handle-owned stable buffer
    (`last_password_host: [129]u8`) under SshHandle.mutex, NUL-
    terminates, rewrites state.payload.password.host to point at
    the stable storage, and only THEN releases the mutex before
    firing the embedder callback. Buffer lifetime: valid for the
    callback duration AND until the next PASSWORD_REQUIRED arrives.
  * Mutex released BEFORE the callback so embedders can call
    entry points (which take SshHandle.mutex) from inside on_state
    without deadlocking. Two concurrent password_required broadcasts
    on the same handle are impossible today because the manager
    serializes listener fan-out on the SSH thread.
  * onStateListener now uses the new helper.
  * Regression test forces stack reuse between the broadcast call
    and the host-bytes assertion — distinctive 0xAB pattern written
    into an 8 KiB stack frame after the broadcast returns. The
    embedder's recorded copy must still equal the input host.
  * Second test asserts the buffer survives across a non-password
    state (e.g. CONNECTED) and is rewritten by a subsequent
    PASSWORD_REQUIRED, locking down the documented lifetime.
  * Old "carries host" test rewritten to assert translateState
    alone returns "" for the host (catches re-introduction of the
    dangling pointer at the source).

Issue ghostty-org#6 (MUST FIX) — threading doc widening for synchronous FAILED
ghostty_ssh_open emits emitState(.failed) synchronously on four error
branches (mgr.acquire, dupe(target), dupe(jump), registerStateListener)
before returning, but the threading exception paragraph only mentioned
the initial CONNECTING. Broadened the wording in three places — the
THREADING & OWNERSHIP RULES preamble in include/ghostty.h, the
ghostty_ssh_open declaration comment, and the mirrored module doc
block in ssh_capi.zig — to call out that FAILED transitions may also
fire synchronously on the open caller's thread.

Build verification: aarch64-linux-gnu cross-compile, app-runtime=none
→ 87/87 steps succeeded. Daemon target → 83/83 succeeded. C header
syntax check via `cc -fsyntax-only -Wall -x c` clean. Zig
ast-check clean on both edited Zig files. macOS test target
remains blocked on the pre-existing Metal Toolchain gap; the new
tests will run on reviewer's metal-equipped CI.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
DAmesberger added a commit to DAmesberger/ghostty that referenced this pull request May 22, 2026
Until now the Swift SSH wrapper was only verified via standalone
`swiftc -typecheck` of an isolated module slice — which used a
different setup than the actual Ghostty Xcode target. Native
`zig build test` (now runnable with the Metal Toolchain installed)
compiles the wrapper into the real app and runs GhosttyTests; that
exposed real bugs the isolated typecheck never could.

Fixes, in the order the build surfaced them:

1. LibghosttySSHAPI.sshOpen field declared its first param as a
   non-optional `ghostty_app_t`. The real `ghostty_ssh_open` imports
   with `ghostty_app_t?` — C pointer params import nullable unless the
   header annotates `_Nonnull`. Assigning the real symbol into the
   field was a hard @convention(c) signature mismatch. First param is
   now `ghostty_app_t?`.

2. SSHConnection.init took `app: ghostty_app_t` (non-optional). The
   two integration tests passed a bogus non-null pointer (0xDEADBEEF)
   as a fake app — fine against the old no-op stub, but 6B.1 wired
   ghostty_ssh_open to a real SshConnectionManager resolved by
   dereferencing the app pointer, so the garbage pointer crashed the
   whole xctest runner. init now takes `app: ghostty_app_t?`; the
   tests pass `nil`, which keeps libghostty on its documented
   no-CoreApp stub path (synchronous CONNECTING emit).

3. The on_state trampoline that fires the synchronous CONNECTING from
   inside ghostty_ssh_open resolved `self` from the userdata box — but
   init attached the box only AFTER ghostty_ssh_open returned, so the
   first state transition was dropped and the AsyncStream consumer
   hung. `handle` is now `var ghostty_ssh_t?` (matching SSHChannel's
   existing pattern) so the box can attach to `self` before the C
   open call; `handle` is stamped after, read via `requireHandle()`.

4. ChannelBox.finishAll() finished the output stream but never the
   events stream — it dropped the event-forwarder closure without
   calling `evtCont.finish()`. After on_close, a consumer's
   `for await ev in channel.events` loop never exited. The box now
   stores a paired `eventFinish` closure and finishes both streams.

Routed every C entry point (Connection/Channel/CallbackTrampoline)
through the new `LibghosttySSHAPI` indirection table — the production
default points at the real libghostty symbols; the table exists so a
future mock-libghostty test target (task ghostty-org#6 remaining scope) can swap
it without linker tricks. A handle counter gates the test-only
install/uninstall so the table can't be swapped under a live handle.

Verified: native `zig build test` exits 0; direct `xcodebuild test`
reports TEST SUCCEEDED with 193/194 passing (1 platform skip),
including all SSHTests integration tests.

The mock-libghostty test target itself (reconnect-contract test,
1 MB/64 KB backpressure test) remains task ghostty-org#6's outstanding scope and
follows once this real-compile gate is green.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant