TkTextIO class

  • Thread starter Hidetoshi NAGAI
  • Start date
H

Hidetoshi NAGAI

Hi,

I released a sample of Ruby/Tk: TkTextIO class.
TkTextIO is a class to use a text widget as if an I/O stream
(like as StringIO class).
Because TkTextIO is a subclass of TkText, of course, you can
control it as a text widget.

TkTextIO has same instance methos as IO class's.
You can set a TkTextIO objet to $stdin, $stdout or $stderr.

# When you use 'readline' library, cannot replace $stdin or $stdout.
# If do that, you will get a core dump.

However, there is an important difference.
That is "all operations is done on 'character' base".
For example, TkTextIO#getc returns "one character string".
If the file pointer points a multi-byte character,
you can get the character (not the first byte).
The size of seek or the length of read denotes 'character' size.
For example, seek(10) means "10 characters from head"
(not "10 bytes from head"), and read(20) returns "20 characters"
(not "20 bytes").

By this difference, you cannot replace a stream to a TkTextIO object
when the code assumes that getc returns a Fixnum, and so on.
But I think there are some cases of which the feature is useful.

You can find the source at ext/tk/sample/tktextio.rb on both of
CVS 1.8 and CVS Head.
If you are interested in it, please try it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,919
Members
47,459
Latest member
Vida00R129

Latest Threads

Top