Skip to content

Gem to add typewriter effects on Ruby console output.

License

Notifications You must be signed in to change notification settings

CJGlitter/typewrite

Repository files navigation

Typewrite

Gem Version

Typewrite is a Ruby library that prints console messages "typewriter" style, or letter-by-letter.

Installation

#Installing as Ruby gem
$gem install typewrite

#Cloning the repsository
$git clone git@github.com:CJGlitter/typewrite.git

Usage

require "typewrite"
Typewrite.write("Your message here!")

Options

The variable options include type rate, pause length, line breaks, and interrupt behavior. By default, the type rate is one character per 0.1 second with a 1.5 second pause after each punctuation character ['.','?','!'] with a new line after each message.

Basic Options

You can adjust the type rate and pause length with numbers and turn off the newlines with a boolean:

message = "Here's your message"
Typewrite.write(message, 0.05, 0, false)

That would result in a message that types a character every 0.05 seconds with no punctuation pauses and no newlines after each message.

Interrupt Mode

You can allow users to skip the typewriter animation by pressing keys during output:

# Allow interruption with Enter key (default interrupt behavior)
Typewrite.write("Press ENTER to skip...", interrupt: true)
Typewrite.write("Press ENTER to skip...", interrupt: :enter)

# Allow interruption with any key
Typewrite.write("Press ANY key to skip...", interrupt: :any)

# Allow interruption with specific keys
Typewrite.write("Press Q, X, or SPACE to skip...", interrupt: ["q", "x", " "])

When interrupted, the remaining text prints immediately so users see the complete message.

Development

Running Tests

bundle install
bundle exec rake        # Run tests + linting
bundle exec rspec       # Run tests only
bundle exec rubocop     # Run linting only

Code Quality

This project uses RuboCop for linting. Please ensure your code passes linting before submitting a PR:

bundle exec rubocop -A  # Auto-fix issues

Versioning

Typewrite follows the Semantic Versioning standard.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/CJGlitter/typewrite

License

Copywrite ©Cory Davis 2023

https://cjglitter.com

Released under the MIT license. See LICENSE file for details.

About

Gem to add typewriter effects on Ruby console output.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages