From d9273d476a6653514ddf80f8af388d6ae742e145 Mon Sep 17 00:00:00 2001 From: Seth Rider <2758832+psethwick@users.noreply.github.com> Date: Sat, 21 Nov 2020 18:20:37 +0000 Subject: [PATCH] Retro commands! (#17) * Adds retro versions for all the transformers * Test for retro function * Bumping version Let's see if closing a PR with a new version number auto-releases Co-authored-by: Seth Rider --- README.rst | 29 +++++++++++++------ plover_fancytext/__init__.py | 1 - plover_fancytext/common.py | 20 +++++++++++++ .../{fancytext.py => extensionplugin.py} | 23 ++------------- plover_fancytext/retro.py | 24 +++++++++++++++ ...PloverPlugin.py => testExtensionPlugin.py} | 14 ++++----- plover_fancytext/testRetro.py | 27 +++++++++++++++++ setup.cfg | 5 ++-- 8 files changed, 104 insertions(+), 39 deletions(-) create mode 100644 plover_fancytext/common.py rename plover_fancytext/{fancytext.py => extensionplugin.py} (57%) create mode 100644 plover_fancytext/retro.py rename plover_fancytext/{testPloverPlugin.py => testExtensionPlugin.py} (94%) create mode 100644 plover_fancytext/testRetro.py diff --git a/README.rst b/README.rst index fc210d8..2c39e85 100644 --- a/README.rst +++ b/README.rst @@ -19,7 +19,7 @@ What it does Allows you to use Plover to output text in various (mostly joke, mostly unicode) text formats -Examples: +Transformers: * bubble: ⓑⓤⓑⓑⓛⓔ * crytyping: I' finne,,, h ddon'nt w,,,orry about me, re,,el yy @@ -40,13 +40,25 @@ Installing 3. Select 'plover_fancytext' in the list 4. Click install 5. Restart Plover -6. In the Configure menu, navigate to the plugins section -7. Enable 'plover_fancytext' and apply +6. If you just want the retro commands, you're done! + + +Extra steps for the extension plugin (which enables the +``{:fancytext_set:}`` commands): + +1. In the Configure menu, navigate to the plugins section +2. Enable 'plover_fancytext' and apply Usage ##### -You'll need to add Plover dictionary entries to toggle on/off the modes +You can either apply transformations with +``{:fancytext_retro::}`` +which will replace ```` retroactively with fancy text. Example: +``{:fancytext_retro:2:bubble}`` to bubble-ize the last two words. + +Or you can use ``{:fancytext_set:}`` to turn on +a mode until you turn it back off! The format is ``{:fancytext_set:}`` to turn on the mode and simply ``{:fancytext_set:off}`` to turn off any mode. @@ -70,24 +82,23 @@ Mode Notes ########## It's worth noting that these modes will not always work with Plover's -orthography rules. Some modes will be more wrong than others. +orthography rules. Some modes will be more wrong than others The z̶͉a̕l̬ḡ͙o̕ m͏̎o̬̪d̜e̝̹ can also take two arguments for the minimum and maximum number of combining marks. Example ``{:fancytext_set:zalgo:10:15}`` for quite a lot of -z͙͕̹̩̀͑ͮ̇̉ͣ̄͋̕ȃ̵̝͎̘̬͙̖̼͆ͤ̕͝ͅ l̵̤̟̜͎͍̠̭̽̿͂ͬͩ͜ģ̲͈͍̔ͩ̀ͣͬ̉ͨ̕̚͝o̴̢̓̓ͦ̈́̂̆͛ͭͣ. For reference the default is min=1, max=3. +z͙͕̹̩̀͑ͮ̇̉ͣ̄͋̕ȃ̵̝͎̘̬͙̖̼͆ͤ̕͝ͅ l̵̤̟̜͎͍̠̭̽̿͂ͬͩ͜ģ̲͈͍̔ͩ̀ͣͬ̉ͨ̕̚͝o̴̢̓̓ͦ̈́̂̆͛ͭͣ. For reference the default is min=1, max=3 You may want the  full width mode to use a full-width space. This can be done by setting space in the same entry: ``{:fancytext_set:fullwidth}{MODE:SET_SPACE: }``. If you do this you'll probably also want to add ``{MODE:RESET}`` to your entry which turns -off the mode. +off the mode This trick can also be applied to the upside down mode. Include unicode 202e (right to left mark) as well as a space character for um, a good time. You'll definitely want ``{MODE:RESET}`` on this one, and you might want to add unicode 202d (left to right mark) to it as well. You don't want to use these marks anywhere where text needs to be precisely correct, but should be -fine in many places. -I've not included it as part of the mode because it is definitely an acquired +fine in many places. I've not included it as part of the mode because it is definitely an acquired taste and can end up with you having text backwards after you turn the mode off Contributing diff --git a/plover_fancytext/__init__.py b/plover_fancytext/__init__.py index e5a0d9b..e69de29 100644 --- a/plover_fancytext/__init__.py +++ b/plover_fancytext/__init__.py @@ -1 +0,0 @@ -#!/usr/bin/env python3 diff --git a/plover_fancytext/common.py b/plover_fancytext/common.py new file mode 100644 index 0000000..d578d00 --- /dev/null +++ b/plover_fancytext/common.py @@ -0,0 +1,20 @@ +from .zalgo import Zalgo +from .uwu import Uwu +from .crytyping import CryTyping +from .sarcasm import Sarcasm +from .substitute import Substitute +from .character_helpers import \ + BUBBLE_MAP, MEDIEVAL_MAP, UPSIDE_DOWN_MAP, FULLWIDTH_MAP + +TRANSFORMERS = { + 'bubble': lambda: Substitute(BUBBLE_MAP), + 'crytyping': lambda: CryTyping(), + 'medieval': lambda: Substitute(MEDIEVAL_MAP), + 'fullwidth': lambda: Substitute(FULLWIDTH_MAP), + 'uwu': lambda: Uwu(intense=False), + 'UwU': lambda: Uwu(intense=True), + 'sarcasm': lambda: Sarcasm(), + 'upsidedown': lambda: Substitute(UPSIDE_DOWN_MAP), + 'zalgo': lambda minimum=1, maximum=3: Zalgo(int(minimum), + int(maximum)) +} diff --git a/plover_fancytext/fancytext.py b/plover_fancytext/extensionplugin.py similarity index 57% rename from plover_fancytext/fancytext.py rename to plover_fancytext/extensionplugin.py index 871cb7f..249086a 100644 --- a/plover_fancytext/fancytext.py +++ b/plover_fancytext/extensionplugin.py @@ -6,16 +6,10 @@ from plover.registry import registry from plover.formatting import _Context, _Action -from .zalgo import Zalgo -from .uwu import Uwu -from .crytyping import CryTyping -from .sarcasm import Sarcasm -from .substitute import Substitute -from .character_helpers import \ - BUBBLE_MAP, MEDIEVAL_MAP, UPSIDE_DOWN_MAP, FULLWIDTH_MAP +from .common import TRANSFORMERS -class PloverPlugin(Thread): +class ExtensionPlugin(Thread): def __init__(self, engine: StenoEngine) -> None: super().__init__() @@ -25,18 +19,7 @@ def __init__(self, engine: StenoEngine) -> None: self.formatter = None self.engine = engine - self.transformers = { - 'bubble': lambda: Substitute(BUBBLE_MAP), - 'crytyping': lambda: CryTyping(), - 'medieval': lambda: Substitute(MEDIEVAL_MAP), - 'fullwidth': lambda: Substitute(FULLWIDTH_MAP), - 'uwu': lambda: Uwu(intense=False), - 'UwU': lambda: Uwu(intense=True), - 'sarcasm': lambda: Sarcasm(), - 'upsidedown': lambda: Substitute(UPSIDE_DOWN_MAP), - 'zalgo': lambda minimum=1, maximum=3: Zalgo(int(minimum), - int(maximum)) - } + self.transformers = TRANSFORMERS def fancy_set(self, ctx: _Context, cmdline) -> _Action: args = cmdline.split(':') diff --git a/plover_fancytext/retro.py b/plover_fancytext/retro.py new file mode 100644 index 0000000..3ce3115 --- /dev/null +++ b/plover_fancytext/retro.py @@ -0,0 +1,24 @@ +from plover.formatting import _Context, _Action + +from .common import TRANSFORMERS + + +def fancytext_retro(ctx: _Context, cmdline: str) -> _Action: + action = ctx.copy_last_action() + args = cmdline.split(':') + + # should be :mode: + count = int(args.pop(0)) + mode = args.pop(0) + + transformer = TRANSFORMERS[mode](*args) + + last_words = ''.join(ctx.last_words(count=count)) + + action.word = None + action.text = transformer.format(last_words) + + action.prev_replace = last_words + action.prev_attach = True + + return action diff --git a/plover_fancytext/testPloverPlugin.py b/plover_fancytext/testExtensionPlugin.py similarity index 94% rename from plover_fancytext/testPloverPlugin.py rename to plover_fancytext/testExtensionPlugin.py index 07f6d67..5ecb054 100644 --- a/plover_fancytext/testPloverPlugin.py +++ b/plover_fancytext/testExtensionPlugin.py @@ -3,7 +3,7 @@ from plover.formatting import _Action -from .fancytext import PloverPlugin +from .extensionplugin import ExtensionPlugin class FakeContext(): @@ -24,17 +24,17 @@ def hook_disconnect(self, hook: str, method): self.method_calls[hook] = None -class TestPloverPlugin(unittest.TestCase): +class TestExtensionPlugin(unittest.TestCase): def test_connect_hook(self): e = FakeEngine() - f = PloverPlugin(e) + f = ExtensionPlugin(e) f.start() self.assertIsNotNone(e.method_calls["translated"]) def test_hook_signature(self): e = FakeEngine() - f = PloverPlugin(e) + f = ExtensionPlugin(e) f.start() hooked_method = e.method_calls["translated"] signature = inspect.signature(hooked_method) @@ -45,7 +45,7 @@ def test_hook_signature(self): def test_disconnect_hook(self): e = FakeEngine() - f = PloverPlugin(e) + f = ExtensionPlugin(e) f.start() f.stop() self.assertIsNone(e.method_calls["translated"]) @@ -143,9 +143,9 @@ def test_plugged_zalgo(self): self.assertTrue(new[0].text.endswith(new[1].prev_replace)) - def _set_up_plugin(self) -> PloverPlugin: + def _set_up_plugin(self) -> ExtensionPlugin: e = FakeEngine() - p = PloverPlugin(e) + p = ExtensionPlugin(e) p.start() return p diff --git a/plover_fancytext/testRetro.py b/plover_fancytext/testRetro.py new file mode 100644 index 0000000..364294b --- /dev/null +++ b/plover_fancytext/testRetro.py @@ -0,0 +1,27 @@ +from unittest import TestCase +from .retro import fancytext_retro + +from plover.formatting import _Action + + +class FakeContext(): + def __init__(self, actions): + self.actions = actions + + def copy_last_action(self): + return self.actions[-1] + + def last_words(self, count): + return [a.word for a in self.actions[-count:]] + + +class TestRetro(TestCase): + + def test_retro_sarcasm(self): + action = _Action(word="fancy", text="fancy") + retroed = fancytext_retro(FakeContext([action]), "1:sarcasm") + + self.assertEqual(retroed.prev_replace, "fancy") + self.assertEqual(retroed.text, "fANcY") + self.assertIsNone(retroed.word) + self.assertTrue(retroed.prev_attach) diff --git a/setup.cfg b/setup.cfg index c273c8b..96e4ec3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = plover_fancytext -version = 1.3.0 +version = 1.4.0 description = Silly output formatting plugin for Plover long_description = file: README.rst author = Seth Rider @@ -25,4 +25,5 @@ packages = plover_fancytext [options.entry_points] -plover.extension = plover_fancytext = plover_fancytext.fancytext:PloverPlugin +plover.extension = plover_fancytext = plover_fancytext.extensionplugin:ExtensionPlugin +plover.meta = fancytext_retro = plover_fancytext.retro:fancytext_retro