Git Product home page Git Product logo

rawline's Introduction

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! ;-)

rawline's People

Contributors

h3rald avatar zdennis avatar

Stargazers

Lorenzo Benvenuti avatar DAVID RUPP JR. avatar Vidar Hokstad avatar  avatar Reiner avatar Angus H. avatar Daniel Berger avatar tom quas avatar Johannes Bechberger avatar Konstantin Silin avatar Carson Reinke avatar Max Stepanov avatar Jan Lelis avatar Mike Harris avatar Abdelhak LAKEL avatar Pablo Flouret avatar Konstantin Haase avatar TJ Holowaychuk avatar Kris Rasmussen avatar Tiago Bastos avatar Ilya Grigorik avatar Kaz avatar Mathias Meyer avatar Scott Taylor avatar Aman Gupta Karmani avatar  avatar Piotr Usewicz avatar Mark Carey avatar Gavin-John Noonan avatar Ravil Bayramgalin avatar James Tucker avatar Lachie Cox avatar Jeff Smick avatar  avatar Matt Todd avatar

Watchers

 avatar Bill.Yuan avatar James Cloos avatar  avatar  avatar

rawline's Issues

Some keys binding cannot work in Win10

The backspace, lef/right/up/down_arrows, delete keys all cannot used in Win10.
There are messy log on the terminal if we press these keys.

It's a serious issue, because users cannot modify input strings at all.

History and the up arrow key

Hi,

I thought I would be able to get history in irb using the up-arrow key if I require'd and then include'd Rawline. It doesn't seem to work, except once in a great while. I can't reliably reproduce how or why it works those times.

Ruby 2.1.2 on Windows 7 compile with VC++, btw.

Any ideas?

Can't require RawLine

Installed RawLine using

gem install rawline

Then

$ pry
[1] pry(main)> require "rawline"
ArgumentError: wrong number of arguments (1 for 0)
from /home/tomas/.rvm/gems/ruby-2.0.0-p195/gems/rawline-0.3.1/lib/rawline.rb:96:in `block (2 levels) in <module:RawLine>'

$ ruby -v
ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-linux]
$ gem -v
2.0.3
$ gem environment
RubyGems Environment:
  - RUBYGEMS VERSION: 2.0.3
  - RUBY VERSION: 2.0.0 (2013-05-14 patchlevel 195) [x86_64-linux]
  - INSTALLATION DIRECTORY: /home/tomas/.rvm/gems/ruby-2.0.0-p195
  - RUBY EXECUTABLE: /home/tomas/.rvm/rubies/ruby-2.0.0-p195/bin/ruby
  - EXECUTABLE DIRECTORY: /home/tomas/.rvm/gems/ruby-2.0.0-p195/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /home/tomas/.rvm/gems/ruby-2.0.0-p195
     - /home/tomas/.rvm/gems/ruby-2.0.0-p195@global
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.