-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
235 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,3 +112,5 @@ venv.bak/ | |
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
from scrmbl.scrmbl import echo | ||
from scrmbl.scrmbl import charsets | ||
from scrmbl.main import echo | ||
|
||
__all__ = ['echo', 'charsets'] | ||
__all__ = ['echo'] | ||
|
||
__version__ = '0.1.1' | ||
__version__ = '1.0.0' |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import re | ||
import sys | ||
|
||
import click | ||
|
||
import scrmbl | ||
|
||
|
||
@click.command() | ||
@click.argument('message', default='') | ||
@click.option('-s', '--speed', type=click.FLOAT, default=0.05, | ||
help='Time in seconds between prints. Default: 0.05') | ||
@click.option('-i', '--iterations', type=click.INT, default=2, | ||
help='Number of iterations per character. Default: 2') | ||
@click.option('-c', '--charset', | ||
type=click.Path(exists=True, allow_dash=True, dir_okay=False), | ||
help='Set of chars to scramble.') | ||
@click.version_option(version=scrmbl.__version__) | ||
def cli(message: str, speed: float, iterations: int, charset: str) -> None: | ||
"""Scrmbl print the given message.""" | ||
# no text input | ||
if not message: | ||
# if no stdin or just '-c -' | ||
if sys.stdin.isatty() or charset == '-': | ||
raise click.UsageError('"MESSAGE" is empty. No argument or stdin.') | ||
for line in sys.stdin: | ||
message += line | ||
message = _strip_ansi_colors(message) | ||
if charset: | ||
with click.open_file(charset) as f: | ||
charset_content = f.read() | ||
charset_content = charset_content.replace('\n', '') | ||
else: | ||
charset_content = None | ||
scrmbl.echo(message, charset=charset_content, speed=speed, | ||
iterations=iterations) | ||
|
||
|
||
def _strip_ansi_colors(message: str) -> str: | ||
"""Strip ANSI color codes""" | ||
escape_codes = re.compile(r'\x1B\[[0-?]*[ -/]*[@-~]') | ||
return escape_codes.sub('', message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import random | ||
import string | ||
import time | ||
|
||
import click | ||
|
||
random.seed() | ||
|
||
ALL_CHARS = string.digits + string.ascii_letters + string.punctuation | ||
COLS, _ = click.get_terminal_size() | ||
|
||
|
||
def echo(message: str, charset: str = ALL_CHARS, speed: float = 0.05, | ||
iterations: int = 2) -> None: | ||
"""Scrmbl print the given message.""" | ||
if not charset: | ||
charset = ALL_CHARS | ||
for line in message.split('\n'): | ||
echoed = '' | ||
for char in line: | ||
for _ in range(iterations): | ||
if char != ' ': | ||
ran_char = random.choice(charset) | ||
click.echo('\r{}{}'.format(echoed, ran_char), nl=False) | ||
else: | ||
click.echo('\r{}'.format(echoed), nl=False) | ||
time.sleep(speed) | ||
echoed += char | ||
# wrap if line longer than console cols | ||
if len(echoed) >= COLS - 1: | ||
click.echo('\r' + echoed) | ||
echoed = '' | ||
if echoed: | ||
click.echo('\r' + echoed) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
abcdefg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras accumsan arcu quis ex mollis suscipit. Sed non orci porttitor, tincidunt mauris id, volutpat diam. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aliquam eget porta massa. Aliquam facilisis sit amet quam id sodales. Donec egestas pharetra pellentesque. Nam vestibulum dictum pharetra. Ut eget est at nibh condimentum sagittis ac a dui. Duis iaculis convallis rhoncus. Mauris maximus erat scelerisque, semper leo eget, rhoncus enim. Nulla ullamcorper in purus eget varius. | ||
|
||
Praesent imperdiet odio in massa egestas, a laoreet quam viverra. In hac habitasse platea dictumst. Suspendisse eu lobortis felis. Maecenas auctor purus risus, eget tempor turpis tincidunt at. Aliquam elementum feugiat ligula ac dictum. Aenean sit amet enim non lectus semper dignissim. Aenean posuere pretium faucibus. Suspendisse blandit est vel ultricies mollis. Sed pellentesque sem vel ullamcorper tempus. Fusce non nisi lorem. Phasellus at urna ut est viverra auctor. Vestibulum faucibus dapibus nisi nec mollis. Aenean commodo libero ipsum, ac mattis lectus dapibus vitae. Praesent urna massa, condimentum a sapien dapibus, fringilla gravida urna. | ||
|
||
Vestibulum gravida feugiat urna vitae commodo. Sed consequat mollis sem, ultrices ornare sapien dignissim ac. Mauris vestibulum ut nunc eget ultricies. Fusce vel fringilla arcu. Aenean felis ipsum, accumsan scelerisque ullamcorper ut, dignissim ac purus. Integer ornare, ligula sit amet condimentum hendrerit, turpis neque mattis erat, vitae fermentum lectus eros at urna. Sed nec dignissim felis, ac condimentum velit. Nam et tortor auctor, semper eros eget, lacinia dui. Maecenas id placerat mauris. Proin eget volutpat risus, sed ultrices tortor. Vivamus hendrerit congue dui, ut volutpat purus rhoncus sed. Maecenas consequat diam non metus dignissim faucibus. Donec sit amet posuere ex. In convallis placerat mi ac porttitor. Nullam blandit posuere mauris, et venenatis dui lobortis eget. Sed id est nec urna placerat pellentesque ac ut massa. | ||
|
||
Vivamus quis tristique metus. Fusce lobortis laoreet porta. Nam a luctus magna. Etiam eu tempor turpis, et scelerisque eros. Curabitur placerat mattis nibh sit amet lobortis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Donec dictum erat in justo sollicitudin suscipit. Nulla at odio quis magna posuere congue mollis non mi. | ||
|
||
Nam bibendum, lacus at molestie porttitor, risus ipsum egestas mauris, non vulputate ex erat nec diam. Nunc nec sollicitudin lectus. Aenean elementum sollicitudin augue, quis luctus dui mollis ut. Sed sed risus id enim gravida lobortis et in metus. Suspendisse eget sollicitudin risus. Praesent eget lacinia nunc. Maecenas laoreet nibh sit amet arcu hendrerit auctor. Proin in nulla in ex iaculis rutrum sed eu lectus. Vestibulum sollicitudin turpis ut odio aliquet, in gravida tellus sodales. Vestibulum vel tortor nec ante elementum venenatis in eu erat. Proin ornare semper ex a tempus. Etiam placerat orci ut tellus aliquet, a cursus nisl volutpat. | ||
|
||
Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Mauris non ligula sapien. Donec eu felis sed diam suscipit accumsan. Etiam eu aliquet ligula, non tristique massa. Proin quis tempus mi, in hendrerit ex. Fusce vestibulum sodales mauris feugiat eleifend. Suspendisse at est accumsan, laoreet tortor quis, volutpat quam. Curabitur pellentesque nunc eu tempus cursus. Donec eget mollis enim, in fringilla eros. Curabitur malesuada eget orci eget faucibus. Sed id auctor velit. Vivamus ac diam quis eros pellentesque sollicitudin. Ut eu nisi ultricies justo finibus finibus. | ||
|
||
Morbi vel leo ut mi congue elementum. Donec scelerisque est sapien, ut malesuada arcu malesuada nec. Cras euismod ligula id leo posuere pellentesque. Ut et quam ut massa condimentum bibendum. Mauris venenatis fermentum nisl, quis convallis sem aliquam ac. Phasellus lobortis ac neque at interdum. Pellentesque non convallis magna. Vivamus ornare velit a leo interdum, a auctor nunc commodo. Donec lobortis lacus et nisl volutpat, at pharetra ex posuere. | ||
|
||
Nunc malesuada arcu non faucibus sodales. Morbi placerat quam ipsum, nec aliquam nulla vulputate at. Integer dignissim molestie faucibus. Mauris quis tortor porttitor sem pharetra ullamcorper. Vestibulum sodales varius efficitur. Quisque fringilla luctus massa vitae porttitor. Phasellus fermentum nibh eros, vitae condimentum felis finibus quis. In faucibus eget metus malesuada lobortis. Donec ut neque eget tellus imperdiet convallis nec eu tortor. Quisque felis purus, blandit eu fringilla eu, scelerisque a enim. | ||
|
||
Donec rhoncus lectus ex, vitae rhoncus sem aliquam in. Cras vitae facilisis justo. Nullam non fringilla arcu. In viverra lobortis lacus, a convallis nunc bibendum a. Nunc porta risus eu nisl varius euismod. Vestibulum sodales rutrum diam, nec elementum sapien suscipit non. Duis id turpis id justo aliquet lacinia at metus. |
Oops, something went wrong.