compose

package
v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package compose turns keysym sequences into text: pressing ' then e on a us-intl/deadkeys layout commits "é". The XKB keymap only yields the dead_acute keysym; composing needs an XKB compose table (~/.XCompose plus the system file), which this package resolves and parses once per process and shares across input contexts.

The parser, trie, and state machine come from lys-lib's pure-Go compose implementation (no cgo, the Compose file is just data); this package adds lys-ui's semantics on top: Feed answers pending, done-with-text, or none; backspace unwinds one level; a nil table — no compose file anywhere — is the disabled state and every call is a no-op, so callers never branch on whether compose exists.

Compose commits on completion only, X11 style: while a sequence is in flight no text is emitted, and there is no preedit display (that is the IME's territory). Composing works without the text-input protocol.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Result

type Result uint8

Result classifies what one Feed did to the sequence in flight.

const (
	// None means the keysym took no part in a sequence: the caller
	// routes it through normal text handling. A sequence that was in
	// flight is cancelled by the time None returns.
	None Result = iota
	// Pending means the keysym joined a sequence that is still waiting
	// for more keysyms; nothing has been emitted.
	Pending
	// Done means a sequence completed and text is its committed string.
	Done
)

type State

type State struct {
	// contains filtered or unexported fields
}

State is one compose state machine: feed it the committed keysyms of key presses and it answers pending, done-with-text, or none. Not safe for concurrent use; it lives on the input thread. The nil State is the disabled machine: every method is a no-op.

func (*State) Backspace

func (s *State) Backspace() bool

Backspace unwinds one level of an in-flight sequence and reports whether anything was pending. Outside a sequence it reports false — the caller must then let backspace through as the widget's delete action. Backspace itself never emits text either way.

func (*State) Cancel

func (s *State) Cancel()

Cancel drops any in-flight sequence.

func (*State) Composing

func (s *State) Composing() bool

Composing reports whether a sequence is in flight.

func (*State) Feed

func (s *State) Feed(sym xkb.Keysym) (Result, string)

Feed advances the machine by one committed keysym. A keysym that matches no continuation cancels the sequence and reports None, so the key itself still goes through normal text handling; the dead-key prefix is dropped (there is no replay of cancelled prefixes). Modifier keysyms are not fed and never cancel: they cannot appear in sequences, and tapping shift mid-sequence must not lose it.

type Table

type Table struct {
	// contains filtered or unexported fields
}

Table is an immutable set of compose sequences: keysym chains mapped to their committed text. Safe for concurrent use; a process needs one table (Load) and each input context its own State (Start).

func Load

func Load() *Table

Load resolves the active compose file the way X11 clients do and parses it: $XCOMPOSEFILE, then ~/.XCompose, then the system file for the locale (LC_ALL/LC_CTYPE/LANG, with en_US.UTF-8 as the fallback). A nil Table means compose is disabled — no compose file exists, and dead-key layouts simply keep producing bare dead keysyms, which callers then treat like any other non-text key.

func NewTableFile

func NewTableFile(path string) (*Table, error)

NewTableFile parses one explicit Compose file — the seam tests and unusual setups use instead of the Load search order.

func (*Table) Start

func (t *Table) Start() *State

Start opens a state machine over the table. Start on a nil Table (compose disabled) returns a nil State whose methods are all no-ops.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL