##============================================================================== ## Tk::Stdio - capture program standard output and standard error, ## accept standard input ##============================================================================== ## Tk::Stdio is based on: ## ## Tk::Stderr - capture program standard error output ##============================================================================== require 5.006; package Tk::Stdio; use strict; use warnings; use vars qw($VERSION @ISA); ($VERSION) = q$Revision: 1.0 $ =~ /Revision:\s+(\S+)/ or $VERSION = "0.0"; use base qw(Tk::Derived Tk::MainWindow); use Tk::Text; use Tk::Frame; =pod =head1 NAME Tk::Stdio - capture standard output and error, accept standard input, display in separate window =head1 SYNOPSIS use Tk::Stdio; $mw = MainWindow->new->InitStdio; print "something\n"; ## goes to standard IO window print STDERR 'stuff'; ## likewise warn 'eek!'; ## likewise my $input = ; ## keyboard entry is in standard IO window my $char = getc; ## likewise =head1 DESCRIPTION This module captures the standard output or error of a program and redirects it to a read only text widget, which doesn't appear until necessary. When it does appear, the user can close it; it'll appear again when there is more output. Standard input can be entered in the widget, which becomes temporarily writable. =cut $Tk::Stdio::first_char = '1.0'; # 'line.char' set in READLINE or GETC ##============================================================================== ## Populate ##============================================================================== sub Populate { my ( $mw, $args ) = @_; my $private = $mw->privateData; $private->{ReferenceCount} = 0; $private->{Enabled} = 0; $mw->SUPER::Populate($args); $mw->withdraw; $mw->protocol( WM_DELETE_WINDOW => [ $mw => 'withdraw' ] ); my $f = $mw->Frame( Name => 'stderr_frame', )->pack( -fill => 'both', -expand => 1 ); my $text = $f->Scrolled( 'Text', -wrap => 'char', -scrollbars => 'oe', -state => 'disabled', -fg => 'white', -bg => 'black', -insertbackground => 'white', )->pack( -fill => 'both', -expand => 1 ); $text->bind( '