| 1 | |||
| 2 | package App::Asciio::stripes::editable_box2 ; | ||
| 3 | use parent qw/App::Asciio::stripes::single_stripe/ ; | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | |||
| 8 | use IO::Prompter; | ||
| 9 | use File::Slurp ; | ||
| 10 | use File::Temp ; | ||
| 11 | |||
| 12 | #----------------------------------------------------------------------------- | ||
| 13 | |||
| 14 | sub display_box_edit_dialog | ||
| 15 | { | ||
| 16 | my ($self, $title, $text, $asciio) = @_ ; | ||
| 17 | |||
| 18 | my $title_separator = $self->{BOX_TYPE}[1] ; | ||
| 19 | |||
| 20 | if(defined $asciio->{DIALOGS}{BOX_EDIT}) | ||
| 21 | { | ||
| 22 | my $file = File::Temp->new()->filename ; | ||
| 23 | |||
| 24 | write_file($file, "$title\n\n" . ($title_separator->[0] // 0) . "\n\n$text\n") ; | ||
| 25 | |||
| 26 | system "$asciio->{DIALOGS}{BOX_EDIT} $file" ; | ||
| 27 | my $user_input = read_file $file ; | ||
| 28 | |||
| 29 | ($title, $title_separator->[0], $text) = split /\n\n\n?/, $user_input ; | ||
| 30 | |||
| 31 | } | ||
| 32 | else | ||
| 33 | { | ||
| 34 | print "\e[2J\e[H\e[?25h" ; | ||
| 35 | |||
| 36 | my $input = prompt "old title: $title\nnew title: ", -default => $title ; | ||
| 37 | if($input) | ||
| 38 | { | ||
| 39 | $input =~ s/\r$// ; | ||
| 40 | $input =~ s/\\n/\n/g ; | ||
| 41 | $title = "$input" ; | ||
| 42 | } | ||
| 43 | else | ||
| 44 | { | ||
| 45 | $title = undef ; | ||
| 46 | } | ||
| 47 | |||
| 48 | $title_separator->[0] = prompt "title_sepearator [y/n]: ", -y1 ; | ||
| 49 | |||
| 50 | $input = prompt "old text: $text\nnew text: ", -default => $text ; | ||
| 51 | if($input) | ||
| 52 | {$input =~ s/\r$// ; | ||
| 53 | $input =~ s/\\n/\n/g ; | ||
| 54 | $text = "$input" ; | ||
| 55 | } | ||
| 56 | else | ||
| 57 | { | ||
| 58 | $text = undef ; | ||
| 59 | } | ||
| 60 | |||
| 61 | print "\e[?25l" ; # hide cursor | ||
| 62 | } | ||
| 63 | |||
| 64 | return($text, $title) ; | ||
| 65 | } | ||
| 66 | |||
| 67 | #----------------------------------------------------------------------------- | ||
| 68 | |||
| 69 | 1 ; |