diff --git a/CHANGES.rst b/CHANGES.rst index b292f78..2b9b065 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,8 @@ +v3.7.0 +====== + +Added ``layouts`` module and ``to-qwerty`` and ``to-dvorak`` scripts. + v3.6.0 ====== diff --git a/README.rst b/README.rst index 97209b7..e0aa858 100644 --- a/README.rst +++ b/README.rst @@ -19,3 +19,16 @@ .. image:: https://img.shields.io/badge/skeleton-2021-informational :target: https://blog.jaraco.com/skeleton + + +Layouts +======= + +One of the features of this package is the layouts module, which +provides a simple example of translating keystrokes from one keyboard +layout to another:: + + echo qwerty | python -m jaraco.text.to-dvorak + ',.pyf + echo "',.pyf" | python -m jaraco.text.to-qwerty + qwerty diff --git a/docs/index.rst b/docs/index.rst index 5c77b41..5fcc2d1 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -12,6 +12,11 @@ Welcome to |project| documentation! :undoc-members: :show-inheritance: +.. automodule:: jaraco.text.layouts + :members: + :undoc-members: + :show-inheritance: + Indices and tables ================== diff --git a/jaraco/text/layouts.py b/jaraco/text/layouts.py new file mode 100644 index 0000000..9636f0f --- /dev/null +++ b/jaraco/text/layouts.py @@ -0,0 +1,25 @@ +qwerty = "-=qwertyuiop[]asdfghjkl;'zxcvbnm,./_+QWERTYUIOP{}ASDFGHJKL:\"ZXCVBNM<>?" +dvorak = "[]',.pyfgcrl/=aoeuidhtns-;qjkxbmwvz{}\"<>PYFGCRL?+AOEUIDHTNS_:QJKXBMWVZ" + + +to_dvorak = str.maketrans(qwerty, dvorak) +to_qwerty = str.maketrans(dvorak, qwerty) + + +def translate(input, translation): + """ + >>> translate('dvorak', to_dvorak) + 'ekrpat' + >>> translate('qwerty', to_qwerty) + 'x,dokt' + """ + return input.translate(translation) + + +def _translate_stream(stream, translation): + """ + >>> import io + >>> _translate_stream(io.StringIO('foo'), to_dvorak) + urr + """ + print(translate(stream.read(), translation)) diff --git a/jaraco/text/to-dvorak.py b/jaraco/text/to-dvorak.py new file mode 100644 index 0000000..a6d5da8 --- /dev/null +++ b/jaraco/text/to-dvorak.py @@ -0,0 +1,6 @@ +import sys + +from . import layouts + + +__name__ == '__main__' and layouts._translate_stream(sys.stdin, layouts.to_dvorak) diff --git a/jaraco/text/to-qwerty.py b/jaraco/text/to-qwerty.py new file mode 100644 index 0000000..abe2728 --- /dev/null +++ b/jaraco/text/to-qwerty.py @@ -0,0 +1,6 @@ +import sys + +from . import layouts + + +__name__ == '__main__' and layouts._translate_stream(sys.stdin, layouts.to_qwerty)