blib/lib/oEdtk/tuiEdtk.pm

filter: Statementstmt 88.8% 16 / 18 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 91.6% 22 / 24 CC 1 SCAR 0.5
CC
1
Cov
89%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/oEdtk/libXls.pm ↑ Summary lib/oEdtk/TexDoc.pm »
1 package oEdtk::tuiEdtk;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 BEGIN {
6 1 ▶ use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶ use vars qw($VERSION @ISA @EXPORT); # @EXPORT_OK %EXPORT_TAGS);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶ use Term::ReadKey;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶ use oEdtk::trackEdtk qw(env_Var_Completion);
Subroutine BEGIN: called CC=1 SCAR=2.6
11  
12 $VERSION = 2.1126;
13 @ISA = qw(Exporter);
14 @EXPORT = qw(
15 clear_Screen start_Screen stop_Screen
16 admin_Screen not_Configured
17 );
18  
19 # @EXPORT_OK = qw(
20 # )
21 }
22  
23 sub clear_Screen() {
24 my $command = "clear"; # default
25 if ( $^O eq "MSWin32" ) {
26 $command = "cls";
27 }
28 else {
29 # TODO test...
30 warn "INFO OS $^O, tuiEdtk::clear_Screen awaiting feedback\n";
31 }
32  
33 system($command) == 0
34 or warn "INFO OS $^O system command $command failed: $?";
35  
36 return 1;
37 }
38  
39 sub admin_Screen {
40 &clear_Screen();
41 my $wait = 10 * $ENV{EDTK_WAITRUN};
42 print STDOUT <<"EOF";
43  
44 oEtdk Simple Administration
45 ______________________________________
46  
47 Select Option
48 <I> show edtk init file
49 <C> version control utility
50 <D> deliveries (planned)
51 <Q> quit
52  
53 Choose an option by typing associated letter
54 (wait ${wait}s or press any key to stop).
55 EOF
56  
57 my $key = &readKey_Wait($wait);
58 $key ||= "";
59  
60 if ( $key =~ /i/i ) {
61 &show_INIEDTK();
62 &admin_Screen();
63  
64 }
65 elsif ( $key =~ /c/i ) {
66 print " -> Choice = $key\n";
67 &VCS_Screen();
68  
69 }
70 elsif ( $key =~ /d/i ) {
71 print " -> Choice = $key\n";
72 &delivery_Screen();
73  
74 }
75 elsif ( $key =~ /a/i ) {
76 print " -> Choice = $key\n";
77 }
78  
79 warn "INFO: -END- \n";
80  
81 exit 1;
82 1;
83 }
84  
85 sub show_INIEDTK() {
86  
87 # determine the default editor based on HOSTNAME
88 my $wait = 10 * $ENV{EDTK_WAITRUN};
89 my $iniedtk = $ENV{EDTK_INIEDTK};
90 env_Var_Completion($iniedtk);
91  
92 my @args = ( "more", $iniedtk );
93 eval { system(@args); };
94  
95 if ($?) {
96 print "Screen refresh";
97 &readKey_Wait();
98 return $?;
99 }
100  
101 &readKey_Wait($wait);
102 1;
103 }
104  
105 sub start_Screen() {
106 &clear_Screen();
107  
108 print STDOUT <<"EOF";
109  
110 Application launcher $ENV{EDTK_PRGNAME}
111 ______________________________________
112
113 Auto start in $ENV{EDTK_WAITRUN}s, or press <enter>.
114 Parameters :
115 application $ENV{EDTK_PRGNAME}
116 data $ENV{EDTK_FDATAIN}.$ENV{EDTK_EXT_DATA}
117 output $ENV{EDTK_FDATAOUT}
118 temp $ENV{EDTK_DIR_APPTMP}
119  
120 Options :
121 <1> Run: $ENV{EDTK_PRGNAME}.$ENV{EDTK_EXT_PERL}
122 <A> Administration
123  
124 To change an option, type its value or <enter> for the default.
125 EOF
126 my $key = &readKey_Wait();
127 $key ||= "";
128  
129 if ( $key =~ /a/i ) {
130 &admin_Screen();
131 }
132 elsif ( $key =~ /\d+/ ) {
133 print " -> Choice = run $ENV{EDTK_PRGNAME}\n";
134 }
135  
136 print "\n";
137  
138 return 1;
139 }
140  
141 sub stop_Screen () {
142 print "\nPause, hit <enter> to exit or <w> to watch Doc result...\n";
143 my $key = &readKey_Wait( $ENV{EDTK_WAITRUN} * 100 ) || "";
144 my $arg = "$ENV{EDTK_FDATAOUT}." . $ENV{EDTK_EXT_DEFAULT};
145  
146 if ( $key =~ /W/i and $arg ) {
147  
148 env_Var_Completion($arg);
149  
150 warn "$arg...\n";
151 eval { system($arg); };
152 }
153 else {
154  
155 }
156  
157 1;
158 }
159  
160 sub readKey_Wait {
161 my $key;
162 my $wait_time = shift;
163 $wait_time ||= $ENV{EDTK_WAITRUN};
164 $wait_time ||= 1;
165  
166 ReadMode('raw');
167 $key = ReadKey($wait_time);
168 ReadMode('restore');
169  
170 return $key;
171 }
172  
173 sub not_Configured() {
174 my $wait = 10 * $ENV{EDTK_WAITRUN};
175  
176 SCREEN: {
177 print STDOUT <<"EOF";
178  
179 Function not configured
180 ______________________________________
181  
182 Repository $ENV{EDTK_VCS_LOCATION}
183 Branch $ENV{EDTK_DIR_BASE}
184 Application $ENV{EDTK_PRGNAME}
185  
186  
187 <Q> quit
188  
189 EOF
190  
191 my $key = &readKey_Wait($wait);
192 $key ||= "";
193 }
194  
195 exit 1;
196 1;
197 }
198  
199 sub VCS_Screen {
200 if ( $ENV{EDTK_VCS_LOCATION} eq "" ) { not_Configured(); }
201  
202 my $wait = 10 * $ENV{EDTK_WAITRUN};
203  
204 SCREEN: {
205 &clear_Screen();
206 print STDOUT <<"EOF";
207  
208 Version Control
209 ______________________________________
210  
211 Repository $ENV{EDTK_VCS_LOCATION}
212 Branch $ENV{EDTK_DIR_BASE}
213  
214 <S> show branch log (log)
215 <A> add files into branch (test - add)
216 <C> commit branch changes (commit)
217 <T> send To repository (push)
218 <W> missing between branch/rep (missing)
219 <U> update local branch (pull)
220 <M> merge local branch (merge)
221 <F> build branch From repository(planned - branch)
222 <L> build local VCS (planned - init)
223  
224 <B> back <Q> quit
225  
226 Choose an option by typing associated letter.
227 EOF
228  
229 my $key = &readKey_Wait($wait);
230 $key ||= "";
231  
232 # print " -> Choice = $key\n";
233  
234 if ( $key =~ /S/i ) {
235 &VCS_log();
236  
237 }
238 elsif ( $key =~ /A/i ) {
239 &VCS_add();
240  
241 }
242 elsif ( $key =~ /C/i ) {
243 &VCS_commit();
244  
245 }
246 elsif ( $key =~ /U/i ) {
247 &VCS_update();
248  
249 }
250 elsif ( $key =~ /T/i ) {
251 &VCS_to();
252  
253 }
254 elsif ( $key =~ /W/i ) {
255 &VCS_missing();
256  
257 }
258 elsif ( $key =~ /M/i ) {
259 &VCS_merge();
260 &readKey_Wait();
261  
262 }
263 elsif ( $key =~ /F/i ) {
264 print "planned...";
265 }
266 elsif ( $key =~ /L/i ) {
267 print "planned...";
268 }
269 elsif ( $key =~ /B/i ) {
270 &admin_Screen();
271 }
272 elsif ( $key =~ /Q/i ) {
273 &clear_Screen();
274 exit 1;
275 }
276  
277 redo SCREEN;
278 }
279  
280 exit 1;
281 1;
282 }
283  
284 sub VCS_merge() {
285 my $loc = $ENV{EDTK_DIR_BASE};
286 env_Var_Completion($loc);
287 chdir $loc;
288  
289 print "Merging... ";
290 my @args = ( "bzr", "merge", $loc );
291  
292 eval { system(@args); };
293  
294 if ($?) {
295 print "Screen refresh";
296 &readKey_Wait();
297 return $?;
298 }
299 1;
300 }
301  
302 sub VCS_commit {
303 my $comment = shift;
304 $comment ||= "";
305  
306 # potential branch location problem if run outside the branch
307 my $base = $ENV{EDTK_DIR_BASE};
308 env_Var_Completion($base);
309 chdir $base;
310  
311 my @args = ( "bzr", "commit" );
312 if ( $comment ne "" ) { push( @args, "-m $comment" ); }
313  
314 eval { system(@args); };
315  
316 if ($?) {
317 print "Screen refresh";
318 &readKey_Wait();
319 return $?;
320 }
321  
322 #&VCS_merge();
323 &readKey_Wait();
324 1;
325 }
326  
327 sub VCS_missing() {
328  
329 # potential branch location problem if run outside the branch
330 my $other_branch = $ENV{EDTK_VCS_LOCATION};
331 env_Var_Completion($other_branch);
332 my $base = $ENV{EDTK_DIR_BASE};
333 env_Var_Completion($base);
334 chdir $base;
335  
336 my @args = ( "bzr", "missing", $other_branch );
337  
338 eval { system(@args); };
339  
340 if ($?) {
341 print "Screen refresh";
342 &readKey_Wait();
343 return $?;
344 }
345  
346 &readKey_Wait();
347 1;
348 }
349  
350 sub VCS_add() {
351 my $wait = 10 * $ENV{EDTK_WAITRUN};
352  
353 # potential branch location problem if run outside the branch
354 my $base = $ENV{EDTK_DIR_BASE};
355 env_Var_Completion($base);
356 chdir $base;
357  
358 my @args = ( "bzr", "add", "--dry-run" );
359  
360 eval { system(@args); };
361  
362 if ($?) {
363 return $?;
364  
365 }
366 else {
367 print "Enter <Y>es if you confirm action (wait ${wait}s) :\n";
368 my $key = &readKey_Wait($wait);
369 $key ||= "";
370  
371 if ( $key =~ /y/i ) {
372 print " -> bzr add confirmed\n";
373 }
374 else {
375 print "Canceled\n";
376 &readKey_Wait();
377 return 0;
378 }
379  
380 @args = ( "bzr", "add" );
381 eval { system(@args); };
382  
383 if ($?) {
384 return $?;
385 }
386 print "Screen refresh";
387 }
388 &readKey_Wait();
389 1;
390 }
391  
392 sub VCS_update() {
393  
394 #&VCS_merge();
395  
396 # potential branch location problem if run outside the branch
397 my $base = $ENV{EDTK_DIR_BASE};
398 env_Var_Completion($base);
399 chdir $base;
400  
401 my @args = ( "bzr", "pull" );
402 eval { system(@args); };
403  
404 if ($?) {
405 print "Screen refresh";
406 &readKey_Wait();
407 return $?;
408 }
409  
410 &readKey_Wait();
411 1;
412 }
413  
414 sub VCS_to() {
415 &VCS_merge();
416  
417 my $cmd = "cd $ENV{EDTK_DIR_BASE}";
418 env_Var_Completion($cmd);
419 system($cmd);
420  
421 my $base = $ENV{EDTK_DIR_BASE};
422 env_Var_Completion($base);
423 chdir $base;
424  
425 my @args = ( "bzr", "push" );
426 eval { system(@args); };
427  
428 if ($?) {
429 print "Screen refresh";
430 &readKey_Wait();
431 return $?;
432 }
433  
434 &readKey_Wait();
435 1;
436 }
437  
438 sub VCS_log() {
439 my $loc = $ENV{EDTK_DIR_BASE};
440 env_Var_Completion($loc);
441  
442 # TODO: select qlog or glog depending on the environment
443 my @args = ( "bzr", "qlog", $loc );
444  
445 eval { system(@args); };
446  
447 if ($?) {
448 print "Screen refresh";
449 &readKey_Wait();
450 return $?;
451 }
452  
453 1;
454 }
455  
456 sub VCS_rename() {
457 my $wait = 10 * $ENV{EDTK_WAITRUN};
458  
459 my $base = $ENV{EDTK_DIR_BASE};
460 my $oldname = $ENV{EDTK_DIR_SCRIPT} . "\\" . $ENV{EDTK_PRGNAME};
461 my $newname = $ENV{EDTK_DIR_SCRIPT} . "\\" . $ENV{EDTK_PRGNAME};
462 my @extension;
463  
464 push( @extension, $ENV{EDTK_EXT_PERL} );
465 push( @extension, $ENV{EDTK_EXT_LATEX} );
466  
467 env_Var_Completion($oldname);
468 env_Var_Completion($newname);
469 env_Var_Completion($base);
470 chdir $base;
471  
472 foreach my $ext (@extension) {
473 my @args = ( "bzr", "move", "$oldname.$ext", "$newname.$ext", "--quiet" );
474 eval { system(@args); };
475  
476 if ($?) {
477 return $?;
478 }
479 }
480 &readKey_Wait();
481 1;
482 }
483  
484 sub delivery_Screen {
485 if ( $ENV{EDTK_PRGNAME} eq "" or $ENV{EDTK_DIR_BASE} eq "" ) { not_Configured(); }
486  
487 my $wait = 10 * $ENV{EDTK_WAITRUN};
488  
489 SCREEN: {
490 &clear_Screen();
491 print STDOUT <<"EOF";
492  
493 Deliveries
494 ______________________________________
495  
496 Repository $ENV{EDTK_VCS_LOCATION}
497 Branch $ENV{EDTK_DIR_BASE}
498 Application $ENV{EDTK_PRGNAME}
499  
500  
501 <A> moving from development to tests for Approval :
502 from $ENV{EDTK_PRGNAME} to $ENV{EDTK_PRGNAME}
503  
504 <P> delivering approved applications to Production : (planned)
505 from $ENV{EDTK_PRGNAME} to $ENV{EDTK_PRGNAME}
506  
507 <B> back <Q> quit
508  
509 Choose an option by typing associated letter.
510 EOF
511  
512 my $key = &readKey_Wait($wait);
513 $key ||= "";
514  
515 if ( $key =~ /A/i ) {
516 &VCS_rename();
517 &VCS_commit("move $ENV{EDTK_PRGNAME} to $ENV{EDTK_PRGNAME}");
518  
519 }
520 elsif ( $key =~ /P/i ) {
521 print "planned...";
522  
523 #&VCS_commit();
524  
525 }
526 elsif ( $key =~ /B/i ) {
527 &admin_Screen();
528 }
529 elsif ( $key =~ /Q/i ) {
530 &clear_Screen();
531 exit 1;
532 }
533  
534 redo SCREEN;
535 }
536  
537 exit 1;
538 1;
539 }
540  
541 END { }
542 1;
543  
544 # THIS COMMENTING METHOD IS INTERESTING BUT POLLUTES POD
545  
546 # =begin comment
547  
548 # http://perl.enstimac.fr/DocFr/perldiag.html
549  
550 # http://perl.enstimac.fr/DocFr/perlfaq8.html
551 # How to read a key without waiting for a press on ``enter'' ?
552  
553 # use HotKey;
554 # $key = readkey();
555  
556 # Use the diagnostics pragma which turns normal Perl error messages into a longer discussion of the subject.
557 # use diagnostics;
558  
559 # BEGIN {
560 # $SIG{__WARN__} = sub{ print STDERR "Perl: ", @_; };
561 # $SIG{__DIE__} = sub{ print STDERR "Perl: ", @_; exit 1};
562 # }
563  
564 # How to manage my own modules/libraries directory?
565 # When building modules, use the PREFIX and LIB options at the Makefile generation step:
566 # perl Makefile.PL PREFIX=/mydir/perl LIB=/mydir/perl/lib
567  
568 # then either set the PERL5LIB environment variable before running the scripts that use these modules/libraries (see the perlrun man page), or use:
569 # use lib '/mydir/perl/lib';
570 #
571 # if the directory is not known in advance...
572 # use FindBin qw($Bin);
573 # use lib "$Bin/myPm";
574  
575 # =end comment
576  
577 #perl -d:ptkdb
578  
579 =head1 NAME
580  
581 oEdtk::tuiEdtk - simple terminal screens for the oEdtk launcher
582  
583 =head1 SYNOPSIS
584  
585 use oEdtk::tuiEdtk;
586  
587 start_Screen();
588 # ... run the application ...
589 stop_Screen();
590  
591 =head1 DESCRIPTION
592  
593 Draws the simple terminal screens of the oEdtk command-line launcher: the start
594 screen, the administration menu and the exit pause. The screens are driven by the
595 C<EDTK_*> environment variables; key reads go through C<Term::ReadKey> and path
596 expansion through L<oEdtk::trackEdtk>.
597  
598 =head1 FUNCTIONS
599  
600 =head2 clear_Screen
601  
602 clear_Screen();
603  
604 Clear the terminal with C<clear> on Unix or C<cls> on Windows.
605  
606 =head2 start_Screen
607  
608 start_Screen();
609  
610 Display the application launcher and read the user's choice.
611  
612 =head2 stop_Screen
613  
614 stop_Screen();
615  
616 Pause at the end of a run and, on request, open the produced document.
617  
618 =head2 admin_Screen
619  
620 admin_Screen();
621  
622 Display the simple administration menu and dispatch to the chosen action.
623  
624 =head2 not_Configured
625  
626 not_Configured();
627  
628 Display the "function not configured" screen and exit.
629  
630 The following subs are internal helpers and are not part of the public API:
631 C<show_INIEDTK>, C<readKey_Wait>, C<delivery_Screen>, and the version-control
632 helpers C<VCS_Screen>, C<VCS_merge>, C<VCS_commit>, C<VCS_missing>, C<VCS_add>,
633 C<VCS_update>, C<VCS_to>, C<VCS_log> and C<VCS_rename>.
634  
635 =head1 AUTHOR
636  
637 The oEdtk team.
638  
639 =cut
« blib/lib/oEdtk/libXls.pm ↑ Summary lib/oEdtk/TexDoc.pm »