From 193293755ce9026d861064eedf9c4578598c7a75 Mon Sep 17 00:00:00 2001 From: z448 Date: Tue, 23 Jan 2024 10:01:13 +0100 Subject: [PATCH] -X option for non colored and non wait_key results --- lib/App/trrr/RBG.pm | 1 - trrr | 32 +++++++++++++++++++++----------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/lib/App/trrr/RBG.pm b/lib/App/trrr/RBG.pm index d2d64cc..03b4a1f 100644 --- a/lib/App/trrr/RBG.pm +++ b/lib/App/trrr/RBG.pm @@ -77,7 +77,6 @@ sub results { $t{domain} = $domain; $t{link} = $1; $t{link} = 'https://' . $domain . $t{link}; - print "$t{link}\n"; $t{title} = $2; } diff --git a/trrr b/trrr index 56ce1ab..6624b7a 100644 --- a/trrr +++ b/trrr @@ -19,7 +19,7 @@ our $VERSION = '0.23'; my @keyword = (); -if( scalar @ARGV == 0 or (scalar @ARGV == 1 and $ARGV[0] =~ /^-(p|r|y|k|e|x|l|[A-O])$/) ){ +if( scalar @ARGV == 0 or (scalar @ARGV == 1 and $ARGV[0] =~ /^-(p|r|y|k|e|x|l|[A-O]|X)$/) ){ my $clipboard = clipboard(); $clipboard =~ s/\n/ /g; $clipboard =~ s/^ //; @@ -45,7 +45,7 @@ if( -f "$ENV{HOME}/.trrr" ){ if($field eq 'api'){ print "unrecognized source '$value'\n" and exit unless $value =~ /^(tpb|rbg|yts|kat|ext|x137|lme)$/; } - $opt->{$field} = $value if $field =~ /^(seeds|api)$/; + $opt->{$field} = $value if $field =~ /^(seeds|api|color)$/; } close $conf; } @@ -58,11 +58,13 @@ else { for(@ARGV){ - if(/^\-(h|-help|help|[A-O]|v|p|r|y|k|e|x|l)$/){ + if(/^\-(h|-help|help|[A-O]|X|v|p|r|y|k|e|x|l)$/){ s/\-//; if(/^(h|-help|help)$/){ help() and exit } if(/^(v)$/){ print "$VERSION\n" and exit } - if(/^[A-O]$/){ $opt->{key} = $_ } + if(/^[A-O]|X$/){ $opt->{key} = $_ } + if(/^X$/){ $opt->{color} = 0 } + #if(/^[A-O]$/){ $opt->{key} = $_ } if(/^p$/){ $opt->{api} = "tpb" } if(/^r$/){ $opt->{api} = "rbg" } if(/^y$/){ $opt->{api} = "yts" } @@ -146,7 +148,7 @@ sub show { unless(@result){ print colored(['yellow'], 'no results') . "\n" and exit } - print colored(['white on_white'], ' ') . colored(['black on_white'], $result[0]->{source}) . colored(['white on_white'], ' ') ."\n"; + print colored(['white on_white'], ' ') . colored(['black on_white'], $result[0]->{source}) . colored(['white on_white'], ' ') ."\n" if $opt->{color}; my $key = 'A'; my( $key_color ) = (); @@ -165,9 +167,17 @@ sub show { } if($_->{api} eq 'yts'){ - print colored([$key_color], $key) . ' ' . colored( ['yellow'], $_->{title} ) . ' ' . colored(['yellow'], "($_->{year})") . ' ' . colored(['grey8'], $_->{category}) . "\n"; + if( $opt->{color} ){ + print colored([$key_color], $key) . ' ' . colored( ['yellow'], $_->{title} ) . ' ' . colored(['yellow'], "($_->{year})") . ' ' . colored(['grey8'], $_->{category}) . "\n"; + } else { + print $key . ' ' . $_->{title} . ' ' . $_->{year} . ' ' . $_->{category} . "\n"; + } } else { - print colored([$key_color], $key) . ' ' . colored(['grey7'], $_->{seeds}) . ' ' . colored(['yellow'], $_->{title} ) . ' ' . colored(['grey7'], $_->{category}) . ' ' . colored(['bold'], $_->{size}) . "\n"; + if( $opt->{color} ){ + print colored([$key_color], $key) . ' ' . colored(['grey7'], $_->{seeds}) . ' ' . colored(['yellow'], $_->{title} ) . ' ' . colored(['grey7'], $_->{category}) . ' ' . colored(['bold'], $_->{size}) . "\n"; + } else { + print $key . ' ' . $_->{seeds} . ' ' . $_->{title} . ' ' . $_->{category} . ' ' . $_->{size} . "\n"; + } } $key++; $i++; } @@ -178,17 +188,15 @@ sub wait_key { my $result = shift; if( $opt->{key} ){ + exit if $opt->{key} eq 'X'; get_torrent($result) and exit; } else { if( $^O eq 'MSWin32' or $^O eq 'msys' ){ print "To pick from results repeat search and add -[key] (e.g. -a)\n" and exit; } - - # print colored(['white on_grey3'],'P') . colored(['grey5 on_white'],'RESS') . colored(['white on_grey3'],'K') . colored(['grey5 on_white'],'EY') . "\n"; + print ' ' . colored(['grey5 on_white'],'P') . colored(['white on_grey3'],'RESS') . colored(['grey5 on_white'],'K') . colored(['white on_grey3'],'EY') . "\n"; - #require App::trrr::HotKey; - #App::trrr::HotKey->import( 'readkey' ) ; use App::trrr::HotKey qw< readkey >; $opt->{key} = uc readkey(); get_torrent($result); @@ -298,6 +306,8 @@ C - To automaticaly open some magnet link from results add its key -[A-O] as an option. E.g: to open first (A) magnet link use following command. +- To just list results without picking any use -X option. + =over 10 C