/src/lib/io/basic/readline_input_stream.e

http://github.com/tybor/Liberty · Specman e · 144 lines · 92 code · 22 blank · 30 comment · 5 complexity · 2b482469b9cd9da3198199a52f2815d4 MD5 · raw file

  1. -- This file is part of a Liberty Eiffel library.
  2. -- See the full copyright at the end.
  3. --
  4. class READLINE_INPUT_STREAM
  5. --
  6. -- An input stream where the data is read from CLI using GNU Readline.
  7. --
  8. -- NOTE: the history is a singleton so there is really no point in creating more than
  9. -- one readline stream...
  10. --
  11. inherit
  12. TERMINAL_INPUT_STREAM
  13. redefine
  14. valid_last_character, dispose
  15. end
  16. insert
  17. READ_LINE
  18. rename
  19. read_line as gnu_readline,
  20. last_line as gnu_lastline
  21. end
  22. create {ANY}
  23. make, make_no_history
  24. feature {ANY}
  25. set_prompt (a_prompt: like prompt)
  26. require
  27. a_prompt /= Void
  28. do
  29. prompt := a_prompt
  30. end
  31. end_of_input: BOOLEAN
  32. do
  33. Result := gnu_lastline = Void or else offset > gnu_lastline.upper
  34. end
  35. is_connected: BOOLEAN
  36. must_disconnect: BOOLEAN False
  37. can_unread_character: BOOLEAN
  38. do
  39. Result := gnu_lastline /= Void and then offset >= gnu_lastline.lower
  40. end
  41. disconnect
  42. do
  43. filter := Void
  44. is_connected := False
  45. end
  46. valid_last_character: BOOLEAN
  47. do
  48. Result := gnu_lastline /= Void and then gnu_lastline.valid_index(offset)
  49. end
  50. feature {FILTER_INPUT_STREAM}
  51. filtered_read_character
  52. do
  53. offset := offset + 1
  54. if gnu_lastline = Void or else offset > gnu_lastline.upper then
  55. gnu_readline
  56. if gnu_lastline /= Void then
  57. if keep_history and then not gnu_lastline.is_empty then
  58. history.add(gnu_lastline)
  59. end
  60. gnu_lastline.extend('%N')
  61. offset := gnu_lastline.lower
  62. end
  63. end
  64. end
  65. filtered_unread_character
  66. do
  67. offset := offset - 1
  68. end
  69. filtered_last_character: CHARACTER
  70. do
  71. Result := gnu_lastline.item(offset)
  72. end
  73. feature {FILTER}
  74. filtered_descriptor: INTEGER
  75. do
  76. std_error.put_string("READLINE_INPUT_STREAM.filtered_descriptor has been called!%N")
  77. crash
  78. end
  79. filtered_has_descriptor: BOOLEAN False
  80. filtered_stream_pointer: POINTER
  81. do
  82. std_error.put_string("READLINE_INPUT_STREAM.filtered_stream_pointer has been called!%N")
  83. crash
  84. end
  85. filtered_has_stream_pointer: BOOLEAN False
  86. feature {}
  87. dispose
  88. do
  89. -- No need to force people to disconnect such a STREAM.
  90. end
  91. make
  92. do
  93. is_connected := True
  94. keep_history := True
  95. end
  96. make_no_history
  97. do
  98. is_connected := True
  99. end
  100. offset: INTEGER
  101. keep_history: BOOLEAN
  102. end -- class READLINE_INPUT_STREAM
  103. --
  104. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  105. --
  106. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  107. -- of this software and associated documentation files (the "Software"), to deal
  108. -- in the Software without restriction, including without limitation the rights
  109. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  110. -- copies of the Software, and to permit persons to whom the Software is
  111. -- furnished to do so, subject to the following conditions:
  112. --
  113. -- The above copyright notice and this permission notice shall be included in
  114. -- all copies or substantial portions of the Software.
  115. --
  116. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  117. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  118. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  119. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  120. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  121. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  122. -- THE SOFTWARE.