Skip to content

Commit

Permalink
Retro commands! (#17)
Browse files Browse the repository at this point in the history
* 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 <seth@thumbquat.com>
  • Loading branch information
psethwick and Seth Rider committed Nov 21, 2020
1 parent 506cbfa commit d9273d4
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 39 deletions.
29 changes: 20 additions & 9 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:<transformer>}`` 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:<number of words>:<transformer>}``
which will replace ``<number of words>`` retroactively with fancy text. Example:
``{:fancytext_retro:2:bubble}`` to bubble-ize the last two words.

Or you can use ``{:fancytext_set:<transformer>}`` to turn on
a mode until you turn it back off!

The format is ``{:fancytext_set:<mode>}`` to turn on the mode and simply ``{:fancytext_set:off}`` to turn off any mode.

Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion plover_fancytext/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
#!/usr/bin/env python3
20 changes: 20 additions & 0 deletions plover_fancytext/common.py
Original file line number Diff line number Diff line change
@@ -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))
}
Original file line number Diff line number Diff line change
Expand Up @@ -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__()
Expand All @@ -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(':')
Expand Down
24 changes: 24 additions & 0 deletions plover_fancytext/retro.py
Original file line number Diff line number Diff line change
@@ -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 <numwords>:mode:<any extra mode args>
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from plover.formatting import _Action

from .fancytext import PloverPlugin
from .extensionplugin import ExtensionPlugin


class FakeContext():
Expand All @@ -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)
Expand All @@ -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"])
Expand Down Expand Up @@ -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

Expand Down
27 changes: 27 additions & 0 deletions plover_fancytext/testRetro.py
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 3 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

0 comments on commit d9273d4

Please sign in to comment.