Methods
#
B
C
D
E
F
G
I
L
O
P
R
S
T
U
W
Constants
OPT_DEFAULTS = { 'mode' => nil, 'overwrite' => false, 'text' => nil, 'show' => :pos, 'wrap' => 'char', 'sync' => true, 'prompt' => nil, 'prompt_cmd' => nil, 'hist_size' => 1000, }
 
Instance Public methods
<<(obj)
# File ext/tk/sample/tktextio.rb, line 397
def <<(obj)
  _write(obj)
  self
end
binmode()
# File ext/tk/sample/tktextio.rb, line 402
def binmode
  self
end
clone()
# File ext/tk/sample/tktextio.rb, line 406
def clone
  fail NotImplementedError, 'cannot clone TkTextIO'
end
close()
# File ext/tk/sample/tktextio.rb, line 413
def close
  close_read
  close_write
  nil
end
close_read()
# File ext/tk/sample/tktextio.rb, line 418
def close_read
  @open[:r] = false if @open[:r]
  nil
end
close_write()
# File ext/tk/sample/tktextio.rb, line 422
def close_write
  @open[:w] = false if @opne[:w]
  nil
end
closed?(dir=nil)
# File ext/tk/sample/tktextio.rb, line 427
def closed?(dir=nil)
  case dir
  when :r, 'r'
    !@open[:r]
  when :w, 'w'
    !@open[:w]
  else
    !@open[:r] && !@open[:w]
  end
end
destroy()
# File ext/tk/sample/tktextio.rb, line 75
def destroy
  @flusher.kill rescue nil

  @idle_flush.stop rescue nil
  @timer_flush.stop rescue nil

  @receiver.kill rescue nil

  super()
end
dup()
# File ext/tk/sample/tktextio.rb, line 409
def dup
  fail NotImplementedError, 'cannot duplicate TkTextIO'
end
each(rs = $/)
Alias for: each_line
each_byte()
Alias for: each_char
each_char()
Also aliased as: each_byte
# File ext/tk/sample/tktextio.rb, line 457
def each_char
  _check_readable
  while(c = self.getc)
    yield(c)
  end
  self
end
each_line(rs = $/)
Also aliased as: each
# File ext/tk/sample/tktextio.rb, line 448
def each_line(rs = $/)
  _check_readable
  while(s = self.gets(rs))
    yield(s)
  end
  self
end
eof()
Alias for: eof?
eof?()
Also aliased as: eof
# File ext/tk/sample/tktextio.rb, line 466
def eof?
  compare(@txtpos, '==', 'end - 1 char')
end
fcntl(*args)
# File ext/tk/sample/tktextio.rb, line 471
def fcntl(*args)
  fail NotImplementedError, "fcntl is not implemented on #{self.class}"
end
fileno()
# File ext/tk/sample/tktextio.rb, line 479
def fileno
  nil
end
flush()
# File ext/tk/sample/tktextio.rb, line 483
def flush
  Thread.pass
  if @open[:w] || ! @write_buffer.empty?
    @write_buf_mutex.synchronize {
      _sync_write_buf(@write_buffer)
      @write_buffer[0..-1] = ''
    }
  end
  self
end
fsync()
# File ext/tk/sample/tktextio.rb, line 475
def fsync
  0
end
getc()
# File ext/tk/sample/tktextio.rb, line 494
def getc
  return _block_read(1) if @console_mode

  _check_readable
  return nil if eof?
  c = get(@txtpos)
  @txtpos.set(@txtpos + '1 char')
  _see_pos
  c
end
gets(rs = $/)
# File ext/tk/sample/tktextio.rb, line 505
def gets(rs = $/)
  return _block_read(rs) if @console_mode

  _check_readable
  return nil if eof?
  _readline(rs)
end
index_pos()
Also aliased as: tell_index
# File ext/tk/sample/tktextio.rb, line 545
def index_pos
  index(@txtpos)
end
index_pos=(idx)
# File ext/tk/sample/tktextio.rb, line 550
def index_pos=(idx)
  @txtpos.set(idx)
  @txtpos.set('end - 1 char') if compare(@txtpos, '>=', :end)
  _see_pos
  idx
end
ioctrl(*args)
# File ext/tk/sample/tktextio.rb, line 513
def ioctrl(*args)
  fail NotImplementedError, 'iocntl is not implemented on TkTextIO'
end
isatty()
# File ext/tk/sample/tktextio.rb, line 517
def isatty
  false
end
lineno()
# File ext/tk/sample/tktextio.rb, line 524
def lineno
  @lineno + @line_offset
end
lineno=(num)
# File ext/tk/sample/tktextio.rb, line 528
def lineno=(num)
  @line_offset = num - @lineno
  num
end
overwrite=(ovwt)
# File ext/tk/sample/tktextio.rb, line 537
def overwrite=(ovwt)
  @overwrite = (ovwt)? true: false
end
overwrite?()
# File ext/tk/sample/tktextio.rb, line 533
def overwrite?
  @overwrite
end
pid()
# File ext/tk/sample/tktextio.rb, line 541
def pid
  nil
end
pos()
Also aliased as: tell
# File ext/tk/sample/tktextio.rb, line 557
def pos
  s = get('1.0', @txtpos)
  number(tk_call('string', 'length', s))
end
pos=(idx)
# File ext/tk/sample/tktextio.rb, line 563
def pos=(idx)
  seek(idx, IO::SEEK_SET)
  idx
end
pos_gravity()
# File ext/tk/sample/tktextio.rb, line 568
def pos_gravity
  @txtpos.gravity
end
pos_gravity=(side)
# File ext/tk/sample/tktextio.rb, line 572
def pos_gravity=(side)
  @txtpos.gravity = side
  side
end
print(arg=$_, *args)
# File ext/tk/sample/tktextio.rb, line 577
def print(arg=$_, *args)
  _check_writable
  args.unshift(arg)
  args.map!{|val| (val == nil)? 'nil': val.to_s }
  str = args.join($,)
  str << $\ if $\
  _write(str)
  nil
end
printf(*args)
# File ext/tk/sample/tktextio.rb, line 586
def printf(*args)
  _check_writable
  _write(sprintf(*args))
  nil
end
putc(c)
# File ext/tk/sample/tktextio.rb, line 592
def putc(c)
  _check_writable
  c = c.chr if c.kind_of?(Fixnum)
  _write(c)
  c
end
puts(*args)
# File ext/tk/sample/tktextio.rb, line 599
def puts(*args)
  _check_writable
  if args.empty?
    _write("\n")
    return nil
  end
  args.each{|arg|
    if arg == nil
      _write("nil\n")
    elsif arg.kind_of?(Array)
      puts(*arg)
    elsif arg.kind_of?(String)
      _write(arg.chomp)
      _write("\n")
    else
      begin
        arg = arg.to_ary
        puts(*arg)
      rescue
        puts(arg.to_s)
      end
    end
  }
  nil
end
read(len=nil, buf=nil)
# File ext/tk/sample/tktextio.rb, line 635
def read(len=nil, buf=nil)
  return _block_read(len, buf) if @console_mode

  _check_readable
  if len
    return "" if len == 0
    return nil if eof?
    s = _read(len)
  else
    s = get(@txtpos, 'end - 1 char')
    @txtpos.set('end - 1 char')
    _see_pos
  end
  buf.replace(s) if buf.kind_of?(String)
  s
end
readchar()
# File ext/tk/sample/tktextio.rb, line 652
def readchar
  return _block_read(1) if @console_mode

  _check_readable
  fail EOFError if eof?
  c = get(@txtpos)
  @txtpos.set(@txtpos + '1 char')
  _see_pos
  c
end
readline(rs = $/)
# File ext/tk/sample/tktextio.rb, line 698
def readline(rs = $/)
  return _block_readline(rs) if @console_mode

  _check_readable
  fail EOFError if eof?
  _readline(rs)
end
readlines(rs = $/)
# File ext/tk/sample/tktextio.rb, line 706
def readlines(rs = $/)
  if @console_mode
    lines = []
    while (line = _block_readline(rs))
      lines << line
    end
    return lines
  end

  _check_readable
  lines = []
  until(eof?)
    lines << _readline(rs)
  end
  $_ = nil
  lines
end
readpartial(maxlen, buf=nil)
# File ext/tk/sample/tktextio.rb, line 724
def readpartial(maxlen, buf=nil)
  #return @console_buffer.readpartial(maxlen, buf) if @console_mode
  return _block_read(maxlen, buf, nil) if @console_mode

  _check_readable
  fail EOFError if eof?
  s = _read(maxlen)
  buf.replace(s) if buf.kind_of?(String)
  s
end
reopen(*args)
# File ext/tk/sample/tktextio.rb, line 735
def reopen(*args)
  fail NotImplementedError, 'reopen is not implemented on TkTextIO'
end
rewind()
# File ext/tk/sample/tktextio.rb, line 739
def rewind
  @txtpos.set('1.0')
  _see_pos
  @lineno = 0
  @line_offset = 0
  self
end
seek(offset, whence=IO::SEEK_SET)
Also aliased as: sysseek
# File ext/tk/sample/tktextio.rb, line 747
def seek(offset, whence=IO::SEEK_SET)
  case whence
  when IO::SEEK_SET
    offset = "1.0 + #{offset} char" if offset.kind_of?(Numeric)
    @txtpos.set(offset)

  when IO::SEEK_CUR
    offset = "#{offset} char" if offset.kind_of?(Numeric)
    @txtpos.set(@txtpos + offset)

  when IO::SEEK_END
    offset = "#{offset} char" if offset.kind_of?(Numeric)
    @txtpos.set("end - 1 char + #{offset}")

  else
    fail Errno::EINVAL, 'invalid whence argument'
  end

  @txtpos.set('end - 1 char') if compare(@txtpos, '>=', :end)
  _see_pos

  0
end
show_mode()
# File ext/tk/sample/tktextio.rb, line 777
def show_mode
  (@show == @txtpos)? :pos : @show
end
show_mode=(mode)
# File ext/tk/sample/tktextio.rb, line 781
def show_mode=(mode)
  # define show mode  when file position is changed.
  #  mode == :pos or "pos" or true :: see current file position.
  #  mode == :insert or "insert"   :: see insert cursor position.
  #  mode == nil or false          :: do nothing
  #  else see 'mode' position ('mode' should be text index or mark)
  case mode
  when :pos, 'pos', true
    @show = @txtpos
  when :insert, 'insert'
    @show = :insert
  when nil, false
    @show = false
  else
    begin
      index(mode)
    rescue
      fail ArgumentError, 'invalid show-position'
    end
    @show = mode
  end

  _see_pos

  mode
end
stat()
# File ext/tk/sample/tktextio.rb, line 808
def stat
  fail NotImplementedError, 'stat is not implemented on TkTextIO'
end
sync()
# File ext/tk/sample/tktextio.rb, line 812
def sync
  @sync
end
sync=(mode)
# File ext/tk/sample/tktextio.rb, line 816
def sync=(mode)
  @sync = mode
end
sysread(len, buf=nil)
# File ext/tk/sample/tktextio.rb, line 820
def sysread(len, buf=nil)
  return _block_read(len, buf) if @console_mode

  _check_readable
  fail EOFError if eof?
  s = _read(len)
  buf.replace(s) if buf.kind_of?(String)
  s
end
sysseek(offset, whence=IO::SEEK_SET)
Alias for: seek
syswrite(obj)
# File ext/tk/sample/tktextio.rb, line 830
def syswrite(obj)
  _write(obj)
end
tell()
Alias for: pos
tell_index()
Alias for: index_pos
to_io()
# File ext/tk/sample/tktextio.rb, line 834
def to_io
  self
end
trancate(len)
# File ext/tk/sample/tktextio.rb, line 838
def trancate(len)
  delete("1.0 + #{len} char", :end)
  0
end
tty?()
# File ext/tk/sample/tktextio.rb, line 520
def tty?
  false
end
ungetc(c)
# File ext/tk/sample/tktextio.rb, line 843
def ungetc(c)
  if @console_mode
    @read_buf_mutex.synchronize {
      @read_buffer[0,0] = c.chr
    }
    return nil
  end

  _check_readable
  c = c.chr if c.kind_of?(Fixnum)
  if compare(@txtpos, '>', '1.0')
    @txtpos.set(@txtpos - '1 char')
    delete(@txtpos)
    insert(@txtpos, tk_call('string', 'range', c, 0, 1))
    @txtpos.set(@txtpos - '1 char') if @txtpos.gravity == 'right'
    _see_pos
  else
    fail IOError, 'cannot ungetc at head of stream'
  end
  nil
end
write(obj)

end

# File ext/tk/sample/tktextio.rb, line 911
def write(obj)
  _check_writable
  _write(obj)
end