Skip to content

Commit

Permalink
ADDED: execute script from asciio
Browse files Browse the repository at this point in the history
  • Loading branch information
nkh committed Nov 14, 2023
1 parent 2663db8 commit 4533086
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 8 deletions.
3 changes: 3 additions & 0 deletions Todo.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

run script from asciio
insert boxes, ...

constraints
alignement
arrows not overlapping
Expand Down
16 changes: 16 additions & 0 deletions documentation/mdbook_asciio/src/for_developers/scripting.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,20 @@ save_to "from_script.asciio" ;
ascii_out ;
```

## Executing your script

### From the command line

The script is a normal perl script.

```
perl my_asciio_script.pl
```

### From within Asciio

***Binding:*** «:!»

Pick the file you want to execute.


6 changes: 6 additions & 0 deletions documentation/scripting/asciio_script.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

add 'box1', new_box(TEXT_ONLY =>'A'), 0, 2 ;
add 'box2', new_box(TEXT_ONLY =>'B'), 20, 10 ;
add 'box3', new_box(TEXT_ONLY =>'C'), 40, 5 ;

select_all_elements 1 ;
1 change: 1 addition & 0 deletions documentation/scripting/connected_boxes.pl
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@

ascii_out ;

select_all_elements ;
26 changes: 26 additions & 0 deletions lib/App/Asciio/Scripting.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require Exporter ;
move_named_connector
optimize_connections
get_canonizer
run_external_script
) ;

use strict ; use warnings ;
Expand Down Expand Up @@ -50,6 +51,22 @@ use App::Asciio::stripes::wirl_arrow ;
my $script_asciio ; # make script non OO
my %name_to_element ;

sub run_external_script
{
my ($asciio) = @_ ;

my $script = $asciio->get_file_name() ;

if(defined $script)
{
$script_asciio = $asciio ;

do $script ;

$asciio->update_display() ;
}
}

sub new_script_asciio
{
$script_asciio = new App::Asciio() ;
Expand Down Expand Up @@ -97,6 +114,15 @@ my ($element1_name, $element2_name, @args) = @_ ;
add_connection($script_asciio, @name_to_element{$element1_name, $element2_name}, @args) ;
}

sub select_elements
{
my ($state, @elements) = @_ ;
$script_asciio->select_elements($state, @name_to_element{@elements}) ;
}

sub select_all_elements { $script_asciio->select_all_elements() ; }
sub deselect_all_elements { $script_asciio->select_all_elements() ; }

sub save_to { $script_asciio->save_with_type(undef, 'asciio', $_[0]) ; }
sub to_ascii { $script_asciio->transform_elements_to_ascii_buffer() ; }
sub ascii_out { print $script_asciio->transform_elements_to_ascii_buffer() ; }
Expand Down
17 changes: 9 additions & 8 deletions setup/actions/default_bindings.pl
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
use App::Asciio::Actions::Multiwirl ;
use App::Asciio::Actions::Presentation ;
use App::Asciio::Actions::Ruler ;
use App::Asciio::Scripting ;
use App::Asciio::Actions::Shapes ;
use App::Asciio::Actions::Unsorted ;
use App::Asciio::Actions::ZBuffer ;


#----------------------------------------------------------------------------------------------

register_action_handlers
Expand Down Expand Up @@ -220,14 +220,15 @@
'Display commands' => ['000-c', \&App::Asciio::Actions::Unsorted::display_commands ],
'Display action files' => ['000-f', \&App::Asciio::Actions::Unsorted::display_action_files ],
'Display manpage' => ['000-m', \&App::Asciio::Actions::Unsorted::manpage_in_browser ],


'Open' => ['000-e', \&App::Asciio::Actions::File::open ],
'Save' => ['000-w', \&App::Asciio::Actions::File::save, undef ],
'SaveAs' => ['00S-W', \&App::Asciio::Actions::File::save, 'as' ],
'Insert' => ['000-r', \&App::Asciio::Actions::File::insert ],
'Quit' => ['000-q', \&App::Asciio::Actions::File::quit ],
'Quit no save' => ['00S-Q', \&App::Asciio::Actions::File::quit_no_save],
'Run external script' => ['00S-exclam', \&App::Asciio::Scripting::run_external_script ],

'Open' => ['000-e', \&App::Asciio::Actions::File::open ],
'Save' => ['000-w', \&App::Asciio::Actions::File::save, undef ],
'SaveAs' => ['00S-W', \&App::Asciio::Actions::File::save, 'as' ],
'Insert' => ['000-r', \&App::Asciio::Actions::File::insert ],
'Quit' => ['000-q', \&App::Asciio::Actions::File::quit ],
'Quit no save' => ['00S-Q', \&App::Asciio::Actions::File::quit_no_save ],
},

'Insert leader' =>
Expand Down

0 comments on commit 4533086

Please sign in to comment.