Skip to content

Feature: IME language support via "key display" format in language files #178

Description

@Qiumix

Motivation

Currently, ttyper has no native support for IME-based languages (e.g., Chinese,
Japanese). In its current state, users have two choices when typing these languages:

  1. With an IME active: Users must type the phonetic keys (e.g., Pinyin), use the IME overlay to select the correct word, and then commit it to the terminal. This completely breaks the speed and actually is quite annoying.
  2. Without an IME: There is no way to map raw keystrokes directly to target characters. For instance, a user cannot type nihao and have ttyper validate it against 你好.

Proposed Format

Language files would support a mixed format. Each line is either:

  • word — existing format, unchanged
  • key_to_type\tdisplay_text — new format, split on the first tab

Example (chinese_full_pinyin):
nihao 你好
zaijian 再见
hello ← existing format still works
This is compatible with previous language files.

Alignment

In a monospace terminal, CJK characters and some others unicode characters typically render as 2 columns wide. This means key_to_type and display_text may have different terminal widths:

key display key width display width padding needed
nihao 你好 5 4 1 space after display
zf 字符 2 4 2 space after key (in input area)

Each word slot should be padded to max(key_width, display_width) columns. The unicode-width crate (already a transitive dependency via ratatui) provides UnicodeWidthStr::width() for this calculation.
However, some weird terminal/font combinations render all characters as 1 column wide. Maybe there should be a config option (e.g., --cjk-width 1|2) to handle this?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions