rcalc

rcalc is a set of tools to do stuff on the terminal. It is written in pure Ruby. It has no dependencies.

Installation

Add this line to your application’s Gemfile:

gem 'rcalc'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install rcalc

Usage

Main documentation is at: rcalc.davidsiaw.net/

Terminal colors

t = Rcalc::Terminal.new
t.color_white!
puts "white text"
t = Rcalc::Terminal.new
t.color_black!
t.bgcolor_white!
puts "black text on white background"

Listen for keypresses / mouse

c.start_mouse!
c.listen! do |k|
  print "#{k.inspect}\r\n"
  if k == "\u0003"
    true # quit when receiving Ctrl+C
  elsif k == "q"
    p c.pos # show cursor position
    false
  elsif k == "s"
    p c.size # get console size
    false
  elsif k == "c"
    c.clear! # clear console
    false
  elsif k == "h"
    c.home! # go to top left
    false
  else
    false
  end
end
c.stop_mouse!

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Lots of development is based on this: invisible-island.net/xterm/ctlseqs/ctlseqs.pdf

I only use alacritty, gnome terminal and kitty. I don’t know if it works for your terminal emulator. Try it and fix if you care.

Contributing

Bug reports and pull requests are welcome on GitHub at github.com/davidsiaw/rcalc. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Base project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.