plover icon indicating copy to clipboard operation
plover copied to clipboard

Allow system plugins to customize stroke display

Open lynn opened this issue 1 year ago • 0 comments

Summary of changes

System definitions/plugins can now define a function display, which is used to render outlines in the UI (suggestions, lookup, dictionary view, etc).

For example, if I look up Lynn instead of seeing the suggestion 4R*EU7B I might want to see #HR*EUPB or even #L*IN. When adding or editing outlines, the underlying syntax is still used, so that this is a purely cosmetic change.

Here is an example of a system plugin that defines display to restore letters from digits, as may please users of Lapwing theory, which uses # for proper nouns.

# english_stenotype_no_digits.py

from plover.system.english_stenotype import *

UNDIGIT_TABLE = str.maketrans('1234506789', 'STPHAOFPLT')

def display_stroke(stroke):
    undigit = stroke.translate(UNDIGIT_TABLE)
    return stroke if stroke == undigit else '#' + undigit

def display(strokes):
    return '/'.join(map(display_stroke, strokes))

[!NOTE]
This example shows that this isn't quite the right abstraction: English Stenotype and English Stenotype (display lowercase) are not really two different steno systems. But tying the display function to the system keeps things architecturally simple. This way, display functions can be distributed as system plugins (instead of having to invent some new plugin type just for this niche feature), and power users can just edit the display definition in their english_stenotype.py if they so desire.

Pull Request Checklist

  • [ ] Changes have tests
  • [x] News fragment added in news.d. See documentation for details

lynn avatar Feb 05 '24 02:02 lynn