/src/wrappers/readline/library/read_line.e

http://github.com/tybor/Liberty · Specman e · 74 lines · 44 code · 12 blank · 18 comment · 1 complexity · 41f8db4b53cb5cf560d363df099e080d MD5 · raw file

  1. deferred class READ_LINE
  2. -- Interface to the GNU readline library
  3. -- Insert this class to get access to library interface.
  4. insert
  5. WRAPPER_HANDLER
  6. READLINE_EXTERNALS
  7. STRING_HANDLER
  8. undefine
  9. is_equal, copy
  10. end
  11. feature {ANY} -- Read line
  12. prompt: ABSTRACT_STRING
  13. -- The prompt presented to the user
  14. last_line: STRING -- The last line read by `read_line'
  15. read_line
  16. -- Print `prompt' and read a line, put into `last_line'
  17. local
  18. p: POINTER
  19. do
  20. p := readline(null_or_string(prompt))
  21. if p.is_not_null then
  22. create last_line.from_external(p)
  23. else
  24. -- if ^D is pressed
  25. last_line := Void
  26. end
  27. end
  28. buffer: FIXED_STRING
  29. do
  30. Result := buffer_
  31. Result.from_external(rl_line_buffer)
  32. end
  33. completion: READ_LINE_COMPLETION
  34. local
  35. c: READLINE_CECIL -- we need that indirection to force Liberty Eiffel to "see" the assignment READLINE_CECIL -> READ_LINE_COMPLETION
  36. once
  37. create {READ_LINE_COMPLETION} c.make
  38. Result ::= c
  39. end
  40. history: READ_LINE_HISTORY
  41. once
  42. create Result.using_history
  43. end
  44. feature {}
  45. buffer_: FIXED_STRING
  46. once
  47. create Result.make_from_string("deadstring")
  48. end
  49. end -- class READ_LINE
  50. -- Copyright (C) 2010-2017: Paolo Redaelli, 2012 Cyril Adrian
  51. -- This library is free software: you can redistribute it and/or modify
  52. -- it under the terms of the GNU General Public License as published by
  53. -- the Free Software Foundation, either version 3 of the License, or
  54. -- (at your option) any later version.
  55. --
  56. -- This package is distributed in the hope that it will be useful,
  57. -- but WITHOUT ANY WARRANTY; without even the implied warranty of
  58. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  59. -- GNU General Public License for more details.
  60. --
  61. -- You should have received a copy of the GNU General Public License
  62. -- along with Readline. If not, see <http://www.gnu.org/licenses/>.