0.0
No commit activity in last 3 years
No release in over 3 years
RawLine can be used to define custom key bindings, perform common line editing operations, manage command history and define custom command completion rules.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 3.0

Runtime

>= 1.7.2, ~> 1.7
 Project Readme

RawLine¶ ↑

RawLine was created to provide a 100% Ruby alternative to the ReadLine library, providing some of its most popular features such as:

  • Basic line editing operations

  • Word completion

  • History Management

  • Custom key/key sequences bindings

Installation¶ ↑

The simplest method to install RawLine is to install the gem:

gem install rawline

Usage¶ ↑

Editor initialization:

require 'rawline'
editor = RawLine::Editor.new

Key binding:

editor.bind(:ctrl_z) { editor.undo }
editor.bind(:up_arrow) { editor.history_back }
editor.bind(:ctrl_x) { puts "Exiting..."; exit }

Setup word completion

editor.completion_proc = lambda do |word|
  if word
    ['select', 'update', 'delete', 'debug', 'destroy'].find_all  { |e| e.match(/^#{Regexp.escape(word)}/) }
  end
end
editor.completion_append_string = " "

Read input:

editor.read("=> ", true)

Replacing Readline¶ ↑

Simply include the RawLine (or Rawline) module:

include Rawline

…and you’ll get:

readline(prompt, add_history) # RawLine::Editor#read(prompt, add_history)
HISTORY  # RawLine::Editor#history
FILENAME_COMPLETION_PROC  # Rawline::Editor#filename_completion_proc
...

but also:

Rawline.editor  # RawLine::Editor

…which opens a world of endless possibilities! ;-)