Skip to content

Commit

Permalink
Add layouts module and scripts for converting to qwerty and dvorak.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Jun 3, 2022
1 parent 139ef36 commit a115de1
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
v3.7.0
======

Added ``layouts`` module and ``to-qwerty`` and ``to-dvorak`` scripts.

v3.6.0
======

Expand Down
13 changes: 13 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ Welcome to |project| documentation!
:undoc-members:
:show-inheritance:

.. automodule:: jaraco.text.layouts
:members:
:undoc-members:
:show-inheritance:


Indices and tables
==================
Expand Down
25 changes: 25 additions & 0 deletions jaraco/text/layouts.py
Original file line number Diff line number Diff line change
@@ -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))
6 changes: 6 additions & 0 deletions jaraco/text/to-dvorak.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import sys

from . import layouts


__name__ == '__main__' and layouts._translate_stream(sys.stdin, layouts.to_dvorak)
6 changes: 6 additions & 0 deletions jaraco/text/to-qwerty.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import sys

from . import layouts


__name__ == '__main__' and layouts._translate_stream(sys.stdin, layouts.to_qwerty)

0 comments on commit a115de1

Please sign in to comment.