script/TextViDemo.pl untested

filter: Statementstmt 0.0% 0 / 55 Branchbran 0.0% 0 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 91 CC 12 SCAR 38.1
CC
12
Cov
0%
showstat
90.0
dosys
20.0
BEGIN
2.0
CRAP 45.2
1 # Demonstration of Tk::TextVi
2
3 use strict;
4 use warnings;
5
6 # Test it without a make install
7 BEGIN { unshift @INC, '../lib' }
8
9 use Tk;
10 use Tk::TextVi;
11
12 my $mw = MainWindow->new( );
13
14 my $frame = $mw->Frame( )->pack( -side => 'top' );
15 my $split = 0;
16
17 my $text = $frame->TextVi(
18 -background => '#FFFFFF',
19 -statuscommand => \&showstat,
20 -messagecommand => \&showmsg,
21 -errorcommand => \&showerr,
22 -systemcommand => \&dosys,
23 -height => 20,
24 -width => 55,
25 )->pack( );
26
27 my $left = $mw->Label( -font => 'Courier' )->pack( -side => 'left' );
28 my $right = $mw->Label( -font => 'Courier' )->pack( -side => 'right' );
29
30 {
31 undef $/;
32 $text->Contents( <DATA> );
33 }
34
35 $text->SetCursor('1.0');
36 $text->focus();
37
38 MainLoop;
39
40 sub dosys {
41 my ($action) = @_;
42
43 if( $action eq 'quit' ) {
44 Tk::exit(0);
45 }
46 elsif( $action eq 'split' ) {
47 return "Already split" if $split;
48 $split = 1;
49
50 # ***** it. There's some magical set of pack() flags that
51 # will make the frame divide in two but after a half hour of
52 # the nonsensical behavior plus four interruptions I don't
53 # ******* care any more.
54 $text->configure( -height => 10 );
55 return $frame->TextVi(
56 -background => '#FFFFFF',
57 -statuscommand => \&showstat,
58 -messagecommand => \&showmsg,
59 -errorcommand => \&showerr,
60 -systemcommand => \&dosys,
61 -height => 10,
62 -width => 55,
63 )->pack( -side => 'top' );
64 }
65
66 return;
67 }
68
69 sub showstat {
70 my ($mode,$keys) = @_;
71
72 $keys =~ s/([\x01-\x19])/'^'.chr(0x40+ord($1))/ge;
73
74 my $rec = (substr($mode,1,1) eq 'q') ? 'recording' : '';
75 $mode = substr $mode, 0, 1;
76
77 $left->configure( -foreground => '#000000' );
78
79 if( $mode eq 'n' ) {
80 $left->configure( -text => ' '.$rec );
81 $right->configure( -text => $keys );
82 }
83 elsif( $mode eq 'c' ) {
84 $left->configure( -text => ':' . $keys );
85 }
86 elsif( $mode eq '/' ) {
87 $left->configure( -text => '/' . $keys );
88 }
89 elsif( $mode eq 'i' ) {
90 $left->configure( -text => '-- INSERT --'.$rec );
91 $right->configure( -text => $keys );
92 }
93 elsif( $mode eq 'R' ) {
94 $left->configure( -text => '-- REPLACE --'.$rec );
95 $right->configure( -text => $keys );
96 }
97 elsif( $mode eq 'v' ) {
98 $left->configure( -text => '-- VISUAL --'.$rec );
99 $right->configure( -text => $keys );
100 }
101 elsif( $mode eq 'V' ) {
102 $left->configure( -text => '-- VISUAL LINE --'.$rec );
103 $right->configure( -text => $keys );
104 }
105 }
106
107 sub showmsg {
108 $left->configure( -foreground => '#000000' );
109 $left->configure( -text => $text->viMessage() );
110 }
111
112 sub showerr {
113 $left->configure( -foreground => '#FF0000' );
114 $left->configure( -text => $text->viError() );
115 }
116
117 __DATA__