Cool! That has inspired me to write a "minimal" Tk editor. This punts on everything from file reading/writing to appearance control.
=pod
This program reads text from "stdin" and writes to "stdout" on exit.
It can be used to do in-place editing of a file by executing with perl
+ -i.bak
If you exit via 'OK' or 'Cancel', the process exit code will be 0 or 1
+, respectively.
If you exit with 'Cancel' and are NOT running with perl -i, the text w
+ill not be printed to "stdout".
Examples:
% foo | perl stream_editor_tk | bar
# foo produces text;
# stream_editor_tk is this program;
# bar consumes text.
% perl -i.bak stream_editor_tk some_doc.txt
# edit a file in place.
=cut
use Tk;
use strict;
use warnings;
my $orig = $_ = do { local $/; <> };
my $code = 1;
my $mw = new MainWindow( -title => 'Edit' );
my $fr = $mw->Frame( -border => 2, -relief => 'raised' )->pack( -side
+=> 'bottom', -fill => 'both', );
my $text = $mw->Scrolled( 'Text', -wrap => 'none' )->pack( -side => 'b
+ottom', -fill => 'both', -expand => 1 );
$fr->Button( -text => 'Reset', -command => sub { $text->delete( '1.0',
+ 'end' ); $text->insert( end => $_ ) } )->place( -relx => 0.25, -anch
+or => 'n', );
my $ok = $fr->Button( -text => 'OK', -command => sub { print $text->ge
+t( '1.0', 'end' ); $code = 0; $mw->destroy } )->place( -relx => 0.5,
+-anchor => 'n', );
$fr->Button( -text => 'Cancel', -command => sub { defined $^I and prin
+t $orig; $mw->destroy } )->place( -relx => 0.75, -anchor => 'n', );
$mw->after( 100, sub { $fr->configure( -height => $ok->height + 5 ); }
+ );
$text->insert( end => $_ );
MainLoop;
exit $code;
We're building the house of the future together.