Class: GenericIOMethod

Inherits:
IRB::StdioInputMethod
  • Object
show all
Defined in:
lib/live_console.rb

Overview

The GenericIOMethod is a class that wraps I/O for IRB.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, output = nil, readline = false) ⇒ GenericIOMethod

call-seq: GenericIOMethod.new io GenericIOMethod.new input, output

Creates a GenericIOMethod, using either a single object for both input and output, or one object for input and another for output.



232
233
234
235
236
237
# File 'lib/live_console.rb', line 232

def initialize(input, output = nil, readline=false)
  @input, @output = input, output
  @line = []
  @line_no = 0
  @readline = readline
end

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



239
240
241
# File 'lib/live_console.rb', line 239

def input
  @input
end

Instance Method Details

#closeObject



280
281
282
283
# File 'lib/live_console.rb', line 280

def close
  input.close
  output.close if @output
end

#encodingObject



276
277
278
# File 'lib/live_console.rb', line 276

def encoding
  input.external_encoding
end

#eof?Boolean

Returns:

  • (Boolean)


272
273
274
# File 'lib/live_console.rb', line 272

def eof?
  input.eof?
end

#file_nameObject



268
269
270
# File 'lib/live_console.rb', line 268

def file_name
  input.inspect
end

#getsObject



244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/live_console.rb', line 244

def gets
  output.print @prompt
  output.flush
  line = input.gets
  if @readline
    #Return tab completion data as long as we receive input that ends in '\t'
    while line.chomp =~ /\t\z/n
      run_completion_proc line.chomp.chop
      line = input.gets
    end
  end
  @line[@line_no += 1] = line
  @line[@line_no]
end

#linesObject

Returns the user input history.



260
261
262
# File 'lib/live_console.rb', line 260

def lines
  @line.dup
end

#outputObject



240
241
242
# File 'lib/live_console.rb', line 240

def output
  @output || input
end


264
265
266
# File 'lib/live_console.rb', line 264

def print(*a)
  output.print *a
end