Skip to content

Commit

Permalink
ADDED: bindings help
Browse files Browse the repository at this point in the history
  • Loading branch information
nkh committed Nov 15, 2023
1 parent e8752ee commit 2b0171d
Show file tree
Hide file tree
Showing 12 changed files with 904 additions and 207 deletions.
7 changes: 5 additions & 2 deletions Todo.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

run script from asciio
insert boxes, ...
bindings overlay
on off
for top level
except movements
with movements

constraints
alignement
Expand Down
16 changes: 16 additions & 0 deletions documentation/mdbook_asciio/src/Bindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,21 @@ accessed with shortcuts that start with the same letter.

The bindings can be changed in your user configuration, See configuration/user_bindings

# Bindings help

***Binding:*** zb

![bindings_help](bindings_help.gif)

You can get a pop up showing the bindings (*?* in the top level) Or you can configure it:

```
USE_BINDINGS_COMPLETION => 1,
```

## Bindings map

*bindings change truth is in the config not this snapshot*

![bindings](asciio_bindings.png)

Binary file added documentation/mdbook_asciio/src/bindings_help.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
378 changes: 378 additions & 0 deletions group_bindings.md

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions lib/App/Asciio.pm
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,9 @@ my $modifiers = $event->{MODIFIERS} ;

if($self->{PREVIOUS_X} != $x || $self->{PREVIOUS_Y} != $y)
{
delete $self->{BINDINGS_COMPLETION} ;
$self->update_display ;

if($self->exists_action("${modifiers}motion_notify"))
{
$self->run_actions(["${modifiers}motion_notify", $event]) ;
Expand Down
84 changes: 83 additions & 1 deletion lib/App/Asciio/Actions.pm
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@

package App::Asciio ;

use strict ; use warnings ;

use Encode ;
use List::Util qw(max) ;

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

Expand All @@ -17,6 +21,65 @@ $self->run_actions($action) ;
$self->{CROSS_ACTION_GROUP}++ ;
}

sub create_binding_completions
{
my ($self, $keep_visible) = @_ ;

if($self->{USE_BINDINGS_COMPLETION})
{
my $binding_max_length =
max map { length }
grep {
$_ ne 'IS_GROUP'
&& $_ ne 'ENTER_GROUP'
&& $_ ne 'ESCAPE_KEY'
&& $_ ne 'NAME'
&& $_ ne 'SHORTCUTS'
&& $_ ne 'ORIGIN'
&& $_ ne 'CODE'
}
keys $self->{CURRENT_ACTIONS}->%* ;

my $max_length = 0 ;

$self->{BINDINGS_COMPLETION} =
[
map
{
my $completion = sprintf("%-${binding_max_length}s - %s", $_, $self->{CURRENT_ACTIONS}{$_}{NAME}) ;
my $length = length $completion ;

$max_length = $length if $length > $max_length ;
$completion ;
}
sort grep {
$_ ne 'IS_GROUP'
&& $_ ne 'ENTER_GROUP'
&& $_ ne 'ESCAPE_KEY'
&& $_ ne 'NAME'
&& $_ ne 'SHORTCUTS'
&& $_ ne 'ORIGIN'
&& $_ ne 'CODE'
}
keys $self->{CURRENT_ACTIONS}->%*
] ;

$self->{BINDINGS_COMPLETION_LENGTH} = $max_length ;

$self->update_display() ;
}
else
{
if(exists $self->{BINDINGS_COMPLETION})
{
delete $self->{BINDINGS_COMPLETION} ;
$self->update_display() ;
}
}

$_[0]->{KEEP_BINDINGS_COMPLETION}++ if $keep_visible ;
}

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

sub run_actions
Expand Down Expand Up @@ -92,9 +155,26 @@ for my $action (@actions)
] ;
}

$self->{CURRENT_ACTIONS} = $self->{ACTIONS} unless $is_group || $in_capture || $self->{CROSS_ACTION_GROUP} ;
$is_group += $self->{CROSS_ACTION_GROUP} // 0 ;
delete $self->{CROSS_ACTION_GROUP} ;

$self->{CURRENT_ACTIONS} = $self->{ACTIONS} unless $is_group || $in_capture ;

if ($is_group)
{
$self->create_binding_completions() ;
}
else
{
unless ($self->{KEEP_BINDINGS_COMPLETION})
{
delete $self->{BINDINGS_COMPLETION} ;
$self->update_display() ;
}

delete $self->{KEEP_BINDINGS_COMPLETION} ;
}

if($is_group && defined $self->{CURRENT_ACTIONS}{ENTER_GROUP})
{
$self->{CURRENT_ACTIONS}{ENTER_GROUP}->($self) ;
Expand Down Expand Up @@ -131,9 +211,11 @@ for my $action (@actions)
{
$self->{ACTION_VERBOSE}->(sprintf "\e[31m%-30s\e[m", "$action") if $self->{ACTION_VERBOSE} ;
$self->{CURRENT_ACTIONS} = $self->{ACTIONS} ;

}

$self->update_display() ;
delete $self->{BINDINGS_COMPLETION} ;
}
}

Expand Down
50 changes: 49 additions & 1 deletion lib/App/Asciio/GTK/Asciio.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use Glib ':constants';
use Gtk3 -init;
use Pango ;

use List::MoreUtils qw(all) ;
use List::Util qw(min) ;

use App::Asciio::GTK::Asciio::stripes::editable_exec_box;
use App::Asciio::GTK::Asciio::stripes::editable_box2;
Expand Down Expand Up @@ -477,11 +477,59 @@ if($self->{DRAW_HINT_LINES})
$gc->stroke() ;
}

$self->display_bindings_completion($gc, $character_width, $character_height) ;

return TRUE;
}

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

sub display_bindings_completion
{
my ($self, $gc, $character_width, $character_height) = @_ ;

if ($self->{USE_BINDINGS_COMPLETION} && defined $self->{BINDINGS_COMPLETION})
{
$gc->set_source_rgb(@{$self->get_color('hint_background')}) ;

my ($width, $height) = ($self->{BINDINGS_COMPLETION_LENGTH} * $character_width, $character_height * $self->{BINDINGS_COMPLETION}->@*) ;

my ($window_width, $window_height) = $self->{root_window}->get_size() ;

my $start_x ;
if ($window_width < (($self->{MOUSE_X} + 3) * $character_width) + $width)
{
$start_x = (($self->{MOUSE_X} - 3) * $character_width) - $width ;
}
else
{
$start_x = ($self->{MOUSE_X} + 3) * $character_width ;
}

my $start_y = min($window_height - $height , ($self->{MOUSE_Y} + 1) * $character_height) ;

$gc->rectangle($start_x, $start_y, $width, $height) ;
$gc->fill() ;

my $surface = Cairo::ImageSurface->create('argb32', $width, $height) ;
my $gco = Cairo::Context->create($surface) ;

my $layout = Pango::Cairo::create_layout($gco) ;
my $font_description = Pango::FontDescription->from_string($self->get_font_as_string()) ;
$layout->set_font_description($font_description) ;

$layout->set_text(join "\n", $self->{BINDINGS_COMPLETION}->@*) ;
Pango::Cairo::show_layout($gco, $layout) ;

$gc->set_source_surface($surface, $start_x, $start_y) ;
$gc->paint;

$gc->stroke() ;
}
}

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

sub draw_cross_overlays
{
my ($self, $gc, $widget_width, $widget_height, $character_width, $character_height) = @_ ;
Expand Down
44 changes: 43 additions & 1 deletion lib/App/Asciio/Setup.pm
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ my $installed = find_installed('App::Asciio') ;
my ($basename, $path, $ext) = File::Basename::fileparse($installed, ('\..*')) ;
my $asciio_setup_path = $path . $basename . '/setup/' ;

my %first_level_group ;

for my $action_file (@{ $action_files })
{
my $context = new Eval::Context() ;
Expand All @@ -152,6 +154,7 @@ for my $action_file (@{ $action_files })
INSTALL_SUBS => {
register_action_handlers => sub { %action_handlers = @_ ; },
register_action_handlers_remove_old_shortcuts => sub { %action_handlers = @_ ; $remove_old_shortcuts++ ; },
register_first_level_group => sub { %first_level_group = (%first_level_group, @_) ; },
},
PRE_CODE => "use strict;\nuse warnings;\n",
CODE_FROM_FILE => $location,
Expand Down Expand Up @@ -265,6 +268,14 @@ for my $action_file (@{ $action_files })
}
}
}

my $action_handler = $self->setup_first_level_group(\%first_level_group) ;
my $name = $action_handler->{SHORTCUTS}[0] ;

if (defined $name)
{
$self->{ACTIONS}{$name} = $action_handler ;
}
}

#------------------------------------------------------------------------------------------------------
Expand All @@ -276,6 +287,7 @@ my $name = $action_handler->{NAME} ;

if(exists $self->{ACTIONS_BY_NAME}{$name})
{
my $reused = '' ;
print "\e[33mOverriding action: '$name', file: '$action_file', old_file: '" . ($self->{ACTIONS_BY_NAME}{ORIGINS}{$name}{ORIGIN} // 'unknown') ;

my $old_handler = $self->{ACTIONS_BY_NAME}{$name} ;
Expand All @@ -285,7 +297,6 @@ if(exists $self->{ACTIONS_BY_NAME}{$name})
die "\tno shortcuts in definition\n" ;
}

my $reused = '' ;
if(! defined $action_handler->{CODE} && defined $old_handler->{CODE})
{
$reused .= ", reused code" ;
Expand Down Expand Up @@ -316,6 +327,37 @@ if(exists $self->{ACTIONS_BY_NAME}{$name})

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

sub setup_first_level_group
{
my ($self, $group_definition) = @_ ;

my %handler ;

for my $name ( grep { $_ ne 'SHORTCUT' } keys %{$group_definition} )
{
die "Asciio: Group 'first_level' entry '$name' not defined\n" unless exists $self->{ACTIONS_BY_NAME}{$name} ;
my $handler = $self->{ACTIONS_BY_NAME}{$name} ;

for my $shortcut ('ARRAY' eq ref $handler->{SHORTCUTS} ? $handler->{SHORTCUTS}->@* : $handler->{SHORTCUTS})
{
$handler{$shortcut} = $handler
}
}

@handler{'IS_GROUP', 'ENTER_GROUP', 'ESCAPE_KEY', 'SHORTCUTS', 'CODE', 'NAME', 'ORIGIN'} =
(
1,
$group_definition->{ENTER_GROUP},
$group_definition->{ESCAPE_KEY},
[ $group_definition->{SHORTCUT} ],
sub { $_[0]->{CURRENT_ACTIONS} = \%handler },
'first_level_group',
'action_file'
) ;

return \%handler ;
}

sub get_group_action_handler
{
my ($self, $setup_path, $action_file, $group_name, $group_definition) = @_ ;
Expand Down
28 changes: 28 additions & 0 deletions lib/App/Asciio/ZBuffer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,34 @@ return
($x-1) .';'. ($y+1), $x .';'. ($y+1), ($x+1) .';'. ($y+1)
}
}
# ------------------------------------------------------------------------------

# sub get_cardinal_neighbors
# {
# my ($self, $coordinate) = @_ ;
# my ($x, $y) = split ';', $coordinate ;

# return
# {
# map
# {
# exists $self->{coordinates}{$_}
# ? ( $self->{coordinates}{$_} ne ' ' ? ($_ => $self->{coordinates}{$_}) : undef)
# : undef
# }
# $x .';'. ($y-1),
# $x .';'. ($y+1),
# ($x+1) .';'. $y,
# ($x-1) .';'. $y,
# ($x+1) .';'. ($y-1),
# ($x+1) .';'. ($y+1),
# ($x-1) .';'. ($y+1),
# ($x-1) .';'. ($y-1) ;
# }
# }


# my ($up, $down, $left, $right, $char_45, $char_135, $char_225, $char_315) = $zbuffer->get_cardinal_neighbors() ;

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

Expand Down
1 change: 1 addition & 0 deletions setup/Text/asciio_object/basic.pl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},

TAB_AS_SPACES => ' ',
USE_BINDINGS_COMPLETION => 0,

# use ANSI colors
COLOR_SCHEMES =>
Expand Down
Loading

0 comments on commit 2b0171d

Please sign in to comment.