content/rawline.textile
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
----- permalink: rawline filters_pre: - erb - redcloth title: "Project: RawLine" type: project github: rawline links: - "Documentation": http://rawline.rubyforge.org - "Download": http://rubyforge.org/projects/rawline - "Source": http://github.com/h3rald/rawline/tree/master - "Tracking": http://h3rald.lighthouseapp.com/projects/26374-rawline/overview status: On Hold version: 0.3.1 ----- <%= render 'project_data', :tag => 'rawline' %> RawLine is 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 <br style="clear:both" /> h3. Installation The simplest method to install RawLine is to install the gem: <% highlight :text do %>gem install rawline<% end %> h3. Usage Editor initialization: <% highlight :ruby do %> require 'rawline' editor = RawLine::Editor.new <% end %> Key binding: <% highlight :ruby do %> editor.bind(:ctrl_z) { editor.undo } editor.bind(:up_arrow) { editor.history_back } editor.bind(:ctrl_x) { puts "Exiting..."; exit } <% end %> Setup word completion <% highlight :ruby do %> 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 = " " <% end %> Read input: <% highlight :ruby do %>editor.read("=> ", true)<% end %> h3. Replacing Readline Simply include the RawLine (or Rawline) module: <% highlight :ruby do %>include Rawline<% end %> …and you’ll get: <% highlight :ruby do %> readline(prompt, add_history) # RawLine::Editor#read(prompt, add_history) HISTORY # RawLine::Editor#history FILENAME_COMPLETION_PROC # Rawline::Editor#filename_completion_proc # ... <% end %> but also: <% highlight :ruby do %>Rawline.editor # RawLine::Editor<% end %> ...which opens a world of endless possibilities! ;-) <%= render 'project_updates', :tag => 'rawline' %> |