Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'ffi'
- module Readline
- extend FFI::Library
- ffi_lib 'readline','libreadline.so.5.2'
- attach_function :readline, [:string], :string
- end
- module ReadlineHistory
- extend FFI::Library
- ffi_lib 'history','libhistory.so.5.2'
- class HIST_ENTRY < FFI::Struct
- layout :line, :string,
- :timestampe, :string,
- :data, :pointer
- end
- class HISTORY_STATE < FFI::Struct
- layout :entries, :pointer,
- :offset, :int,
- :length, :int,
- :size, :int,
- :flags, :int
- end
- attach_function :using_history, [], :void
- attach_function :add_history, [:string], :void
- attach_function :add_history_time, [:string], :void
- attach_function :remove_history, [:int], :pointer
- end
- ReadlineHistory.using_history
- loop do
- tmp = Readline.readline "> "
- if tmp == "quit" or tmp == "q"
- break
- end
- ReadlineHistory.add_history tmp if tmp
- end
Add Comment
Please, Sign In to add comment