Skip to content

Commit 9ed71c3

Browse files
committed
FIXED: asciio_to_text opens projects
1 parent b406da5 commit 9ed71c3

File tree

6 files changed

+105
-22
lines changed

6 files changed

+105
-22
lines changed

documentation/mdbook_asciio/src/UI/CLI.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
## asciio_to_text
88

9-
Converts an existing '.asciio' file to ASCII and display it in the terminal
9+
Converts an existing '.asciio' file/project to ASCII and display it in the terminal
1010

1111
## text_to_asciio
1212

lib/App/Asciio/GTK/Asciio/TabManager.pm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,6 @@ if($tar)
872872
}
873873
else
874874
{
875-
print "loaded tar\n" ;
876875
for my $document_name ($asciio_project->{documents}->@*)
877876
{
878877
my ($config, $asciio) = $self->create_tab({serialized => $tar->get_content($document_name)}) ;

lib/App/Asciio/Io.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ Readonly my @ELEMENTS_TO_KEEP_AWAY_FROM_CURRENT_OBJECT =>
149149

150150
sub load_serialized_self
151151
{
152-
my ($self, $serialized_self) = @_;
152+
my ($self, $serialized_self) = @_;
153153

154154
return unless defined $serialized_self ;
155155

script/asciio

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use App::Asciio::GTK::Asciio::TabManager ;
1111
my $window = Gtk3::Window->new('toplevel') ;
1212
$window->set_title('Asciio') ;
1313
$window->set_default_size(600, 400) ;
14-
1514
my $tab_manager = App::Asciio::GTK::Asciio::TabManager->new() ;
1615

1716
$window->add($tab_manager->get_widget()) ;

script/asciio_to_text

Lines changed: 102 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,109 @@ use strict;
44
use warnings;
55
use utf8 ;
66

7-
use App::Asciio ;
8-
97
use Module::Util qw(find_installed) ;
108
use File::Basename ;
9+
use Archive::Tar ;
10+
11+
use open qw( :std :encoding(UTF-8) ) ;
12+
binmode(STDOUT) ;
13+
binmode(STDIN) ;
14+
15+
use App::Asciio ;
16+
my $ASCIIO_MIME_TYPE = "application/x-asciio" ;
17+
18+
# ------------------------------------------------------------------------------
19+
20+
asciio_to_text() ;
21+
22+
# ------------------------------------------------------------------------------
23+
24+
sub asciio_to_text
25+
{
26+
my ($asciio_config, $asciio) = get_asciio() ;
27+
28+
if (-p STDIN || -f STDIN)
29+
{
30+
print STDERR "document_name: reading from STDIN\n" ;
31+
32+
undef $/ ;
33+
$asciio->load_self($asciio->get_decompressed_asciio(<STDIN>)) ;
34+
35+
print $asciio->transform_elements_to_ascii_buffer() ;
36+
}
37+
else
38+
{
39+
for my $project_name ($asciio_config->{TARGETS}->@*)
40+
{
41+
process_file($asciio, $project_name) ;
42+
}
43+
44+
# if(defined $asciio_config->{SCRIPT})
45+
# {
46+
# require App::Asciio::Scripting ;
47+
48+
# App::Asciio::Scripting::run_external_script($asciio, $asciio_config->{SCRIPT}) ;
49+
# }
50+
}
51+
52+
}
53+
54+
# ------------------------------------------------------------------------------
55+
56+
sub process_file
57+
{
58+
my ($asciio, $project_name) = @_ ;
59+
60+
# save original settings. You could also use lexical typeglobs.
61+
*OLD_STDOUT = *STDOUT;
62+
*OLD_STDERR = *STDERR;
1163

64+
# reassign STDOUT, STDERR
65+
open my $log_fh, '>>', 'asciio_io.log' ;
66+
*STDOUT = $log_fh;
67+
*STDERR = $log_fh;
68+
69+
my $tar = Archive::Tar->new($project_name) ;
70+
71+
# restore STDOUT/STDERR
72+
*STDOUT = *OLD_STDOUT;
73+
*STDERR = *OLD_STDERR;
74+
75+
if($tar)
76+
{
77+
my %documents = map { $_ => 1 } grep { $_ ne 'asciio_project' } $tar->list_files ;
78+
79+
my $serialized_asciio_project = $tar->get_content('asciio_project') ;
80+
my $asciio_project = eval { Sereal::Decoder->new->decode($serialized_asciio_project) } ;
81+
82+
if ($@)
83+
{
84+
print STDERR "Error: deserializing '$project_name': $@"
85+
}
86+
else
87+
{
88+
for my $document_name ($asciio_project->{documents}->@*)
89+
{
90+
$asciio->load_serialized_self($tar->get_content($document_name)) ;
91+
print STDERR "document_name: $document_name\n" ;
92+
print $asciio->transform_elements_to_ascii_buffer() ;
93+
}
94+
}
95+
}
96+
else
97+
{
98+
print STDERR "document_name: $project_name\n" ;
99+
100+
my $document_name = $asciio->load_file($project_name) ;
101+
102+
print $asciio->transform_elements_to_ascii_buffer() ;
103+
}
104+
}
105+
106+
# ------------------------------------------------------------------------------
107+
108+
sub get_asciio
109+
{
12110
my $asciio = new App::Asciio() ;
13111

14112
$asciio->{UI} = 'TUI' ;
@@ -50,20 +148,6 @@ else
50148
$asciio->setup($setup_paths, { %object_override, DISPLAY_SETUP_INFORMATION_ACTION => 0 }) ;
51149
}
52150

53-
if(defined $asciio_config->{TARGETS}[0])
54-
{
55-
local $asciio->{ACTION_VERBOSE} = sub { ; } ;
56-
$asciio->run_actions_by_name(['Open', $asciio_config->{TARGETS}[0]]) ;
57-
}
58-
59-
60-
if(defined $asciio_config->{SCRIPT})
61-
{
62-
require App::Asciio::Scripting ;
63-
64-
App::Asciio::Scripting::run_external_script($asciio, $asciio_config->{SCRIPT}) ;
65-
}
66-
67-
use open qw( :std :encoding(UTF-8) ) ;
68-
print $asciio->transform_elements_to_ascii_buffer() ;
151+
return $asciio_config, $asciio ;
152+
}
69153

script/text_to_asciio

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use strict; use warnings;
55
use File::Slurper qw(read_text) ;
66
use App::Asciio::Scripting ;
77

8+
use open qw( :std :encoding(UTF-8) ) ;
89
binmode(STDOUT) ;
910
my $pos = -1 ;
1011

0 commit comments

Comments
 (0)