@@ -1,4 +1,6 @@
-20130999 1.68 handle Haiku's \eO[ABCD] arrow-keys
+20140999 1.70
+20140712 1.69 ask() displays a default of "0"
+20130703 1.68 handle Haiku's \eO[ABCD] arrow-keys
20130323 1.67 Home and End work in sub ask; bug fixes in sub ask_password
20120905 1.66 ask_filename strips trailing space after filename-completion
20120327 1.65 also ask_filename introduced
@@ -8,7 +8,7 @@
#########################################################################
package Term::Clui::FileSelect;
-$VERSION = '1.68';
+$VERSION = '1.70';
import Term::Clui(':DEFAULT','back_up');
require Exporter;
@ISA = qw(Exporter);
@@ -8,7 +8,7 @@
#########################################################################
package Term::Clui;
-$VERSION = '1.68'; # handle Haiku's \eO[ABCD] arrow-keys
+$VERSION = '1.70'; # ask_filename() uses readline to display its own prompt
my $stupid_bloody_warning = $VERSION; # circumvent -w warning
require Exporter;
@ISA = qw(Exporter);
@@ -391,7 +391,7 @@ sub endwin {
# ----------------------- size handling ----------------------
my ($maxcols, $maxrows); my $size_changed = 1;
-my ($otherlines, @otherlines, $notherlines);
+my @OtherLines; # 20131002 $otherlines, $notherlines no longer global
sub check_size {
if (! $size_changed) { return; }
@@ -405,9 +405,8 @@ sub check_size {
}
$maxcols = $maxcols || 80; $maxcols--;
$maxrows = $maxrows || 24;
- if ($notherlines) {
- @otherlines = &fmt($otherlines);
- $notherlines = scalar @otherlines;
+ if (@OtherLines) {
+ @OtherLines = &fmt(join("\n",@OtherLines));
}
$size_changed = 0;
}
@@ -426,11 +425,9 @@ sub ask_filename { my ($question, $default) = @_; # 1.65 tab-completion
return ask($question, $default);
}
initscr(speakup_silent=>1);
- my $nol = display_question($question);
endwin();
$term = new Term::ReadLine 'ProgramName';
- # print STDERR "$question ";
- my $filename = $term->readline('');
+ my $filename = $term->readline($question.' '); # 1.70
print STDERR "\e[J";
$filename =~ s/ $//; # 1.66
return $filename;
@@ -444,7 +441,7 @@ sub ask { my ($question, $default) = @_;
my $nol = &display_question($question);
my $i = 0; my $n = 0; my @s = (); # cursor position, length, string
- if ($default) {
+ if (defined $default) { # 1.69 defined, to include 0
&speak("$question, default is $default");
$default =~ s/\t/ /g;
@s = split(q{}, $default); $n = scalar @s; $i = $[;
@@ -531,9 +528,8 @@ sub choose { my $question = shift; local @list = @_; # @list must be local
&initscr(mouse_mode=>1, speakup_silent=>1);
&size_and_layout(0);
- @otherlines = &fmt($otherlines);
- $notherlines = scalar @otherlines;
- my $speaktext = join(' ',$list[$this_cell],'. ',@otherlines);
+ @OtherLines = &fmt($otherlines);
+ my $speaktext = join(' ',$list[$this_cell],'. ',@OtherLines);
if (wantarray) {
$#marked = $#list;
if ($firstlinelength < $maxcols-30) {
@@ -560,7 +556,7 @@ sub choose { my $question = shift; local @list = @_; # @list must be local
&up(1); &clrtoeol(); &endwin(); $clue_has_been_given = 0;
return wantarray ? () : undef;
}
- my $speaktext = join(' ',$list[$this_cell],'. ',@otherlines);
+ my $speaktext = join(' ',$list[$this_cell],'. ',@OtherLines);
&speak("choose, $speaktext");
}
&wr_screen();
@@ -614,11 +610,12 @@ sub choose { my $question = shift; local @list = @_; # @list must be local
$this_cell--; &wr_cell($this_cell+1); &wr_cell($this_cell);
&speak($list[$this_cell]);
} elsif ((($c eq "j") || ($c == $KEY_DOWN)) && ($irow < $nrows)) {
- $mid_col = $icol[$this_cell] + 0.5 * length($list[$this_cell]);
- $left_of_target = 1000;
+ my $mid_col = $icol[$this_cell] + 0.5 * length($list[$this_cell]);
+ my $left_of_target = 1000;
for ($inew=$this_cell+1; $inew < $#list; $inew++) {
last if $icol[$inew] < $mid_col; # skip rest of row
}
+ my $new_mid_col = 0;
for (; $inew < $#list; $inew++) {
$new_mid_col = $icol[$inew] + 0.5*length($list[$inew]);
last if $new_mid_col >= $mid_col; # we've reached it
@@ -630,11 +627,12 @@ sub choose { my $question = shift; local @list = @_; # @list must be local
&wr_cell($iold); &wr_cell($this_cell);
&speak($list[$this_cell]);
} elsif ((($c eq "k") || ($c == $KEY_UP)) && ($irow > 1)) {
- $mid_col = $icol[$this_cell] + 0.5*length($list[$this_cell]);
- $right_of_target = 1000;
+ my $mid_col = $icol[$this_cell] + 0.5*length($list[$this_cell]);
+ my $right_of_target = 1000;
for ($inew=$this_cell-1; $inew > 0; $inew--) {
last if $irow[$inew] < $irow[$this_cell]; # skip rest of row
}
+ my $new_mid_col = 0;
for (; $inew > 0; $inew--) {
last unless $icol[$inew];
$new_mid_col = $icol[$inew] + 0.5*length($list[$inew]);
@@ -731,12 +729,12 @@ sub layout { my @list = @_;
return $irow;
}
sub wr_screen {
- my $i;
- for ($i=$[; $i<=$#list; $i++) {
+ for (my $i=$[; $i<=$#list; $i++) {
&wr_cell($i) unless $i==$this_cell;
}
+ my $notherlines = scalar @OtherLines;
if ($notherlines && ($nrows+$notherlines) < $maxrows) {
- &puts("\r\n", join("\r\n", @otherlines), "\r");
+ &puts("\r\n", join("\r\n", @OtherLines), "\r");
}
&wr_cell($this_cell);
}
@@ -983,9 +981,10 @@ sub edit { my ($title, $text) = @_;
system $ENV{EDITOR} || "vi"; # should also look in ~/db/choices.db
} elsif ($argc == 2) {
# must create tmp file with title embedded in name
- $tmpdir = '/tmp';
- ($safename = $title) =~ s/[\W_]+/_/g;
- $file = "$tmpdir/$safename.$$";
+ my $tmpdir = '/tmp';
+ my $safename = $title;
+ $safename =~ s/[\W_]+/_/g;
+ my $file = "$tmpdir/$safename.$$";
if (!open(F,">$file")) {&sorry("can't open $file: $!\n");return q{};}
print F $text; close F;
$editor = $ENV{EDITOR} || "vi"; # should also look in ~/db/choices.db
@@ -1225,19 +1224,19 @@ sub speak { my ($text, $wait) = @_;
sub display_question { my $question = shift; my %options = @_;
# used by &ask and &confirm, but not by &choose ...
&check_size();
- my ($firstline, @otherlines);
+ my ($firstline, $otherlines); # 20131002 @otherlines => $otherlines
if ($options{nofirstline}) {
- @otherlines = &fmt($question);
+ @OtherLines = &fmt($question);
} else {
($firstline,$otherlines) = split(/\r?\n/, $question, 2);
- @otherlines = &fmt($otherlines);
+ @OtherLines = &fmt($otherlines);
if ($firstline) { &puts("$firstline "); }
}
- if (@otherlines) {
- &puts("\r\n", join("\r\n", @otherlines), "\r");
+ if (@OtherLines) {
+ &puts("\r\n", join("\r\n", @OtherLines), "\r");
&goto(1 + length $firstline, 0);
}
- return scalar @otherlines;
+ return scalar @OtherLines;
}
sub erase_lines { # leaves cursor at beginning of line $_[$[]
&goto(0, $_[$[]); print TTY "\e[J";
@@ -1370,9 +1369,9 @@ The application needs no modification.
There is an equivalent Python3 module,
with (as far as possible) the same calling interface, at
-http://cpansearch.perl.org/src/PJB/Term-Clui-1.68/py/TermClui.py
+http://cpansearch.perl.org/src/PJB/Term-Clui-1.70/py/TermClui.py
-This is Term::Clui.pm version 1.68
+This is Term::Clui.pm version 1.70
=head1 WINDOW-SIZE
@@ -1672,6 +1671,6 @@ which were in turn based on some even older curses-based programs in I<C>.
There is an equivalent Python3 module,
with (as far as possible) the same calling interface, at
-http://cpansearch.perl.org/src/PJB/Term-Clui-1.68/py/TermClui.py
+http://cpansearch.perl.org/src/PJB/Term-Clui-1.70/py/TermClui.py
=cut
@@ -1,7 +1,7 @@
# http://module-build.sourceforge.net/META-spec-current.html
#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
name: Term-Clui
-version: 1.68
+version: 1.70
version_from: Clui.pm
installdirs: site
requires:
@@ -7,7 +7,7 @@
# modify it under the same terms as Perl itself. #
#########################################################################
-# SCSI: cdda2wav, cdrecord, cdparanoia, idprio, mencoder, mplayer
+# SCSI: cdda2wav, cdrecord, cdparanoia, idprio, avconv, mplayer
# $ENV{CDDA_DEVICE} cdrecord -scanbus
# ATAPI: cdcontrol -f /dev/cd0c info, burncd, mkisofs
# $ENV{CDROM} /usr/sbin/pciconf -lv, atacontrol list
@@ -253,8 +253,8 @@ sub copy_dvd {
# if (! rmdir $tmp_mnt) { warn "can't rmdir $tmp_mnt: $!\n"; }
# return 0;
#}
- #system "ls -lR $tmp_mnt/*";
+ warn "$dvdbackup -v -M -o $tmp_mnt -i /dev/cdrom\n";
system "$dvdbackup -v -M -o $tmp_mnt -i /dev/cdrom"; # uses libdvdcss!
# discover the DVD's title
my $dh; opendir($dh, $tmp_mnt) or die "can't opendir $tmp_mnt: $!";
@@ -265,20 +265,23 @@ sub copy_dvd {
if (1 != scalar @ds) {
warn "directories @ds found in $tmp_mnt/ , using $title\n";
}
- mkdir "$tmp_mnt/$title/AUDIO_TS";
+ if (! mkdir "$tmp_mnt/$title/AUDIO_TS") {
+ warn " can't mkdir $tmp_mnt/$title/AUDIO_TS\n";
+ }
# mkisofs -dvd-video -o i1.img d1/NAQOYQATSI/
# growisofs -dvd-compat -Z /dev/sr0=i1.img
-
# suppress line-feeds in the progress-bar (on stderr) ...
system "$mkisofs -gui -r -J -T -dvd-video -allow-limited-size"
- ." -V Video_DVD -o $tmpfile $tmp_mnt/$title"
+ ." -V Video_DVD -o $tmpfile '$tmp_mnt/$title'"
." 2>&1 | perl -pe 's/\$/\\e[K\\e[A/'";
+ # quotes 20130611, but should use the list form of system
#system "umount $tmp_mnt";
print "\n";
if ($eject) { system $eject; }
# if (! rmdir $tmp_mnt) { warn "can't rmdir $tmp_mnt: $!\n"; }
- use File::Path; File::Path::remove_tree("$tmp_mnt");
+ use File::Path; File::Path::remove_tree($tmp_mnt);
+ unlink $tmp_mnt;
system "ls -l $tmpfile";
# to be fussy, could mount -o loop $tmpfile and check it's OK ...
if (! -s $tmpfile) { warn " the iso fs was empty :-(\n"; return; }
@@ -294,6 +297,7 @@ sub copy_dvd {
}
if (!unlink $tmpfile) { warn "can't unlink $tmpfile: $!\n"; }
}
+
sub dvd_size {
if (!$mediainfo) {
# could try some other program ?
@@ -648,9 +652,9 @@ sub changedir {
my $newdir = select_file(-Path=>$ENV{PWD}, -Directory=>1);
return unless $newdir;
if (! -d $newdir) { sorry("$newdir is not a directory"); return; }
- if (! chdir $newdir) { sorry("can't chdir to $newdir: \!"); return; }
+ if (! chdir $newdir) { sorry("can't chdir to $newdir: $!"); return; }
# assertively rename *.WAV->*.wav, *.MID->*.mid, *.MP3->*.mp3
- if (! opendir (D, '.')) { sorry("can't opendir $newdir: \!"); return; }
+ if (! opendir (D, '.')) { sorry("can't opendir $newdir: $!"); return; }
my @allfiles = grep { !/^\./ } readdir(D);
closedir D;
my $oldname;
@@ -747,10 +751,10 @@ EOT
sub man {
my @topics = @_ || (
'aconnect', 'alsamixer', 'aplaymidi', 'arecordmidi', 'atacontrol',
- 'audio_stuff', 'bristol', 'burncd',
+ 'audio_stuff', 'avconv', 'bristol', 'burncd',
'cdcontrol', 'cdda2wav', 'cdrecord', 'dvd+rw-mediainfo',
'File::Format::RIFF',
- 'genisoimage', 'icedax', 'lame', 'mencoder', 'mkisofs',
+ 'genisoimage', 'icedax', 'lame', 'mkisofs',
'mplayer', 'normalize', 'normalize-audio', 'pciconf', 'sndfile-play',
'sox', 'soxexam', 'soxeffect',
'Term::Clui', 'Term::Clui::FileSelect', 'timidity', 'timidity.cfg',
@@ -57,16 +57,16 @@ the computer is a human-like conversation-partner, this works very
naturally. The application needs no modification.
Download TermClui.py from www.pjb.com.au/midi/free/TermClui.py or
-from http://cpansearch.perl.org/src/PJB/Term-Clui-1.67/py/TermClui.py
+from http://cpansearch.perl.org/src/PJB/Term-Clui-1.70/py/TermClui.py
and put it in your PYTHONPATH. TermClui.py depends on Python3.
TermClui.py is a translation into Python3 of the Perl CPAN Modules
-Term::Clui and Term::Clui::FileSelect. This is version 1.67
+Term::Clui and Term::Clui::FileSelect. This is version 1.70
'''
import re, sys, select, signal, subprocess, os, random
import termios, fcntl, struct, stat, time, dbm
-VERSION = '1.67'
+VERSION = '1.70'
def _which(s):
for d in os.getenv('PATH').split(':'):
@@ -266,6 +266,21 @@ def _getch():
return _KEY_NPAGE
if (c == 'Z'):
return _KEY_BTAB
+ if (c == 'O'): # 1.68 Haiku wierdness, inherited from an old Suse
+ c = _getc_wrapper(0)
+ if (c == 'A'):
+ return _KEY_UP # 1.68
+ if (c == 'B'):
+ return _KEY_DOWN # 1.68
+ if (c == 'C'):
+ return _KEY_RIGHT # 1.68
+ if (c == 'D'):
+ return _KEY_LEFT # 1.68
+ if (c == 'F'):
+ return _KEY_END # 1.68
+ if (c == 'H'):
+ return _KEY_HOME # 1.68
+ return c
if (c == '['):
c = _getc_wrapper(0)
if (c == 'A'):