From: wolf@... Date: 2017-05-28T18:47:23+00:00 Subject: [ruby-core:81440] [Ruby trunk Feature#13604] Exposing alternative interface of readline Issue #13604 has been updated by graywolf (Gray Wolf). 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). ---------------------------------------- Feature #13604: Exposing alternative interface of readline https://bugs.ruby-lang.org/issues/13604#change-65144 * Author: graywolf (Gray Wolf) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- 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. ```ruby 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_example.rb (606 Bytes) -- https://bugs.ruby-lang.org/ Unsubscribe: