Guest User

Untitled

a guest
May 27th, 2018
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. require 'ffi'
  2.  
  3. module Readline
  4. extend FFI::Library
  5.  
  6. ffi_lib 'readline','libreadline.so.5.2'
  7.  
  8. attach_function :readline, [:string], :string
  9. end
  10.  
  11. module ReadlineHistory
  12. extend FFI::Library
  13.  
  14. ffi_lib 'history','libhistory.so.5.2'
  15.  
  16. class HIST_ENTRY < FFI::Struct
  17. layout :line, :string,
  18. :timestampe, :string,
  19. :data, :pointer
  20.  
  21. end
  22.  
  23. class HISTORY_STATE < FFI::Struct
  24. layout :entries, :pointer,
  25. :offset, :int,
  26. :length, :int,
  27. :size, :int,
  28. :flags, :int
  29.  
  30. end
  31.  
  32. attach_function :using_history, [], :void
  33. attach_function :add_history, [:string], :void
  34. attach_function :add_history_time, [:string], :void
  35. attach_function :remove_history, [:int], :pointer
  36. end
  37.  
  38. ReadlineHistory.using_history
  39.  
  40. loop do
  41. tmp = Readline.readline "> "
  42.  
  43. if tmp == "quit" or tmp == "q"
  44. break
  45. end
  46.  
  47. ReadlineHistory.add_history tmp if tmp
  48. end
Add Comment
Please, Sign In to add comment