Files
faumarayandClaude Opus 5.5 c81d4ea666 spikes/gpui/composer: spike 2, the composer, preedit and chat lines
gpui-component's Textarea as the composer (auto-grow, placeholder), emoji
from a picker of voelin-ui-vm's emoji archive inserted at the caret,
pictures and file paths pasted as attachments (Textarea::on_paste),
Ctrl+Enter bound to Send in the Input context after gpui-component's own
bindings. Sample messages go through voelin_ui_vm::chat::line and are drawn
as StyledText with one GPUI text run per TextRun inside InteractiveText,
links clickable (masked ones ask first). The preedit is GPUI's own (XIM on
X11, text-input-v3 on Wayland); the spike reads the marked range and
prints it. drive.sh runs the scenario on the headless display, ime.sh the
X11 preedit with fcitx5 and Pinyin.

From the interrupted attempt, changed here: runs instead of highlights, so
each run has its font (emoji runs in Noto Color Emoji, code in the theme's
monospace font: the row's font_family("monospace") resolved to no
monospace font); a sample line of the smileys DejaVu Sans also has; the
picker in the emoji font; the font probe (whose get_font_for_id printed
"?" for every fallback font) replaced by an emoji probe that counts the
glyphs GPUI draws in colour (ShapedGlyph::is_emoji), printed by drive.sh as
findings for the system's and a Noto-only font configuration.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 01:43:43 +03:00

98 lines
3.3 KiB
Bash
Executable File

#!/bin/sh
# X11 preedit with a CJK input method on the headless display: fcitx5 with
# Pinyin (fcitx5-chinese-addons) as the XIM server, the composer as its
# client (XMODIFIERS=@im=fcitx), "nihao" typed: the preedit must show in
# the input (marked text), Space commits 你好, Ctrl+Enter sends it. fcitx5's
# configuration and state stay in the headless session's XDG directories.
#
# spikes/gpui/shell.sh spikes/gpui/headless.sh -- spikes/gpui/composer/ime.sh
#
# FCITX5: an fcitx5 with the Pinyin addon (default: built from nixpkgs).
set -eu
root=$(cd "$(dirname "$0")/../../.." && pwd)
out=${OUT:-$root/.scratch/gpui-spikes-results}
mkdir -p "$out"
out=$(cd "$out" && pwd)
if [ -z "${FCITX5:-}" ]; then
FCITX5=$(nix build --option substituters "https://cache.nixos.org/ https://nix-community.cachix.org" \
--no-link --print-out-paths --impure --expr \
'let p = (builtins.getFlake "nixpkgs").legacyPackages.x86_64-linux; in p.qt6Packages.fcitx5-with-addons.override { addons = [ p.qt6Packages.fcitx5-chinese-addons ]; }')
fi
mkdir -p "$XDG_CONFIG_HOME/fcitx5"
cat >"$XDG_CONFIG_HOME/fcitx5/profile" <<'PROFILE'
[Groups/0]
Name=Default
Default Layout=us
DefaultIM=pinyin
[Groups/0/Items/0]
Name=keyboard-us
Layout=
[Groups/0/Items/1]
Name=pinyin
Layout=
[GroupOrder]
0=Default
PROFILE
cat >"$XDG_CONFIG_HOME/fcitx5/config" <<'CONFIG'
[Behavior]
ActiveByDefault=True
ShareInputState=All
CONFIG
# On-the-spot: the preedit goes to the client (GPUI asks for
# XIMPreeditCallbacks); fcitx5 draws it in its own window otherwise.
mkdir -p "$XDG_CONFIG_HOME/fcitx5/conf"
printf 'UseOnTheSpot=True\n' >"$XDG_CONFIG_HOME/fcitx5/conf/xim.conf"
"$FCITX5/bin/fcitx5" --replace --disable=wayland,waylandim,notificationitem,kimpanel >"$out/fcitx5.log" 2>&1 &
fcitx=$!
i=0
until "$FCITX5/bin/fcitx5-remote" >/dev/null 2>&1; do
i=$((i + 1))
[ $i -lt 100 ] || { echo "fcitx5 did not start" >&2; break; }
sleep 0.1
done
sleep 1
events=$out/ime-events.jsonl
XMODIFIERS=@im=fcitx "$root/target/release/spike-composer" --seconds 60 >"$events" 2>"$out/ime.log" &
pid=$!
i=0
until win=$(xdotool search --name 'Composer \(spike\)' 2>/dev/null | head -1) && [ -n "$win" ]; do
i=$((i + 1))
[ $i -lt 150 ] || { echo "no window" >&2; exit 1; }
sleep 0.1
done
xdotool windowactivate --sync "$win"
sleep 2
"$FCITX5/bin/fcitx5-remote" -o || true
echo "fcitx5 state: $("$FCITX5/bin/fcitx5-remote" 2>&1) (2: active)" >&2
sleep 0.5
xdotool type --delay 150 'nihao'
sleep 1.5
xwd -root -silent | magick xwd:- -resize 50% "png:$out/ime-preedit.png"
xwd -id "$win" -silent | magick xwd:- "png:$out/ime-preedit-window.png"
xdotool key space
sleep 1
xwd -id "$win" -silent | magick xwd:- "png:$out/ime-committed.png"
xdotool key ctrl+Return
sleep 0.8
kill "$pid" 2>/dev/null || true
wait "$pid" 2>/dev/null || true
kill "$fcitx" 2>/dev/null || true
fail=0
check() {
if jq -e -s "$2" "$events" >/dev/null; then
echo "PASS $1"
else
echo "FAIL $1"
fail=1
fi
}
ev='[.[] | select(.event)]'
check "the input shows the preedit as marked text" "$ev | any(.event == \"preedit\" and .marked != null and (.marked | length) > 0)"
check "the commit puts Chinese text in the input" "$ev | any((.value // \"\") | explode | any(. >= 19968 and . <= 40959))"
check "Ctrl+Enter sends it" "$ev | any(.event == \"sent\" and (.text | explode | any(. >= 19968 and . <= 40959)))"
exit $fail