diff --git a/Changes b/Changes index 3872f30..d6c8eaa 100644 --- a/Changes +++ b/Changes @@ -4,6 +4,7 @@ - Fix dashes (-) not being accepted in hostname range expansion (Github issue #89) - Amend ranges to work on ports, FQDN's and IP addresses - Fix bug tracker links in the main documentation (Github issue #92) +- New options to specify --rows, --columns and --fillscreen (Github pull request #88) (Thanks to AsharLohmar) 4.10_01 2017-04-12 Duncan Ferguson - Allow 'include' directives when reading SSH configuration files (Github issue #77) (thanks to Azenet) diff --git a/lib/App/ClusterSSH.pm b/lib/App/ClusterSSH.pm index eb4646b..172ddc9 100644 --- a/lib/App/ClusterSSH.pm +++ b/lib/App/ClusterSSH.pm @@ -950,30 +950,50 @@ sub retile_hosts { $self->config->{internal_screen_width} = $xdisplay->{width_in_pixels}; # Now, work out how many columns of terminals we can fit on screen - $self->config->{internal_columns} = int( - ( $self->config->{internal_screen_width} - - $self->config->{screen_reserve_left} - - $self->config->{screen_reserve_right} - ) / ( - $self->config->{internal_terminal_width} - + $self->config->{terminal_reserve_left} - + $self->config->{terminal_reserve_right} - ) - ); - - # Work out the number of rows we need to use to fit everything on screen - $self->config->{internal_rows} = int( - ( $self->config->{internal_total} - / $self->config->{internal_columns} - ) + 0.999 - ); + if ( $self->config->{rows} != -1 || $self->config->{cols} != -1 ) { + if ( $self->config->{rows} != -1 ) { + $self->config->{internal_rows} = $self->config->{rows}; + $self->config->{internal_columns} = int( + ( $self->config->{internal_total} + / $self->config->{internal_rows} + ) + 0.999 + ); + } + else { + $self->config->{internal_columns} = $self->config->{cols}; + $self->config->{internal_rows} = int( + ( $self->config->{internal_total} + / $self->config->{internal_columns} + ) + 0.999 + ); + } + } + else { + $self->config->{internal_columns} = int( + ( $self->config->{internal_screen_width} + - $self->config->{screen_reserve_left} + - $self->config->{screen_reserve_right} + ) / ( + $self->config->{internal_terminal_width} + + $self->config->{terminal_reserve_left} + + $self->config->{terminal_reserve_right} + ) + ); + # Work out the number of rows we need to use to fit everything on screen + $self->config->{internal_rows} = int( + ( $self->config->{internal_total} + / $self->config->{internal_columns} + ) + 0.999 + ); + } $self->debug( 2, "Screen Columns: ", $self->config->{internal_columns} ); $self->debug( 2, "Screen Rows: ", $self->config->{internal_rows} ); + $self->debug( 2, "Fill scree: ", $self->config->{fillscreen} ); # Now adjust the height of the terminal to either the max given, # or to get everything on screen - { + if ( $self->config->{fillscreen} ne 'yes' ) { my $height = int( ( ( $self->config->{internal_screen_height} - $self->config->{screen_reserve_top} @@ -986,15 +1006,41 @@ sub retile_hosts { ) ) / $self->config->{internal_rows} ); - - $self->debug( 2, "Terminal height=$height" ); - $self->config->{internal_terminal_height} = ( $height > $self->config->{internal_terminal_height} ? $self->config->{internal_terminal_height} : $height ); } + else { + $self->config->{internal_terminal_height} = int( + ( ( $self->config->{internal_screen_height} + - $self->config->{screen_reserve_top} + - $self->config->{screen_reserve_bottom} + ) - ( + $self->config->{internal_rows} * ( + $self->config->{terminal_reserve_top} + + $self->config->{terminal_reserve_bottom} + ) + ) + ) / $self->config->{internal_rows} + ); + $self->config->{internal_terminal_width} = int( + ( ( $self->config->{internal_screen_width} + - $self->config->{screen_reserve_left} + - $self->config->{screen_reserve_right} + ) - ( + $self->config->{internal_columns} * ( + $self->config->{terminal_reserve_left} + + $self->config->{terminal_reserve_right} + ) + ) + ) / $self->config->{internal_columns} + ); + } + $self->debug( 2, "Terminal h: ", + $self->config->{internal_terminal_height}, + ", w: ", $self->config->{internal_terminal_width} ); $self->config->dump("noexit") if ( $self->options->debug_level > 1 ); @@ -2388,3 +2434,4 @@ See http://dev.perl.org/licenses/ for more information. =cut 1; + diff --git a/lib/App/ClusterSSH/Config.pm b/lib/App/ClusterSSH/Config.pm index 3a67aae..20bc74a 100644 --- a/lib/App/ClusterSSH/Config.pm +++ b/lib/App/ClusterSSH/Config.pm @@ -108,6 +108,11 @@ my %default_config = ( # don't set username here as takes precendence over ssh config user => '', + rows => -1, + cols => -1, + + fillscreen => "no", + ); sub new { diff --git a/lib/App/ClusterSSH/Getopt.pm b/lib/App/ClusterSSH/Getopt.pm index dd23ae2..bdf2232 100644 --- a/lib/App/ClusterSSH/Getopt.pm +++ b/lib/App/ClusterSSH/Getopt.pm @@ -240,6 +240,22 @@ sub add_common_options { help => $self->loc('Do not output extra text when using some options'), ); + $self->add_option( + spec => 'cols|x=i', + arg_desc => 'cols', + help => $self->loc('Number of columns'), + ); + $self->add_option( + spec => 'rows|y=i', + arg_desc => 'rows', + help => $self->loc('Number of rows'), + ); + + $self->add_option( + spec => 'fillscreen', + help => $self->loc( + 'Resize terminal windows to fill the whole available screen'), + ); return $self; } @@ -380,6 +396,14 @@ sub getopts { = !$self->parent->config->{window_tiling} || 0; } + if ( $self->rows ) { + $self->parent->config->{rows} = $self->rows; + } + if ( $self->cols ) { + $self->parent->config->{cols} = $self->cols; + } + $self->parent->config->{fillscreen} = "yes" + if ( $self->fillscreen ); return $self; } diff --git a/t/15config.t b/t/15config.t index 4d5eb08..b4093b4 100644 --- a/t/15config.t +++ b/t/15config.t @@ -124,6 +124,10 @@ Readonly::Hash my %default_config => { # other bits inheritted from App::ClusterSSH::Base lang => 'en', user => '', + rows => -1, + cols => -1, + + fillscreen => 'no', }; my %expected = %default_config; is_deeply( $config, \%expected, 'default config is correct' ); @@ -538,12 +542,14 @@ my $expected = qq{# Configuration dump produced by "cssh -d" auto_close=5 auto_quit=yes auto_wm_decoration_offsets=no +cols=-1 console=console console_args= console_position= external_cluster_command= extra_cluster_file= extra_tag_file= +fillscreen=no hide_menu=0 history_height=10 history_width=40 @@ -568,6 +574,7 @@ max_host_menu_items=30 menu_host_autotearoff=0 menu_send_autotearoff=0 mouse_paste=Button-2 +rows=-1 rsh=rsh rsh_args= screen_reserve_bottom=60