Simple readline-like tool able to change representation of input
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib Version bump to 0.5.0 Sep 14, 2014
.gemtest Added .gemtest Oct 15, 2011
.gitignore Ignored *.gem Oct 15, 2011
.yardopts Made YARD use RedCarpet to format code to get syntax highlighting on … Mar 27, 2013
LICENSE Fixed years in license file Nov 28, 2013
Rakefile Fixed load path change in the Rakefile Mar 12, 2013
coolline.gemspec Added support for characters with a width ≠ 1 Sep 7, 2014
repl.rb Added a menu to display temporary information below the current line Oct 2, 2012


Coolline is a readline-like library written in pure Ruby.

It offers all of the core readline features, but with a cleaner, simpler implementation, and the ability to easily customize its behaviour.

Customizations include: modifying all key bindings, binding keys custom functions, full control over history and tab completion, and control over what's displayed to the user (transforms).


If you don't need anything fancy, it can work like Ruby's built-in Readline.readline:

result = Coolline.readline

But, of course you want something fancy, otherwise you'd be using readline! Here's how to create a simple REPL with live syntax highlighting and tab completion:

require 'coolline'
require 'coderay'
require 'pp'

cool = do |c|

  # Before the line is displayed, it gets passed through this proc,
  # which performs syntax highlighting.
  c.transform_proc = proc do
    CodeRay.scan(c.line, :ruby).term

  # Add tab completion for constants (and classes)
  c.completion_proc = proc do
    word = c.completed_word { |w| w.start_with? word }

  # Alt-R should reverse the line, because we like to look at our code in the mirror
  c.bind "\er" do |cool|


loop do
  # READ
  line = cool.readline

  # EVAL
  obj = eval(line)

  print "=> "
  pp obj

  # LOOP


Coolline automatically loads a config file before starting, which allows adding new key bindings to it. The file is just a chunk of arbitrary ruby code located at $XDG_CONFIG_HOME/coolline/coolline.rb.

Coolline.bind "\C-z" do |cool|
  puts "Testing key binding with #{cool}!"


gem install coolline

Note: If your Ruby version is less than 1.9.3, you also need to install the io-console gem.