PageRenderTime 15ms CodeModel.GetById 12ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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