Skip to main content

A Python library for creating captivating terminal typing effects with ease.

Project description

PyTypeFx

Python

A Python library for creating captivating terminal typing effects with ease.

PyTypeFx is a versatile and easy-to-use Python library designed to bring your terminal applications to life with a variety of dynamic and customizable typing effects. Whether you're creating a command-line game, a stylish installation script, or just want to add a bit of flair to your program's output, TypeFx provides the tools you need.

Features

  • Multiple Typing Effects: A rich collection of writer functions including TypeWriter, RainbowWriter, GlitchWriter, BounceWriter, and more.
  • Color and Styling: Extensive color support, including basic, bright, and extended named colors, as well as HEX and RGB.
  • Gradient Text: Create beautiful gradient effects on your text.
  • Decorator Support: A simple @typefx decorator to apply effects to function outputs.
  • Sound Effects: Add auditory feedback to your typing effects (platform-dependent).
  • Command-Line Interface: A built-in CLI for applying effects directly from your terminal.
  • Customizable: Easily configure delay, speed, colors, and other parameters.
  • No Dependencies: Pure Python, with no external libraries required.

Installation

You can install PyTypeFx using pip:

pip install PyTypeFx==0.1.1

Usage

Basic Usage

The core of TypeFx is its writer functions. Here's a simple example using the TypeWriter:

from TypeFx import TypeWriter

TypeWriter("Hello, World!", delay=0.05)

Writers

TypeFx comes with a variety of writers, each providing a different effect:

Writer Description
TypeWriter Simulates standard typing.
RainbowWriter Types text with a rainbow color effect.
HexWriter Types text using a list of HEX colors.
DelWriter Types and then deletes text.
LoopWriter Repeats the write-and-delete animation.
SoundWriter Types text with an accompanying sound.
GameDialog Displays text in a game-style dialog box.
RandomWriter Types with a randomized, human-like delay.
MarkdownWriter Strips Markdown formatting and types the clean text.
HTMLWriter Strips HTML tags and types the clean text.
GlitchWriter Types with a "glitch" effect.
ThinkWriter Simulates a "thinking" animation with trailing dots.
ReverseWriter Types text in reverse.
ReverseGlitchWriter Types text in reverse with a glitch effect.
BounceWriter Types text forwards and then deletes it.
BounceGlitchWriter A bouncing animation with a glitch effect.
GradientWriter Types text with a smooth color gradient.

Example:

from TypeFx import RainbowWriter, GlitchWriter

RainbowWriter("This is a rainbow effect!", delay=0.03)
GlitchWriter("This is a glitch effect!", delay=0.01)

Decorator

The @typefx decorator allows you to easily apply typing effects to the output of any function.

from TypeFx import typefx

@typefx(hex_colors=["#FF0000", "#00FF00", "#0000FF"], delay=0.03)
def my_message():
    print("This message will be typed out with a cool effect!")

my_message()

Command-Line Interface

You can also use TypeFx directly from your terminal.

typefx --text "Hello from the CLI!" --delay 0.05 --rainbow

CLI Options:

Option Description
-t, --text Text to type.
-d, --delay Delay between characters.
-l, --loops Number of loops for effects like LoopWriter.
-r, --rainbow Use the rainbow effect.
-rnd, --random Use the random writer effect.
-s, --sound Use the sound effect.
-f, --file Read text from a file.

API Reference

writers

The writers module contains all the typing effect functions. See the "Writers" section above for a full list.

effects

  • BlinkEffect(duration: float, cursor: str, delay: float): Displays a blinking cursor.
  • SoundEffect(frequency: int, duration: int): Plays a sound (platform-dependent).

decorator

  • @typefx(hex_colors=None, delay: float = 0.05, loop: int = 1, speed: str = "normal"): A decorator to apply typewriter effects to function output.

colors

The colors module provides a wide range of color and formatting constants, as well as helper functions:

  • hex_to_ansi(hex_color: str) -> str: Converts a HEX color to an ANSI escape code.
  • rgb_to_ansi(r: int, g: int, b: int) -> str: Converts an RGB color to an ANSI escape code.
  • colorize(text: str, *style: str) -> str: Applies ANSI styles to text.

utility

  • gradient(text: str, start_hex: str, end_hex: str) -> str: Applies a color gradient to text.
  • supports_ansi() -> bool: Checks if the terminal supports ANSI escape codes.

Configuration

The constant module contains default values that can be customized:

Constant Default Value Description
TEXT "Hello World!" Default text for writers.
GLITCH `"!@#$%^&*()_+-=[]{} ;':",./<>?"`
CURSOR _ Default cursor for BlinkEffect.
DELAY 0.05 Default delay between characters.
DURATION 2 Default duration for effects.
HOLD 1 Default hold time for DelWriter.
LOOP 3 Default number of loops.
DOTS 3 Default number of dots for ThinkWriter.
FREQUENCY 800 Default sound frequency.
SOUND_DURATION 30 Default sound duration.
START_HEX "#E74C3C" Default start color for gradients.
END_HEX "#2ECC71" Default end color for gradients.

Examples

Gradient Text

from TypeFx import GradientWriter

GradientWriter("This is a beautiful gradient!", start_hex="#FF00FF", end_hex="#00FFFF", delay=0.02)

Game Dialog

from TypeFx import GameDialog

GameDialog(speaker="Hero", text="I must defeat the final boss!", delay=0.04, sound=True)

Chaining Effects

from TypeFx import TypeWriter, DelWriter, BlinkEffect

TypeWriter("Preparing for deletion...")
DelWriter("This message will self-destruct.", hold=2)
BlinkEffect(duration=2)

License

This project is licensed under the MIT License. See the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytypefx-0.1.1.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytypefx-0.1.1-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file pytypefx-0.1.1.tar.gz.

File metadata

  • Download URL: pytypefx-0.1.1.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for pytypefx-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1338d27ab98783895e0dd1a740d1498eae2620cac18d07b7e55f9e461bf69589
MD5 c9eea22e73bd0c7a9cc64805e94d9cda
BLAKE2b-256 4a16ae0e67de72677f6fcdb1e0f996968e717ce299d96e06da054ec0baeb08b6

See more details on using hashes here.

File details

Details for the file pytypefx-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pytypefx-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for pytypefx-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2efc5c3d67507bd5d3420eb1b18820c5eab4dbf4211fe314c294401b86c9eecc
MD5 f086d50dc92d9a02d4d427d02dbecd42
BLAKE2b-256 c2b407a74545b04857685394734d92eda126e467544ed837f90d426a7b16bdf5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page