aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2020-08-03 00:14:03 +0530
committerAndinus <andinus@nand.sh>2020-08-03 00:14:03 +0530
commit4af2e54cedd28d11150f7c339cb53ba4adc64258 (patch)
treee4533a62662fa01df22902aa6b0eb18f271cd162
parenta86b7ddf871b545cb951c58d7dda2cedee80cf2a (diff)
downloadara-4af2e54cedd28d11150f7c339cb53ba4adc64258.tar.gz
Add auto hide functionality
This will automatically hide columns if the term size is small. It's just some dumb if conditions, no magic.
-rwxr-xr-xara.pl15
1 files changed, 14 insertions, 1 deletions
diff --git a/ara.pl b/ara.pl
index b28cd31..16af5f9 100755
--- a/ara.pl
+++ b/ara.pl
@@ -6,6 +6,7 @@ use warnings;
use lib::relative 'lib';
use StateNotes;
+use Term::Size;
use Path::Tiny;
use Time::Moment;
use Text::ASCIITable;
@@ -34,7 +35,8 @@ foreach my $path (@INC) {
}
my ( $use_local_file, $get_latest, $state_notes, $rows_to_print, $no_delta,
- $no_total, @to_hide, %hide, @to_show, %show, $no_words, $show_delta );
+ $no_total, @to_hide, %hide, @to_show, %show, $no_words, $show_delta,
+ $auto_hide );
sub HelpMessage {
print LOCALCOLOR GREEN "Options:
@@ -45,6 +47,7 @@ sub HelpMessage {
--showdelta Print delta values for all rows
--nodelta Don't print changes in values
--nowords Don't format numbers with words
+ --autohide Automatically hide columns according to term size
--hide Hide states, columns from table (space seperated)
--show Show only these states (space seperated)";
print LOCALCOLOR CYAN "
@@ -61,6 +64,7 @@ GetOptions(
"showdelta" => \$show_delta,
"nodelta" => \$no_delta,
"nototal" => \$no_total,
+ "autohide" => \$auto_hide,
"nowords" => \$no_words,
"hide=s{1,}" => \@to_hide, # Getopt::Long docs say that this is an
# experimental feature with a warning.
@@ -79,6 +83,15 @@ Overriding --latest option\n";
push @to_hide, "india"
if $no_total;
+if ( $auto_hide ) {
+ my ( $t_columns, $t_rows ) = Term::Size::chars;
+
+ push @to_hide, "updated" if $t_columns < 110;
+ push @to_hide, "active" if $t_columns < 100;
+ undef $show_delta if $t_columns < 80;
+ $no_delta = 0 if $t_columns < 80;
+}
+
# Creating %hide and undefining all %hash{@to_hide}, after this we
# check if %hash{@to_hide} exists with exists keyword. Read this as
# "undef these keys from the hash". https://perldoc.pl/perldata#Slices