Typewrite is a Ruby library that prints console messages "typewriter" style, or letter-by-letter.
#Installing as Ruby gem
$gem install typewrite
#Cloning the repsository
$git clone git@github.com:CJGlitter/typewrite.git
require "typewrite"
Typewrite.write("Your message here!")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.
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.
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.
bundle install
bundle exec rake # Run tests + linting
bundle exec rspec # Run tests only
bundle exec rubocop # Run linting onlyThis project uses RuboCop for linting. Please ensure your code passes linting before submitting a PR:
bundle exec rubocop -A # Auto-fix issuesTypewrite follows the Semantic Versioning standard.
Bug reports and pull requests are welcome on GitHub at https://github.com/CJGlitter/typewrite
Copywrite ©Cory Davis 2023
Released under the MIT license. See LICENSE file for details.