Write an input method engine

Luoke IME handles the keys, the candidate window and committing text; an engine decides which candidates to offer. One folder with two files is an engine.

engine.json
{
  "protocol": 1,
  "name": "Minimal example",
  "kind": "typing",
  "run": ["luoke-python", "engine.py"],
  "input_keys": "abcdefghijklmnopqrstuvwxyz"
}
engine.py
import json, sys

TABLE = {"ni": ["你", "呢"], "hao": ["好", "号"], "nihao": ["你好"]}

for line in sys.stdin:
    msg = json.loads(line)
    if msg.get("type") != "query":
        continue
    keys = msg["input"]
    cands = [{"text": t, "consume": n}
             for n in range(len(keys), 0, -1) for t in TABLE.get(keys[:n], [])]
    print(json.dumps({"type": "answer", "id": msg["id"],
                      "candidates": cands}, ensure_ascii=False), flush=True)

Put it in ~/.luoke/ime/engines/ and pick it from the input method menu. Edit a file, and your next keystroke uses the new version.

What you can build

WubiZhengmaZhuyinJyutping

Other ways to type

Any double-pinyin layout, shape-based input, or a shorthand you invented yourself.

Japanese kanaKaomojiLaTeX

Other languages and symbols

Kana, kaomoji, math symbols: each can be its own engine.

XingyunAn internal project codename

Your own word list

A company glossary, or the names you type all the time.

Engines live in a sandbox.

Offline, and only on with your OK

Third-party engines can’t reach the internet or use the GPU. Installing one doesn’t turn it on; you have to confirm.

Writes only to its own folder

It can write only to its own directory. It can’t read your keychain, passwords, browser or email, nor Luoke Memory or the IME’s settings.

Models go through Luoke

To rank candidates by context or continue a sentence, ask Luoke (luoke-core) instead of installing a model of its own.

Done? Submit it

If your engine works well, we’d love to get it to more people.

Submit