Pre-Filled Prompt in Ruby

Pre-Filled Prompt in Ruby

You can do it with RbReadline:

require 'rubygems'
require 'rb-readline'

module RbReadline
def self.prefill_prompt(str)
@rl_prefill = str
@rl_startup_hook = :rl_prefill_hook
end

def self.rl_prefill_hook
rl_insert_text @rl_prefill if @rl_prefill
@rl_startup_hook = nil
end
end

RbReadline.prefill_prompt("Previous query")
str = Readline.readline("Enter query: ", true)

puts "You entered: #{str}"

Pre-fill Rails HTML form with variable

If you look at number_field, you pass in number fields value, class and other options in a single block so try this:

<%= f.number_field :priceOffer, :value => @product.price, class:"form-control" %>

Print editable to console in Ruby

There are similar questions here and here

However, the solutions there don't seem to work as expected, so it looks this is ruby version or platform dependent?

For example, this does not work for me, but also does not throw an error.

require "readline"

filename = Readline.insert_text("untitled.txt").readline("Enter a filename:")
print filename

But since it looks much better, and should work according to the documentation for ruby >= 2, I am leaving it there for now.

The following works on my system (ruby 2.3.1, OS X)

require "readline"
require 'rb-readline'

module RbReadline
def self.prefill_prompt(str)
@rl_prefill = str
@rl_startup_hook = :rl_prefill_hook
end

def self.rl_prefill_hook
rl_insert_text @rl_prefill if @rl_prefill
@rl_startup_hook = nil
end
end

RbReadline.prefill_prompt("untitled.txt")
str = Readline.readline("Enter a filename:", true)

puts "You entered: #{str}"


Related Topics



Leave a reply



Submit