Class: Reline::Dumb
- Inherits:
-
IO
- Object
- IO
- Reline::Dumb
- Defined in:
- lib/reline/io/dumb.rb
Constant Summary collapse
- RESET_COLOR =
Do not send color reset sequence
''
Instance Attribute Summary collapse
-
#output ⇒ Object
writeonly
Sets the attribute output.
Instance Method Summary collapse
- #buffered_output ⇒ Object
- #clear_screen ⇒ Object
- #cursor_pos ⇒ Object
- #deprep(otio) ⇒ Object
- #dumb? ⇒ Boolean
- #encoding ⇒ Object
- #erase_after_cursor ⇒ Object
- #get_screen_size ⇒ Object
- #getc(_timeout_second) ⇒ Object
- #hide_cursor ⇒ Object
- #in_pasting? ⇒ Boolean
-
#initialize(encoding: nil) ⇒ Dumb
constructor
A new instance of Dumb.
- #input=(val) ⇒ Object
- #move_cursor_column(val) ⇒ Object
- #move_cursor_down(val) ⇒ Object
- #move_cursor_up(val) ⇒ Object
- #prep ⇒ Object
- #scroll_down(val) ⇒ Object
- #set_default_key_bindings(_) ⇒ Object
- #set_screen_size(rows, columns) ⇒ Object
- #set_winch_handler(&handler) ⇒ Object
- #show_cursor ⇒ Object
- #ungetc(c) ⇒ Object
- #with_raw_input ⇒ Object
- #write(string) ⇒ Object
Constructor Details
#initialize(encoding: nil) ⇒ Dumb
Returns a new instance of Dumb.
8 9 10 11 12 13 14 15 |
# File 'lib/reline/io/dumb.rb', line 8 def initialize(encoding: nil) @input = STDIN @output = STDOUT @buf = [] @pasting = false @encoding = encoding @screen_size = [24, 80] end |
Instance Attribute Details
#output=(value) ⇒ Object (writeonly)
Sets the attribute output
6 7 8 |
# File 'lib/reline/io/dumb.rb', line 6 def output=(value) @output = value end |
Instance Method Details
#buffered_output ⇒ Object
49 50 51 |
# File 'lib/reline/io/dumb.rb', line 49 def buffered_output yield end |
#clear_screen ⇒ Object
101 102 |
# File 'lib/reline/io/dumb.rb', line 101 def clear_screen end |
#cursor_pos ⇒ Object
76 77 78 |
# File 'lib/reline/io/dumb.rb', line 76 def cursor_pos Reline::CursorPos.new(0, 0) end |
#deprep(otio) ⇒ Object
118 119 |
# File 'lib/reline/io/dumb.rb', line 118 def deprep(otio) end |
#dumb? ⇒ Boolean
17 18 19 |
# File 'lib/reline/io/dumb.rb', line 17 def dumb? true end |
#encoding ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/reline/io/dumb.rb', line 21 def encoding if @encoding @encoding elsif RUBY_PLATFORM =~ /mswin|mingw/ Encoding::UTF_8 else @input.external_encoding || Encoding.default_external end rescue IOError # STDIN.external_encoding raises IOError in Ruby <= 3.0 when STDIN is closed Encoding.default_external end |
#erase_after_cursor ⇒ Object
95 96 |
# File 'lib/reline/io/dumb.rb', line 95 def erase_after_cursor end |
#get_screen_size ⇒ Object
72 73 74 |
# File 'lib/reline/io/dumb.rb', line 72 def get_screen_size @screen_size end |
#getc(_timeout_second) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/reline/io/dumb.rb', line 53 def getc(_timeout_second) unless @buf.empty? return @buf.shift end c = nil loop do Reline.core.line_editor.handle_signal result = @input.wait_readable(0.1) next if result.nil? c = @input.read(1) break end c&.ord end |
#hide_cursor ⇒ Object
80 81 |
# File 'lib/reline/io/dumb.rb', line 80 def hide_cursor end |
#in_pasting? ⇒ Boolean
111 112 113 |
# File 'lib/reline/io/dumb.rb', line 111 def in_pasting? @pasting end |
#input=(val) ⇒ Object
37 38 39 |
# File 'lib/reline/io/dumb.rb', line 37 def input=(val) @input = val end |
#move_cursor_column(val) ⇒ Object
86 87 |
# File 'lib/reline/io/dumb.rb', line 86 def move_cursor_column(val) end |
#move_cursor_down(val) ⇒ Object
92 93 |
# File 'lib/reline/io/dumb.rb', line 92 def move_cursor_down(val) end |
#move_cursor_up(val) ⇒ Object
89 90 |
# File 'lib/reline/io/dumb.rb', line 89 def move_cursor_up(val) end |
#prep ⇒ Object
115 116 |
# File 'lib/reline/io/dumb.rb', line 115 def prep end |
#scroll_down(val) ⇒ Object
98 99 |
# File 'lib/reline/io/dumb.rb', line 98 def scroll_down(val) end |
#set_default_key_bindings(_) ⇒ Object
34 35 |
# File 'lib/reline/io/dumb.rb', line 34 def set_default_key_bindings(_) end |
#set_screen_size(rows, columns) ⇒ Object
104 105 106 |
# File 'lib/reline/io/dumb.rb', line 104 def set_screen_size(rows, columns) @screen_size = [rows, columns] end |
#set_winch_handler(&handler) ⇒ Object
108 109 |
# File 'lib/reline/io/dumb.rb', line 108 def set_winch_handler(&handler) end |
#show_cursor ⇒ Object
83 84 |
# File 'lib/reline/io/dumb.rb', line 83 def show_cursor end |
#ungetc(c) ⇒ Object
68 69 70 |
# File 'lib/reline/io/dumb.rb', line 68 def ungetc(c) @buf.unshift(c) end |
#with_raw_input ⇒ Object
41 42 43 |
# File 'lib/reline/io/dumb.rb', line 41 def with_raw_input yield end |
#write(string) ⇒ Object
45 46 47 |
# File 'lib/reline/io/dumb.rb', line 45 def write(string) @output.write(string) end |