Skip to content

Commit 4254990

Browse files
committed
ADDED: option debug_fd
much output to STDERR is now through sub $asciio->{WARN}, specially the setup phase $asciio->{WARN} and $asciio->{ACTION_VERBOSE} can be redirected to a file descriptor by using option 'debug_fd' this is particularly useful in tasciio, the warning and actions can be directed to another terminal or a file using https://github.com/nkh/bash-rd we can run asciio or tasciio with output via 'rd' $> rd -i asciio $> tasciio --debug_fd 5 5> >(rd -c asciio) # in a separate terminal
1 parent 28a2fb1 commit 4254990

File tree

9 files changed

+98
-48
lines changed

9 files changed

+98
-48
lines changed

lib/App/Asciio/Io.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ local $self->{MIDDLE_BUTTON_SELECTION_FILTER} = undef ;
254254
local $self->{ELEMENT_TYPES} = undef ;
255255
local $self->{ELEMENT_TYPES_BY_NAME} = undef ;
256256
local $self->{ACTION_VERBOSE} = undef ;
257+
local $self->{WARN} = undef ;
257258

258259
my @elements_cache ;
259260
for my $element (@{$self->{ELEMENTS}})

lib/App/Asciio/Options.pm

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ do
3737

3838
$contains_switch = @ARGV ;
3939

40-
local $SIG{__WARN__} = sub {print STDERR $_[0] unless $ignore_error ;} ;
40+
local $SIG{__WARN__} = sub { print STDERR $_[0] unless $ignore_error ; } ;
4141

4242
unless(GetOptions(@flags))
4343
{
@@ -81,17 +81,21 @@ $asciio_config->{SETUP_PATHS} = [] ;
8181

8282
my @flags_and_help =
8383
(
84-
'setup_path=s' => $asciio_config->{SETUP_PATHS},
85-
'Sets the root of the setup directory.',
84+
'setup_path=s' => $asciio_config->{SETUP_PATHS},
85+
'sets the root of the setup directory.',
8686
'',
8787

88-
's|script=s' => \$asciio_config->{SCRIPT},
88+
's|script=s' => \$asciio_config->{SCRIPT},
8989
'script to be run at Asciio start.',
9090
'',
9191

92-
'p|web_port=s' => \$asciio_config->{WEB_PORT},
92+
'p|web_port=s' => \$asciio_config->{WEB_PORT},
9393
'port for web server.',
9494
'',
95+
96+
'debug_fd=i' => \$asciio_config->{DEBUG_FD},
97+
'debug file descriptor number.',
98+
'',
9599
) ;
96100

97101
return(@flags_and_help) ;

lib/App/Asciio/Scripting.pm

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,21 +108,31 @@ sub new_script_asciio
108108
local @ARGV = @ARGV ;
109109
$script_asciio = App::Asciio->new() ;
110110

111-
# warn "Asciio: created script asciio object\n" ;
112-
113111
my ($command_line_switch_parse_ok, $command_line_parse_message, $asciio_config)
114112
= $script_asciio->ParseSwitches([@ARGV], 0) ;
115113

116114
die "Error: '$command_line_parse_message'!" unless $command_line_switch_parse_ok ;
117115

116+
my %object_override ;
117+
if(defined $asciio_config->{DEBUG_FD})
118+
{
119+
open my $fh, ">&=", $asciio_config->{DEBUG_FD} or die "can't open fd 5: $!\n" ;
120+
$fh->autoflush(1) ;
121+
%object_override = (WARN => sub { print $fh "@_\n" }, ACTION_VERBOSE => sub { print $fh "$_[0]\n" ; } ) ;
122+
}
123+
else
124+
{
125+
%object_override = (WARN => sub { print STDERR "@_\n" }, ACTION_VERBOSE => sub { print STDERR "$_[0]\n" ; } ) ;
126+
}
127+
118128
if(@{$asciio_config->{SETUP_PATHS}})
119129
{
120-
$script_asciio->setup($asciio_config->{SETUP_PATHS}) ;
130+
$script_asciio->setup($asciio_config->{SETUP_PATHS}, \%object_override) ;
121131
}
122132
else
123133
{
124134
my ($basename, $path, $ext) = File::Basename::fileparse(find_installed('App::Asciio'), ('\..*')) ;
125-
$script_asciio->setup([$path . $basename . '/setup/setup.ini']) ;
135+
$script_asciio->setup([$path . $basename . '/setup/setup.ini'], \%object_override) ;
126136
}
127137
}
128138

lib/App/Asciio/Setup.pm

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,18 @@ sub setup
1919
{
2020
my($self, $setup_ini_files, $object_overrides) = @_ ;
2121

22+
if (defined $object_overrides)
23+
{
24+
while( my ($k, $v) = each $object_overrides->%* )
25+
{
26+
$self->{$k} = $v ;
27+
}
28+
}
29+
2230
for my $setup_file (@{$setup_ini_files})
2331
{
24-
print STDERR "Initializing with '$setup_file'\n" if $self->{DISPLAY_SETUP_INFORMATION};
25-
warn "Asciio: Warning: can't find setup data '$setup_file'\n" and next unless -e $setup_file ;
32+
$self->{WARN}("Initializing with '$setup_file'\n") if $self->{DISPLAY_SETUP_INFORMATION} ;
33+
$self->{WARN}("Asciio: Warning: can't find setup data '$setup_file'\n") and next unless -e $setup_file ;
2634

2735
push @{$self->{SETUP_PATHS}}, $setup_file ;
2836

@@ -39,15 +47,14 @@ for my $setup_file (@{$setup_ini_files})
3947
CODE_FROM_FILE => $setup_file,
4048
) ;
4149

42-
warn "can't load '$setup_file': $! $@\n" if $@ ;
50+
$self->{WARN}("can't load '$setup_file': $! $@\n") if $@ ;
4351
}
4452

4553
$self->setup_object_options($setup_path, $ini_files->{ASCIIO_OBJECT_SETUP} || []) ;
4654
if (defined $object_overrides)
4755
{
4856
while( my ($k, $v) = each $object_overrides->%* )
4957
{
50-
# print "object override $k -> $v\n" ;
5158
$self->{$k} = $v ;
5259
}
5360
}
@@ -71,25 +78,25 @@ for my $stencil (@{$stencils})
7178
{
7279
if(-f "$setup_path/$stencil")
7380
{
74-
print STDERR "loading stencil '$setup_path/$stencil'\n" if $self->{DISPLAY_SETUP_INFORMATION} ;
81+
$self->{WARN}("loading stencil '$setup_path/$stencil'\n") if $self->{DISPLAY_SETUP_INFORMATION} ;
7582
$self->load_elements("$setup_path/$stencil", $stencil) ;
7683
}
7784
elsif(-d "$setup_path/$stencil")
7885
{
7986
for(glob("$setup_path/$stencil/*"))
8087
{
81-
print STDERR "batch loading stencil '$setup_path/$stencil/$_'\n" if $self->{DISPLAY_SETUP_INFORMATION} ;
88+
$self->{WARN}("batch loading stencil '$setup_path/$stencil/$_'\n") if $self->{DISPLAY_SETUP_INFORMATION} ;
8289
$self->load_elements($_, $stencil) ;
8390
}
8491
}
8592
else
8693
{
87-
print STDERR "Unknown type '$setup_path/$stencil'!\n" ;
94+
$self->{WARN}("Unknown type '$setup_path/$stencil'!\n") ;
8895
}
8996
}
9097
else
9198
{
92-
print STDERR "Can't find '$setup_path/$stencil'!\n" ;
99+
$self->{WARN}("Can't find '$setup_path/$stencil'!\n") ;
93100
}
94101
}
95102
}
@@ -180,7 +187,7 @@ for my $action_file (@{ $action_files })
180187
if('HASH' eq ref $action_handler_definition)
181188
{
182189
$shortcuts_definition = $action_handler_definition->{SHORTCUTS} ;
183-
# print STDERR "\e[31maction_handler: '$name' is group $shortcuts_definition\e[m\n" ;
190+
# $self->{ACTION_VERBOSE}("\e[31maction_handler: '$name' is group $shortcuts_definition\e[m\n") ;
184191

185192
$action_handler = $self->get_group_action_handler($setup_path, $action_file, $name, $action_handler_definition) ;
186193
}
@@ -200,7 +207,7 @@ for my $action_file (@{ $action_files })
200207
}
201208
else
202209
{
203-
# print STDERR "ignoring '$name'\n" ;
210+
# $self->{ACTION_VERBOSE}("ignoring '$name'\n") ;
204211
next ;
205212
}
206213

@@ -258,16 +265,16 @@ for my $action_file (@{ $action_files })
258265
{
259266
if(exists $self->{ACTIONS}{$shortcut})
260267
{
261-
print STDERR "Overriding shortcut '$shortcut'\n" ;
262-
print STDERR "\tnew is '$name' defined in file '$setup_path/$action_file'\n" ;
263-
print STDERR "\told was '$self->{ACTIONS}{$shortcut}{NAME}' defined in file '$self->{ACTIONS}{$shortcut}{ORIGIN}'\n" ;
268+
$self->{ACTION_VERBOSE}("Overriding shortcut '$shortcut'\n") ;
269+
$self->{ACTION_VERBOSE}("\tnew is '$name' defined in file '$setup_path/$action_file'\n") ;
270+
$self->{ACTION_VERBOSE}( "\told was '$self->{ACTIONS}{$shortcut}{NAME}' defined in file '$self->{ACTIONS}{$shortcut}{ORIGIN}'\n") ;
264271
}
265272

266273
$self->{ACTIONS}{$shortcut} = $action_handler ;
267274

268275
if (! defined $action_handler->{CODE} && ! defined $action_handler->{CONTEXT_MENU_SUB})
269276
{
270-
print STDERR "\e[33mNo action for action_handler: '$name', file: '$setup_path/$action_file'\e[m\n" ;
277+
$self->{ACTION_VERBOSE}("\e[33mNo action for action_handler: '$name', file: '$setup_path/$action_file'\e[m\n") ;
271278
delete $self->{ACTIONS}{$shortcut} ;
272279
}
273280

@@ -330,7 +337,7 @@ my $name = $action_handler->{NAME} ;
330337
if(exists $self->{ACTIONS_BY_NAME}{$name})
331338
{
332339
my $reused = '' ;
333-
print STDERR "\e[33mOverriding action: '$name', file: '$action_file', old_file: '" . ($self->{ACTIONS_BY_NAME}{ORIGINS}{$name}{ORIGIN} // 'unknown')
340+
$self->{ACTION_VERBOSE}("\e[33mOverriding action: '$name', file: '$action_file', old_file: '" . ($self->{ACTIONS_BY_NAME}{ORIGINS}{$name}{ORIGIN} // 'unknown'))
334341
if $self->{DISPLAY_SETUP_ACTION_INFORMATION} ;
335342

336343
my $old_handler = $self->{ACTIONS_BY_NAME}{$name} ;
@@ -364,7 +371,7 @@ if(exists $self->{ACTIONS_BY_NAME}{$name})
364371
$action_handler->{CONTEXT_MENU_ARGUMENTS} = $old_handler->{CONTEXT_MENU_ARGUMENTS} ;
365372
}
366373

367-
print STDERR "$reused\e[m\n" ;
374+
$self->{ACTION_VERBOSE}("$reused\e[m\n") ;
368375
}
369376
}
370377

@@ -421,10 +428,10 @@ for my $name (grep { $_ ne 'SHORTCUTS' && $_ ne 'ESCAPE_KEYS' } keys %{$group_de
421428

422429
for my $shortcut ('ARRAY' eq ref $shortcuts_definition ? @$shortcuts_definition : ($shortcuts_definition))
423430
{
424-
print STDERR "Overriding action group '$shortcut' with definition from file '$setup_path/$action_file'!\n"
431+
$self->{ACTION_VERBOSE}("Overriding action group '$shortcut' with definition from file '$setup_path/$action_file'!\n")
425432
if exists $handler{$shortcut} && $self->{DISPLAY_SETUP_ACTION_INFORMATION} ;
426433

427-
# print STDERR "\e[32maction_handler: '$name' shortcut: $shortcut\e[m\n" ;
434+
# $self->{ACTION_VERBOSE}("\e[32maction_handler: '$name' shortcut: $shortcut\e[m\n") ;
428435
$handler{$shortcut} = $action_handler ;
429436

430437
$handler{$shortcut}{GROUP_NAME} = $group_name if defined $group_name ;
@@ -474,7 +481,7 @@ EOC
474481
{
475482
if(exists $self->{IMPORT_EXPORT_HANDLERS}{$extension})
476483
{
477-
print STDERR "Overriding import/export handler for extension '$extension' in file '$setup_path/$import_export_file'\n" ;
484+
$self->{WARN}("Overriding import/export handler for extension '$extension' in file '$setup_path/$import_export_file'\n") ;
478485
}
479486

480487
$self->{IMPORT_EXPORT_HANDLERS}{$extension} = $import_export_handlers{$extension} ;

script/asciio

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ $window->add($scwin);
3030

3131
my @asciios ;
3232

33-
my $asciio = new App::Asciio::GTK::Asciio($window, 50, 25, $scwin) ;
34-
35-
push @asciios, $asciio ;
33+
push @asciios, my $asciio = new App::Asciio::GTK::Asciio($window, 50, 25, $scwin) ;
3634

3735
$scwin->add_with_viewport($asciio->{widget});
3836
$scwin->show_all();
@@ -42,6 +40,18 @@ my ($command_line_switch_parse_ok, $command_line_parse_message, $asciio_config)
4240

4341
die "Error: '$command_line_parse_message'!" unless $command_line_switch_parse_ok ;
4442

43+
my %object_override ;
44+
if(defined $asciio_config->{DEBUG_FD})
45+
{
46+
open my $fh, ">&=", $asciio_config->{DEBUG_FD} or die "can't open fd 5: $!\n" ;
47+
$fh->autoflush(1) ;
48+
%object_override = (WARN => sub { print $fh "@_\n" }, ACTION_VERBOSE => sub { print $fh "$_[0]\n" ; } ) ;
49+
}
50+
else
51+
{
52+
%object_override = (WARN => sub { print STDERR "@_\n" }, ACTION_VERBOSE => sub { print STDERR "$_[0]\n" ; } ) ;
53+
}
54+
4555
my $setup_paths = [] ;
4656

4757
if(@{$asciio_config->{SETUP_PATHS}})
@@ -61,8 +71,7 @@ else
6171
] ;
6272
}
6373

64-
$asciio->setup($setup_paths) ;
65-
$asciio->{ACTION_VERBOSE} = sub { print STDERR "@_\n" } ;
74+
$asciio->setup($setup_paths, \%object_override) ;
6675

6776
my ($character_width, $character_height) = $asciio->get_character_size() ;
6877

script/asciio_to_text

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,23 @@ my ($command_line_switch_parse_ok, $command_line_parse_message, $asciio_config)
1818

1919
die "Error: '$command_line_parse_message'!" unless $command_line_switch_parse_ok ;
2020

21+
my %object_override ;
22+
if(defined $asciio_config->{DEBUG_FD})
23+
{
24+
open my $fh, ">&=", $asciio_config->{DEBUG_FD} or die "can't open fd 5: $!\n" ;
25+
$fh->autoflush(1) ;
26+
%object_override = (WARN => sub { print $fh "@_\n" }, ACTION_VERBOSE => sub { print $fh "$_[0]\n" ; } ) ;
27+
}
28+
else
29+
{
30+
%object_override = (WARN => sub { print STDERR "@_\n" }, ACTION_VERBOSE => sub { print STDERR "$_[0]\n" ; } ) ;
31+
}
32+
2133
my $setup_paths = [] ;
2234

2335
if(@{$asciio_config->{SETUP_PATHS}})
2436
{
25-
$asciio->setup($asciio_config->{SETUP_PATHS}) ;
37+
$asciio->setup($asciio_config->{SETUP_PATHS}, \%object_override) ;
2638
}
2739
else
2840
{
@@ -34,13 +46,13 @@ else
3446
$setup_path . 'setup.ini',
3547
$ENV{HOME} . '/.config/Asciio/Asciio.ini',
3648
] ;
49+
50+
$asciio->setup($setup_paths, { %object_override, DISPLAY_SETUP_ACTION_INFORMATION => 0 }) ;
3751
}
3852

39-
$asciio->setup($setup_paths, { DISPLAY_SETUP_ACTION_INFORMATION => 0 }) ;
40-
4153
if(defined $asciio_config->{TARGETS}[0])
4254
{
43-
local $asciio->{ACTION_VERBOSE} = undef ;
55+
local $asciio->{ACTION_VERBOSE} = sub { ; } ;
4456
$asciio->run_actions_by_name(['Open', $asciio_config->{TARGETS}[0]]) ;
4557
}
4658

script/tasciio

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,25 @@ use File::Basename ;
1212

1313
my $asciio = App::Asciio::Text->new(50, 25) ;
1414

15+
STDERR->autoflush(1) ;
16+
1517
my ($command_line_switch_parse_ok, $command_line_parse_message, $asciio_config)
1618
= $asciio->ParseSwitches([@ARGV], 0) ;
1719

1820
die "Error: '$command_line_parse_message'!" unless $command_line_switch_parse_ok ;
1921

22+
my %object_override ;
23+
if(defined $asciio_config->{DEBUG_FD})
24+
{
25+
open my $fh, ">&=", $asciio_config->{DEBUG_FD} or die "can't open fd 5: $!\n" ;
26+
$fh->autoflush(1) ;
27+
%object_override = (WARN => sub { print $fh "@_\n" }, ACTION_VERBOSE => sub { print $fh "$_[0]\n" ; } ) ;
28+
}
29+
else
30+
{
31+
%object_override = (WARN => sub { print STDERR "@_\n" }, ACTION_VERBOSE => sub { print STDERR "$_[0]\n" ; } ) ;
32+
}
33+
2034
my $setup_paths = [] ;
2135

2236
if(@{$asciio_config->{SETUP_PATHS}})
@@ -42,17 +56,10 @@ $asciio->run_actions_by_name(['Open', $title]) if defined $title ;
4256
# 'open' deserializes an asciio object with it's attributes, if the file
4357
# was saved by a different asciio object (GUI/TUI), the attributes in
4458
# the serialized object will not fit, run setup after 'open'
45-
$asciio->setup($setup_paths) ;
46-
47-
$asciio->set_title($title) if defined $title ;
4859

49-
STDERR->autoflush(1) ;
50-
51-
# open my $fh, ">&=", 5 or die "can't open fh 5: $!\n" ;
52-
# $fh->autoflush(1) ;
60+
$asciio->setup($setup_paths, \%object_override) ;
5361

54-
# $asciio->{ACTION_VERBOSE} = sub { print STDERR "\e[?25l\e[H" ."$_[0]\n" ; } ;
55-
# $asciio->{ACTION_VERBOSE} = sub { ; } ;
62+
$asciio->set_title($title) if defined $title ;
5663

5764
my ($character_width, $character_height) = $asciio->get_character_size() ;
5865

setup/Text/asciio_object/basic.pl

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

22
DRAW_CONNECTION_POINTS => 1,
33
DRAW_HINT_LINES => 0,
4-
ACTION_VERBOSE => 0,
4+
55
LAST_ACTION => '',
66
DIALOGS =>
77
{

setup/asciio_object/basic.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
COPY_OFFSET_Y => 1,
2525
MOUSE_X => 0,
2626
MOUSE_Y => 0,
27-
ACTION_VERBOSE => undef,
27+
2828
DRAG_SELECTS_ARROWS => 0,
2929

3030
COLORS => {},

0 commit comments

Comments
 (0)