Created
December 5, 2013 20:23
-
-
Save kazz187/7813206 to your computer and use it in GitHub Desktop.
readline supports startup_hook.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'readline' | |
require 'fiddle/import' | |
module Readline | |
module LIBREADLINE | |
extend Fiddle::Importer | |
# このパスどうしよ | |
dlload '/usr/local/opt/readline/lib/libreadline.6.2.dylib' | |
RL_STARTUP_HOOK = import_symbol 'rl_startup_hook' | |
end | |
def self.set_startup_hook(&blk) | |
ptr = LIBREADLINE::RL_STARTUP_HOOK | |
cf = LIBREADLINE::bind('int startup_hook_callback()') { blk.call } | |
ptr[0, Fiddle::SIZEOF_VOIDP] = [cf.to_i].pack(Fiddle::SIZEOF_VOIDP == 4 ? 'I!' : 'L!') | |
end | |
end | |
loop do | |
Readline.set_startup_hook do | |
Readline.insert_text 'default text' | |
0 | |
end | |
buf = Readline.readline '> ', true | |
puts buf | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
と言うか、 startup_hook くらい最初からサポートしてて欲しい