Class: TkTextIO
Constant Summary
collapse
- OPT_DEFAULTS =
{
'mode' => nil,
'overwrite' => false,
'text' => nil,
'show' => :pos,
'wrap' => 'char',
'sync' => true,
'prompt' => nil,
'prompt_cmd' => nil,
'hist_size' => 1000,
}
- @@create_queues =
proc{ [Queue.new, Mutex.new, Queue.new, Mutex.new] }
Constants inherited
from TkText
TkText::ItemConfCMD, TkText::TkCommandNames, TkText::WidgetClassName
Constants included
from TkUtil
TkUtil::None, TkUtil::RELEASE_DATE
Constants inherited
from TkTextWin
TkTextWin::TkCommandNames
Constants inherited
from TkWindow
TkWindow::TkCommandNames, TkWindow::WidgetClassName
Constants included
from TkWinfo
TkWinfo::TkCommandNames
Constants included
from Tk
Tk::AUTO_PATH, Tk::INTERP, Tk::JAPANIZED_TK, Tk::LIBRARY_PATH, Tk::MAINLOOP, Tk::PACKAGE_PATH, Tk::RELEASE_DATE, Tk::TCL_LIBRARY_PATH, Tk::TCL_MAJOR_VERSION, Tk::TCL_MINOR_VERSION, Tk::TCL_PACKAGE_PATH, Tk::TCL_PATCHLEVEL, Tk::TCL_PRECISION, Tk::TCL_VERSION, Tk::TK_MAJOR_VERSION, Tk::TK_MINOR_VERSION, Tk::TK_PATCHLEVEL, Tk::TK_VERSION, Tk::Tkextlib_RELEASE_DATE, Tk::TreeCtrl_Widget, Tk::X_Scrollable, Tk::Y_Scrollable
Tk::Encoding::TkCommandNames
Constants included
from TkCore
TkCore::EventFlag, TkCore::INTERP, TkCore::WIDGET_DESTROY_HOOK
Constants included
from TkComm
TkComm::GET_CONFIGINFO_AS_ARRAY, TkComm::GET_CONFIGINFOwoRES_AS_ARRAY, TkComm::TkExtlibAutoloadModule, TkComm::Tk_CMDTBL, TkComm::Tk_IDs, TkComm::Tk_WINDOWS, TkComm::USE_TCLs_LIST_FUNCTIONS, TkComm::WidgetClassNames
Tk::TkDND::Shape::PACKAGE_NAME
Instance Method Summary
collapse
Methods inherited from TkText
#__destroy_hook__, #_addcmd, #_addtag, at, #at, #backspace, #bbox, #clear, #compare, #count, #count_info, #current_image_configinfo, #debug, #debug=, #dlineinfo, #dump, #dump_all, #dump_image, #dump_mark, #dump_tag, #dump_text, #dump_window, #edit_redo, #edit_reset, #edit_separator, #edit_undo, #get_displaychars, #image_cget, #image_configinfo, #image_configure, #image_names, #index, #init_instance_variable, #insert, #mark_gravity, #mark_names, #mark_next, #mark_previous, #mark_set, #mark_unset, #modified, #modified=, #modified?, new, #peer_names, #replace, #rsearch, #rsearch_with_length, #search, #search_with_length, #set_current, #set_insert, #tag_add, #tag_bind, #tag_bind_append, #tag_bind_remove, #tag_bindinfo, #tag_delete, #tag_lower, #tag_names, #tag_nextrange, #tag_prevrange, #tag_raise, #tag_ranges, #tag_remove, #tagid2obj, #text_copy, #text_cut, #text_paste, #tksearch, #tksearch_with_count, #value, #value=, #window_names, #xview_pickplace, #yview_pickplace
#current_tag_configinfo, #current_window_configinfo, #tag_cget, #tag_configinfo, #tag_configure, #window_cget, #window_configinfo, #window_configure
#current_itemconfiginfo, #itemcget, #itemconfiginfo, #itemconfigure, #tagid
#__conv_item_keyonly_opts, #itemconfig_hash_kv
Methods included from TkUtil
_conv_args, #_conv_args, #_fromUTF8, _get_eval_enc_str, #_get_eval_enc_str, #_get_eval_string, _get_eval_string, _symbolkey2str, #_symbolkey2str, #_toUTF8, bool, #bool, callback, eval_cmd, #hash_kv, hash_kv, install_cmd, num_or_str, #num_or_str, number, #number, string, #string, uninstall_cmd
#kanjifont_copy, #kanjitagfont_configure, #latintagfont_configure, #latintagfont_copy, #tagfont_configinfo, #tagfont_configure, #tagfont_copy
Methods inherited from TkTextWin
#bbox, #delete, #get, #insert, #scan_dragto, #scan_mark, #see
Methods inherited from TkWindow
#bind_class, #bindtags, #bindtags=, #bindtags_shift, #bindtags_unshift, #caret, #colormodel, #command, #cursor_propagate, #cursor_restore, #database_class, database_class, #database_classname, database_classname, #eventloop_wait_destroy, #eventloop_wait_visibility, #exist?, #grab, #grab_current, #grab_release, #grab_set, #grab_set_global, #grab_status, #grid, #grid_bbox, #grid_columnconfig, #grid_columnconfiginfo, #grid_config, #grid_forget, #grid_in, #grid_info, #grid_location, #grid_propagate, #grid_remove, #grid_rowconfig, #grid_rowconfiginfo, #grid_size, #grid_slaves, #initialize, #lower, #pack, #pack_config, #pack_forget, #pack_in, #pack_info, #pack_propagate, #pack_slaves, #place, #place_config, #place_configinfo, #place_forget, #place_in, #place_info, #place_slaves, #raise, #set_focus, #thread_wait_destroy, #thread_wait_visibility, #tktrans_get_image, #tktrans_set_image, to_eval, #wait_destroy, #wait_visibility
Methods included from TkBindCore
#bind, #bind_append, #bind_remove, #bindinfo
Methods included from TkWinfo
appname, atom, atomname, cells, children, classname, colormapfull, containing, depth, exist?, fpixels, geometry, height, id, interps, manager, mapped?, parent, pixels, pointerx, pointerxy, pointery, reqheight, reqwidth, rgb, rootx, rooty, screen, screencells, screendepth, screenheight, screenmmheight, screenmmwidth, screenvisual, screenwidth, server, toplevel, viewable, visual, visualid, visualsavailable, vrootheight, vrootwidth, vrootx, vrooty, widget, width, #winfo_appname, #winfo_atom, #winfo_atomname, #winfo_cells, #winfo_children, #winfo_classname, #winfo_colormapfull, #winfo_containing, #winfo_depth, #winfo_exist?, #winfo_fpixels, #winfo_geometry, #winfo_height, #winfo_id, #winfo_interps, #winfo_manager, #winfo_mapped?, #winfo_parent, #winfo_pixels, #winfo_pointerx, #winfo_pointerxy, #winfo_pointery, #winfo_reqheight, #winfo_reqwidth, #winfo_rgb, #winfo_rootx, #winfo_rooty, #winfo_screen, #winfo_screencells, #winfo_screendepth, #winfo_screenheight, #winfo_screenmmheight, #winfo_screenmmwidth, #winfo_screenvisual, #winfo_screenwidth, #winfo_server, #winfo_toplevel, #winfo_viewable, #winfo_visual, #winfo_visualid, #winfo_visualsavailable, #winfo_vrootheight, #winfo_vrootwidth, #winfo_vrootx, #winfo_vrooty, #winfo_widget, #winfo_width, #winfo_x, #winfo_y, x, y
Methods included from Tk
BinaryString, EncodedString, UTF8_String, add_kinsoku, bell, bell_on_display, const_missing, current_grabs, cursor_display, delete_kinsoku, destroy, #encoding, #encoding=, errorCode, errorInfo, exit, focus, focus_lastfor, focus_next, focus_prev, focus_to, fromUTF8, grid, grid_forget, has_mainwindow?, load_tcllibrary, load_tclscript, load_tclscript_rsrc, load_tclscript_rsrcid, lower_window, pack, pack_forget, pkgconfig_get, pkgconfig_list, place, place_forget, raise_window, #root, show_kinsoku, strictMotif, subst_tk_backslash, subst_utf_backslash, tcl_pkgconfig_get, tcl_pkgconfig_list, thread_update, thread_update_idletasks, tk_pkgconfig_get, tk_pkgconfig_list, toUTF8, to_backslash_sequence, ungrid, unload_tcllibrary, unpack, unplace, #update, update, update_idletasks, utf_to_backslash, utf_to_backslash_sequence
#encoding, #encoding=, #encoding_convertfrom, #encoding_convertto, #encoding_dirs, #encoding_dirs=, #encoding_names, #encoding_system, #encoding_system=
Methods included from TkCore
#_tk_call_to_list_core, #after, #after_cancel, #after_idle, #appname, #appsend, #appsend_deny, #appsend_displayof, callback, #callback_break, #callback_continue, #callback_return, #chooseColor, #chooseDirectory, #do_one_event, #event_generate, #getMultipleOpenFile, #getMultipleSaveFile, #getOpenFile, #getSaveFile, #get_eventloop_tick, #get_eventloop_weight, #get_no_event_wait, #inactive, #inactive_displayof, #info, #ip_eval, #ip_eval_with_enc, #ip_eval_without_enc, #ip_invoke, #ip_invoke_with_enc, #ip_invoke_without_enc, #is_mainloop?, #load_cmd_on_ip, #mainloop, #mainloop_exist?, #mainloop_thread?, #mainloop_watchdog, #messageBox, #rb_appsend, #rb_appsend_displayof, #reset_inactive, #reset_inactive_displayof, #restart, #scaling, #scaling_displayof, #set_eventloop_tick, #set_eventloop_weight, #set_no_event_wait, #tk_call, #tk_call_to_list, #tk_call_to_list_with_enc, #tk_call_to_list_without_enc, #tk_call_to_simplelist, #tk_call_to_simplelist_with_enc, #tk_call_to_simplelist_without_enc, #tk_call_with_enc, #tk_call_without_enc, #windowingsystem
Methods included from TkComm
#_at, #bind, #bind_all, #bind_append, #bind_append_all, #bind_remove, #bind_remove_all, #bindinfo, #bindinfo_all, #image_obj, #install_cmd, #subst, #uninstall_cmd
Methods included from TkEvent
#install_bind, #install_bind_for_event_class
package_name, package_patchlevel, package_version, #shape_bounds, #shape_get, #shape_offset, #shape_set, #shape_update, version
#dnd_bindsource, #dnd_bindsource_info, #dnd_bindtarget, #dnd_bindtarget_info, #dnd_clearsource, #dnd_cleartarget, #dnd_drag, version
Methods inherited from TkObject
#epath, #event_generate, #method_missing, #path, #tk_send, #tk_send_to_list, #tk_send_to_list_with_enc, #tk_send_to_list_without_enc, #tk_send_to_simplelist, #tk_send_to_simplelist_with_enc, #tk_send_to_simplelist_without_enc, #tk_send_with_enc, #tk_send_without_enc, #to_eval
#[], #[]=, #cget, #config_hash_kv, #configinfo, #configure, #configure_cmd, #current_configinfo
#font_configinfo, #font_configure, #font_copy, #kanjifont_configure, #kanjifont_copy, #latinfont_configure, #latinfont_copy
Methods inherited from TkKernel
new
Constructor Details
This class inherits a constructor from TkWindow
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class TkObject
Instance Method Details
387
388
389
390
|
# File 'sample/tktextio.rb', line 387
def <<(obj)
_write(obj)
self
end
|
392
393
394
|
# File 'sample/tktextio.rb', line 392
def binmode
self
end
|
396
397
398
|
# File 'sample/tktextio.rb', line 396
def clone
fail NotImplementedError, 'cannot clone TkTextIO'
end
|
403
404
405
406
407
|
# File 'sample/tktextio.rb', line 403
def close
close_read
close_write
nil
end
|
#close_read ⇒ Object
408
409
410
411
|
# File 'sample/tktextio.rb', line 408
def close_read
@open[:r] = false if @open[:r]
nil
end
|
#close_write ⇒ Object
412
413
414
415
|
# File 'sample/tktextio.rb', line 412
def close_write
@open[:w] = false if @opne[:w]
nil
end
|
#closed?(dir = nil) ⇒ Boolean
417
418
419
420
421
422
423
424
425
426
|
# File 'sample/tktextio.rb', line 417
def closed?(dir=nil)
case dir
when :r, 'r'
!@open[:r]
when :w, 'w'
!@open[:w]
else
!@open[:r] && !@open[:w]
end
end
|
75
76
77
78
79
80
81
82
83
84
|
# File '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
|
399
400
401
|
# File 'sample/tktextio.rb', line 399
def dup
fail NotImplementedError, 'cannot duplicate TkTextIO'
end
|
#each_char ⇒ Object
Also known as:
each_byte
447
448
449
450
451
452
453
|
# File 'sample/tktextio.rb', line 447
def each_char
_check_readable
while(c = self.getc)
yield(c)
end
self
end
|
#each_line(rs = $/) ⇒ Object
Also known as:
each
438
439
440
441
442
443
444
|
# File 'sample/tktextio.rb', line 438
def each_line(rs = $/)
_check_readable
while(s = self.gets(rs))
yield(s)
end
self
end
|
#eof? ⇒ Boolean
Also known as:
eof
456
457
458
|
# File 'sample/tktextio.rb', line 456
def eof?
compare(@txtpos, '==', 'end - 1 char')
end
|
#fcntl(*args) ⇒ Object
461
462
463
|
# File 'sample/tktextio.rb', line 461
def fcntl(*args)
fail NotImplementedError, "fcntl is not implemented on #{self.class}"
end
|
469
470
471
|
# File 'sample/tktextio.rb', line 469
def fileno
nil
end
|
473
474
475
476
477
478
479
480
481
482
|
# File 'sample/tktextio.rb', line 473
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
|
465
466
467
|
# File 'sample/tktextio.rb', line 465
def fsync
0
end
|
484
485
486
487
488
489
490
491
492
493
|
# File 'sample/tktextio.rb', line 484
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 = $/) ⇒ Object
495
496
497
498
499
500
501
|
# File 'sample/tktextio.rb', line 495
def gets(rs = $/)
return _block_read(rs) if @console_mode
_check_readable
return nil if eof?
_readline(rs)
end
|
#index_pos ⇒ Object
Also known as:
tell_index
535
536
537
|
# File 'sample/tktextio.rb', line 535
def index_pos
index(@txtpos)
end
|
#index_pos=(idx) ⇒ Object
540
541
542
543
544
545
|
# File 'sample/tktextio.rb', line 540
def index_pos=(idx)
@txtpos.set(idx)
@txtpos.set('end - 1 char') if compare(@txtpos, '>=', :end)
_see_pos
idx
end
|
#ioctrl(*args) ⇒ Object
503
504
505
|
# File 'sample/tktextio.rb', line 503
def ioctrl(*args)
fail NotImplementedError, 'iocntl is not implemented on TkTextIO'
end
|
507
508
509
|
# File 'sample/tktextio.rb', line 507
def isatty
false
end
|
514
515
516
|
# File 'sample/tktextio.rb', line 514
def lineno
@lineno + @line_offset
end
|
#lineno=(num) ⇒ Object
518
519
520
521
|
# File 'sample/tktextio.rb', line 518
def lineno=(num)
@line_offset = num - @lineno
num
end
|
#overwrite=(ovwt) ⇒ Object
527
528
529
|
# File 'sample/tktextio.rb', line 527
def overwrite=(ovwt)
@overwrite = (ovwt)? true: false
end
|
#overwrite? ⇒ Boolean
523
524
525
|
# File 'sample/tktextio.rb', line 523
def overwrite?
@overwrite
end
|
531
532
533
|
# File 'sample/tktextio.rb', line 531
def pid
nil
end
|
#pos ⇒ Object
Also known as:
tell
547
548
549
550
|
# File 'sample/tktextio.rb', line 547
def pos
s = get('1.0', @txtpos)
number(tk_call('string', 'length', s))
end
|
#pos=(idx) ⇒ Object
553
554
555
556
|
# File 'sample/tktextio.rb', line 553
def pos=(idx)
seek(idx, IO::SEEK_SET)
idx
end
|
#pos_gravity ⇒ Object
558
559
560
|
# File 'sample/tktextio.rb', line 558
def pos_gravity
@txtpos.gravity
end
|
#pos_gravity=(side) ⇒ Object
562
563
564
565
|
# File 'sample/tktextio.rb', line 562
def pos_gravity=(side)
@txtpos.gravity = side
side
end
|
#print(arg = $_, *args) ⇒ Object
567
568
569
570
571
572
573
574
575
|
# File 'sample/tktextio.rb', line 567
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) ⇒ Object
576
577
578
579
580
|
# File 'sample/tktextio.rb', line 576
def printf(*args)
_check_writable
_write(sprintf(*args))
nil
end
|
582
583
584
585
586
587
|
# File 'sample/tktextio.rb', line 582
def putc(c)
_check_writable
c = c.chr if c.kind_of?(Fixnum)
_write(c)
c
end
|
#puts(*args) ⇒ Object
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
|
# File 'sample/tktextio.rb', line 589
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) ⇒ Object
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
|
# File 'sample/tktextio.rb', line 625
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
|
642
643
644
645
646
647
648
649
650
651
|
# File 'sample/tktextio.rb', line 642
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 = $/) ⇒ Object
688
689
690
691
692
693
694
|
# File 'sample/tktextio.rb', line 688
def readline(rs = $/)
return _block_readline(rs) if @console_mode
_check_readable
fail EOFError if eof?
_readline(rs)
end
|
#readlines(rs = $/) ⇒ Object
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
|
# File 'sample/tktextio.rb', line 696
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) ⇒ Object
714
715
716
717
718
719
720
721
722
723
|
# File 'sample/tktextio.rb', line 714
def readpartial(maxlen, buf=nil)
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) ⇒ Object
725
726
727
|
# File 'sample/tktextio.rb', line 725
def reopen(*args)
fail NotImplementedError, 'reopen is not implemented on TkTextIO'
end
|
729
730
731
732
733
734
735
|
# File 'sample/tktextio.rb', line 729
def rewind
@txtpos.set('1.0')
_see_pos
@lineno = 0
@line_offset = 0
self
end
|
#seek(offset, whence = IO::SEEK_SET) ⇒ Object
Also known as:
sysseek
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
|
# File 'sample/tktextio.rb', line 737
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 ⇒ Object
767
768
769
|
# File 'sample/tktextio.rb', line 767
def show_mode
(@show == @txtpos)? :pos : @show
end
|
#show_mode=(mode) ⇒ Object
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
|
# File 'sample/tktextio.rb', line 771
def show_mode=(mode)
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
|
798
799
800
|
# File 'sample/tktextio.rb', line 798
def stat
fail NotImplementedError, 'stat is not implemented on TkTextIO'
end
|
802
803
804
|
# File 'sample/tktextio.rb', line 802
def sync
@sync
end
|
#sync=(mode) ⇒ Object
806
807
808
|
# File 'sample/tktextio.rb', line 806
def sync=(mode)
@sync = mode
end
|
#sysread(len, buf = nil) ⇒ Object
810
811
812
813
814
815
816
817
818
|
# File 'sample/tktextio.rb', line 810
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
|
#syswrite(obj) ⇒ Object
820
821
822
|
# File 'sample/tktextio.rb', line 820
def syswrite(obj)
_write(obj)
end
|
824
825
826
|
# File 'sample/tktextio.rb', line 824
def to_io
self
end
|
#trancate(len) ⇒ Object
828
829
830
831
|
# File 'sample/tktextio.rb', line 828
def trancate(len)
delete("1.0 + #{len} char", :end)
0
end
|
#tty? ⇒ Boolean
510
511
512
|
# File 'sample/tktextio.rb', line 510
def tty?
false
end
|
#ungetc(c) ⇒ Object
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
|
# File 'sample/tktextio.rb', line 833
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) ⇒ Object
901
902
903
904
|
# File 'sample/tktextio.rb', line 901
def write(obj)
_check_writable
_write(obj)
end
|