Project

General

Profile

Actions

Feature #13604

closed

Exposing alternative interface of readline

Feature #13604: Exposing alternative interface of readline

Added by graywolf (Gray Wolf) over 8 years ago. Updated over 1 year ago.

Status:
Closed
Target version:
-
[ruby-core:81417]

Description

GNU Readline has multiple modes of operation. At the moment, the readline extension only supports typical, Readline.readline mode. However, there is also alternative callback-based interface which is also useful.

require_relative 'readline' PROMPT = "rltest$ " $running = true $sigwinch_received = false Readline.handler_install(PROMPT, add_hist: true) do |line| # Can use ^D (stty eof) or `exit' to exit. if !line || line == "exit" puts unless line puts "exit" Readline.handler_remove $running = false else puts "input line: #{line}" end end Signal.trap('SIGWINCH') { $sigwinch_received = true } while $running do rs = IO.select([$stdin]) if $sigwinch_received Readline.resize_terminal $sigwinch_received = false end Readline.read_char if r = rs[0] end puts "rltest: Event loop has exited" 

Patch adding support for this is attached. This is my first try at contributing to ruby, so please tell me what I did wrong (I'm sure something, C is not my strong language).


Files

readline_alternative_interface.diff (7.22 KB) readline_alternative_interface.diff Patch graywolf (Gray Wolf), 05/27/2017 10:00 AM
readline_alternative_interface_example.rb (606 Bytes) readline_alternative_interface_example.rb How it can be used? graywolf (Gray Wolf), 05/27/2017 10:00 AM
readline_alternative_interface_update1.diff (7.08 KB) readline_alternative_interface_update1.diff improved version graywolf (Gray Wolf), 05/29/2017 06:34 PM

Updated by shevegen (Robert A. Heiler) over 8 years ago Actions #1 [ruby-core:81425]

All improvements to Readline are great - I can't have commandline user interfaces in ruby (on linux) without Readline these days. :)

The only thing that I think isn't too great is the use of global variables. Is it possible to get rid of them?

Updated by graywolf (Gray Wolf) over 8 years ago Actions #2 [ruby-core:81440]

It should be possible. The bool is easy (I just set it on Readline module just like I do the handler block and I try to find a way to pass char * inside VALUE. I'll find a way and post updated patch.

I don't really see a benefit though, it's not like you can use Readline multiple times at once anyway, underlying C library doesn't support it (afaict).

Updated by graywolf (Gray Wolf) over 8 years ago Actions #3 [ruby-core:81459]

I think I managed to simplify it quite a bit, if you would take a look :)

Also I'm thinking about exposing the add_hist setting, since it's saved on mReadline anyway, it would allow user to dynamicly enable/disable auto-adding of history between each invocation of read_char. What do you think?

Updated by hsbt (Hiroshi SHIBATA) about 8 years ago Actions #4 [ruby-core:82608]

  • Status changed from Open to Assigned
  • Assignee set to kouji (Kouji Takao)

@kouji (Kouji Takao) or @nobu (Nobuyoshi Nakada)

Can you review this patch?

Updated by graywolf (Gray Wolf) almost 8 years ago Actions #5 [ruby-core:84813]

any update on this?

Updated by nobu (Nobuyoshi Nakada) almost 6 years ago Actions #6 [ruby-core:96948]

  • Assignee changed from kouji (Kouji Takao) to aycabta (aycabta .)

Updated by hsbt (Hiroshi SHIBATA) over 1 year ago Actions #7 [ruby-core:117413]

  • Status changed from Assigned to Closed

The C wrapper library of libreadline is extracted https://github.com/ruby/readline-ext from Ruby 3.3. If you still interest this, can you submit your proposal to upstream?

Actions

Also available in: PDF Atom