Skip to content

Plugin fails to initialize on OpenCode v1.16.0: api.keybind undefined + Uint16Array buffer invisible #7

Description

@yingmanwumen

Summary

oc-plugin-rainbow@0.1.1 is broken on OpenCode v1.16.0 (and >= v1.14 for the buffer issue). Two separate bugs:


Bug 1: api.keybind.create is not a function — Plugin fails to initialize

Severity: Critical (plugin crashes on load)

Affected version: OpenCode >= v1.15.0 (when api.keybind was removed from @opencode-ai/plugin TUI API)

Root cause: tui.tsx:139 calls api.keybind.create() which no longer exists in TuiPluginApi. The current API uses api.keymap for keybinding management, and api.command.register() accepts a keybind?: string property directly.

Error log:

TypeError: undefined is not an object (evaluating 'api.keybind.create')
failed to initialize tui plugin

Fix: Remove api.keybind.create() call. The keybind string (splashKeybind = "ctrl+shift+r") is already defined as a constant — just pass it directly to api.command.register(). Also remove the orphaned obj() helper.

Files changed: tui.tsx (3 edits: remove dead code, remove keybind.create(), simplify keybind.get() → direct string)


Bug 2: Rainbow effect invisible — Uint16Array buffer format mismatch

Severity: Major (plugin loads but produces no visual effect)

Affected version: OpenCode >= v1.14.40 (when @opentui/core changed buffer format)

Root cause: OptimizedBuffer.buffers.fg/bg changed from Float32Array (0.0–1.0 float) to Uint16Array (0–255 integer) starting from @opentui/core@0.2.2. The plugin's rainbow-post-process.ts types and all pixel operations assume Float32Array, writing float values like 0.5 which truncate to 0 in Uint16Array — all colors become black/invisible.

Fix: Add runtime buffer-type detection with three helpers:

  • isUint16(buf) — detect buffer type
  • readColor(buf, slot)/255 for Uint16Array, passthrough for Float32Array
  • writeColor(buf, slot, value)Math.round(value * 255) for Uint16Array, passthrough for Float32Array

Update all function signatures and pixel read/write operations to use these helpers. Backward compatible — works with both old and new buffer formats.

Files changed: rainbow-post-process.ts (3 helpers + updated types + 4 updated functions)


Testing

Verified working on OpenCode v1.16.0, Linux (Kitty terminal). Foreground rainbow and logo splash (Ctrl+Shift+R) both functional.

Note: Background glow (bg: true) causes persistent cursor blinking on Kitty due to the 12-24fps repaint resetting the terminal cursor blink timer. This is a terminal-level artifact (issue #4), unrelated to the fixes above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions