From 4725e46fe07d1f653096745970c778da5fbe0e77 Mon Sep 17 00:00:00 2001 From: Seth Rider <2758832+psethwick@users.noreply.github.com> Date: Fri, 28 May 2021 22:34:36 +0100 Subject: [PATCH] space out morse characters in Substitute (#20) * space out morse characters in Substitute * uhh this file * Update README.rst * Update setup.cfg * add test for morse Co-authored-by: Seth Rider --- README.rst | 1 + plover_fancytext/character_helpers.py | 158 ++++++++++++------------ plover_fancytext/common.py | 2 +- plover_fancytext/substitute.py | 5 +- plover_fancytext/testExtensionPlugin.py | 8 ++ setup.cfg | 2 +- 6 files changed, 93 insertions(+), 83 deletions(-) diff --git a/README.rst b/README.rst index 061e082..9ac7007 100644 --- a/README.rst +++ b/README.rst @@ -25,6 +25,7 @@ Transformers: * crytyping: I' finne,,, h ddon'nt w,,,orry about me, re,,el yy * fullwidth: vaporwave * medieval: 𝕸𝖊𝖉𝖎𝖊𝖛𝖆𝖑 +* morse: ... --- ... * sarcasm: wELl ThIs IS cONvEnIeNt * upsidedown: ndsᴉpǝ poʍu * uwu: Hewwoooo <3 this aww you nyeed. diff --git a/plover_fancytext/character_helpers.py b/plover_fancytext/character_helpers.py index 5f07051..92adf1e 100644 --- a/plover_fancytext/character_helpers.py +++ b/plover_fancytext/character_helpers.py @@ -180,86 +180,86 @@ } MORSE_MAP = { - 'A': '.- ', - 'B': '-... ', - 'C': '-.-. ', - 'D': '-.. ', - 'E': '. ', - 'F': '..-. ', - 'G': '--. ', - 'H': '.... ', - 'I': '.. ', - 'J': '.--- ', - 'K': '-.- ', - 'L': '.-.. ', - 'M': '-- ', - 'N': '-. ', - 'O': '--- ', - 'P': '.--. ', - 'Q': '--.- ', - 'R': '.-. ', - 'S': '... ', - 'T': '- ', - 'U': '..- ', - 'V': '...- ', - 'W': '.-- ', - 'X': '-..- ', - 'Y': '-.-- ', - 'Z': '--.. ', - 'a': '.- ', - 'b': '-... ', - 'c': '-.-. ', - 'd': '-.. ', - 'e': '. ', - 'f': '..-. ', - 'g': '--. ', - 'h': '.... ', - 'i': '.. ', - 'j': '.--- ', - 'k': '-.- ', - 'l': '.-.. ', - 'm': '-- ', - 'n': '-. ', - 'o': '--- ', - 'p': '.--. ', - 'q': '--.- ', - 'r': '.-. ', - 's': '... ', - 't': '- ', - 'u': '..- ', - 'v': '...- ', - 'w': '.-- ', - 'x': '-..- ', - 'y': '-.-- ', - 'z': '--.. ', - '0': '----- ', - '1': '.---- ', - '2': '..--- ', - '3': '...-- ', - '4': '....- ', - '5': '..... ', - '6': '-.... ', - '7': '--... ', - '8': '---.. ', - '9': '----. ', - '!': '-.-.-- ', - '?': '..--.. ', - '-': '-....- ', - '.': '.-.-.- ', + 'A': '.-', + 'B': '-...', + 'C': '-.-.', + 'D': '-..', + 'E': '.', + 'F': '..-.', + 'G': '--.', + 'H': '....', + 'I': '..', + 'J': '.---', + 'K': '-.-', + 'L': '.-..', + 'M': '--', + 'N': '-.', + 'O': '---', + 'P': '.--.', + 'Q': '--.-', + 'R': '.-.', + 'S': '...', + 'T': '-', + 'U': '..-', + 'V': '...-', + 'W': '.--', + 'X': '-..-', + 'Y': '-.--', + 'Z': '--..', + 'a': '.-', + 'b': '-...', + 'c': '-.-.', + 'd': '-..', + 'e': '.', + 'f': '..-.', + 'g': '--.', + 'h': '....', + 'i': '..', + 'j': '.---', + 'k': '-.-', + 'l': '.-..', + 'm': '--', + 'n': '-.', + 'o': '---', + 'p': '.--.', + 'q': '--.-', + 'r': '.-.', + 's': '...', + 't': '-', + 'u': '..-', + 'v': '...-', + 'w': '.--', + 'x': '-..-', + 'y': '-.--', + 'z': '--..', + '0': '-----', + '1': '.----', + '2': '..---', + '3': '...--', + '4': '....-', + '5': '.....', + '6': '-....', + '7': '--...', + '8': '---..', + '9': '----.', + '!': '-.-.--', + '?': '..--..', + '-': '-....-', + '.': '.-.-.-', ',': '--..--', - '@': '.--.-. ', - '=': '-...- ', - '(': '-.--. ', - ')': '-.--.- ', - '+': '.-.-. ', - '&': '.-... ', - '\'': '.----. ', - '"': '.-..-. ', - ';': '-.-.-. ', - ':': '---... ', - '$': '...-..- ', - '_': '..--.- ', - ' ': '/ ' + '@': '.--.-.', + '=': '-...-', + '(': '-.--.', + ')': '-.--.-', + '+': '.-.-.', + '&': '.-...', + '\'': '.----.', + '"': '.-..-.', + ';': '-.-.-.', + ':': '---...', + '$': '...-..-', + '_': '..--.-', + ' ': '/' } # TODO: https://www.unicode.org/charts/PDF/UFF00.pdf diff --git a/plover_fancytext/common.py b/plover_fancytext/common.py index b92f2ad..60d2048 100644 --- a/plover_fancytext/common.py +++ b/plover_fancytext/common.py @@ -9,7 +9,7 @@ TRANSFORMERS = { 'bubble': lambda: Substitute(BUBBLE_MAP), - 'morse': lambda: Substitute(MORSE_MAP), + 'morse': lambda: Substitute(MORSE_MAP, ' '), 'crytyping': lambda: CryTyping(), 'medieval': lambda: Substitute(MEDIEVAL_MAP), 'fullwidth': lambda: Substitute(FULLWIDTH_MAP), diff --git a/plover_fancytext/substitute.py b/plover_fancytext/substitute.py index e851374..20a7c13 100644 --- a/plover_fancytext/substitute.py +++ b/plover_fancytext/substitute.py @@ -3,7 +3,8 @@ class Substitute(FormatterBase): - def __init__(self, character_map): + def __init__(self, character_map, joiner=''): + self._joiner = joiner self._character_map = character_map def swap(self, c: str) -> str: @@ -14,4 +15,4 @@ def swap(self, c: str) -> str: def format(self, str: str) -> str: if str is None: return None - return ''.join(self.swap(c) for c in str) + return self._joiner.join(self.swap(c) for c in str) diff --git a/plover_fancytext/testExtensionPlugin.py b/plover_fancytext/testExtensionPlugin.py index 5ecb054..1142614 100644 --- a/plover_fancytext/testExtensionPlugin.py +++ b/plover_fancytext/testExtensionPlugin.py @@ -143,6 +143,14 @@ def test_plugged_zalgo(self): self.assertTrue(new[0].text.endswith(new[1].prev_replace)) + def test_plugged_morse(self): + p = self._set_up_plugin() + p.fancy_set(FakeContext(), "morse") + new = self._get_action_return("test") + p.translated([], new) + + self.assertEqual(new[0].text, "- . ... -") + def _set_up_plugin(self) -> ExtensionPlugin: e = FakeEngine() p = ExtensionPlugin(e) diff --git a/setup.cfg b/setup.cfg index 16fb991..8affb4a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = plover_fancytext -version = 1.5.0 +version = 1.6.0 description = Silly output formatting plugin for Plover long_description = file: README.rst author = Seth Rider