<commit_before>#!/usr/bin/perl
# trev.pl

use strict;
use warnings;
use utf8;
binmode( STDOUT, ":utf8" );    # or use open ":utf8", ":std";

use Term::ANSIColor;      # Color screen output using ANSI escape sequences
use Term::ReadLine;       # Perl interface to various readline packages.
use Term::ReadLine::Gnu;  # Perl extension for the GNU Readline/History Library.
use Term::UI;             # Term::ReadLine UI made easy

# use Term::ReadKey;        # MSWindows?

# > > > > > > > > > > > > > > >  Configuration > > > > > > > > > > > > > > > > > > > > > >
my $prompt   = "trev> ";
my $lblstyle = "reverse bold";
my $sepstyle = "underline bold";

# Uncomment STRINGs in your preferred localization ---------------------------------- L10N
# ---------------------------------------------------------------------------------- en-US
my $STRING_LBL_SEL  = "Selected:";
my $STRING_MSG_AMB  = "is ambiguous, can be:";
my $STRING_MSG_END  = "Finished.";
my $STRING_MSG_ERR  = "Warning: not completed";
my $STRING_MSG_NON  = "\nNone\n\n";
my $STRING_MSG_QIT  = "Terminated (task ";
my $STRING_MSG_RET  = "Press [RET] to continue: ";
my $STRING_MSG_STA  = ": doesn't appear as visible.";
my $STRING_MSG_UND  = "Not understood.";
my $STRING_MSG_VER  = "Taskwarrior version must be 2.2.0 at least.";
my $STRING_NOW_TXT  = "Now reviewing:";
# ---------------------------------------------------------------------------------- es-ES
#my $STRING_LBL_SEL = "Seleccionadas:";
#my $STRING_MSG_AMB = "es ambiguo, puede ser:";
#my $STRING_MSG_END = "Finalizado.";
#my $STRING_MSG_ERR = "Aviso: no se completa";
#my $STRING_MSG_NON = "\nNinguna\n\n";
#my $STRING_MSG_QIT = "Terminado (tarea ";
#my $STRING_MSG_RET = "Presione [RET] para continuar: ";
#my $STRING_MSG_STA = ": no aparece como visible.";
#my $STRING_MSG_UND = "No comprendido.";
#my $STRING_MSG_VER = "Taskwarrior debe estar al menos en su versión 2.2.0 .";
#my $STRING_NOW_TXT = "Revisando ahora:";

# ---------------------------------------------------------- selection and filter defaults
my $selatt = "active";    # selection attribute
my $on     = "start";     # select action
my $off    = "stop";      # unselect action
my $filter = "";

# < < < < < < < < < < < < < < <  Configuration < < < < < < < < < < < < < < < < < < < < < <

# -------------------------------------------------------------------------- Version check
my ( $major, $minor ) = split( /\./, `task --version` );
if ( $major < 2 || $minor < 2 ) { print "$STRING_MSG_VER\n"; exit(1); }

my $term = Term::ReadLine->new('');
$term->ornaments(0);    # disable prompt default styling (underline)

#my %features = %{$term->Features};
#print "Features supported by ",$term->ReadLine,"\n";
#foreach (sort keys %features) { print "\t$_ => \t$features{$_}\n"; }; exit 0;

# ---------------------------------------------------------------------- Parsing arguments
my $start  = -1;

if ( scalar(@ARGV) != 0 ) {
    if ( $ARGV[0] =~ m/\+\+(.+)/ )
    {                     # selection attribute requested: matches '++some'
        $selatt = "+$1";           # selection attribute
        $on     = "modify +$1";    # select action
        $off    = "modify -$1";    # unselect action
        shift(@ARGV);              # pulls $ARGV[0] out ; $ARGV[1] => $ARGV[0]
    }

    # if starting task number requested (matches 'digit(s)+'):
    if ( scalar(@ARGV) && $ARGV[0] =~ m/(\d+)\+/ ) {
        $start = $1;
        $filter =~ s/$start//;
        shift(@ARGV);              # pulls $ARGV[0] out ; $ARGV[1] => $ARGV[0]

        # check $start exists (and throwing STDOUT and STDERR)
        my $sysret = system("task $start rc.verbose:off >/dev/null 2>&1");

        # system() returns a false value on success, then:
        if ( $sysret != 0 ) {
            print "$start$STRING_MSG_STA\n";
            exit(2);               # exit on error
        }

    }
    $filter = join( ' ', @ARGV );
}

# ------------------------------------------------------------------------ Allowed Actions
# These actions don't change the total number of tasks:
my @allow = (
    'annotate',    'append',  'denotate', 'edit',
    'information', 'log',     'prepend',  'start',
    'stop',        'version', 'calendar'
);

# These actions can change the total number of tasks:
my @allowch = ( 'add', 'delete', 'done', 'modify', );    # 'duplicate','undo'

# These actions don't need a task number in the command line:
my @nonumb = ( 'add', 'log', 'version', 'calendar' );

# ----------------------------------------------------------------------------- gettasks()<commit_msg>Relocated code defining allowed actions to a more logical place.<commit_after>#!/usr/bin/perl
# trev.pl

use strict;
use warnings;
use utf8;
binmode( STDOUT, ":utf8" );    # or use open ":utf8", ":std";

use Term::ANSIColor;      # Color screen output using ANSI escape sequences
use Term::ReadLine;       # Perl interface to various readline packages.
use Term::ReadLine::Gnu;  # Perl extension for the GNU Readline/History Library.
use Term::UI;             # Term::ReadLine UI made easy

# use Term::ReadKey;        # MSWindows?

# > > > > > > > > > > > > > > >  Configuration > > > > > > > > > > > > > > > > > > > > > >
my $prompt   = "trev> ";
my $lblstyle = "reverse bold";
my $sepstyle = "underline bold";

# Uncomment STRINGs in your preferred localization ---------------------------------- L10N
# ---------------------------------------------------------------------------------- en-US
my $STRING_LBL_SEL  = "Selected:";
my $STRING_MSG_AMB  = "is ambiguous, can be:";
my $STRING_MSG_END  = "Finished.";
my $STRING_MSG_ERR  = "Warning: not completed";
my $STRING_MSG_NON  = "\nNone\n\n";
my $STRING_MSG_QIT  = "Terminated (task ";
my $STRING_MSG_RET  = "Press [RET] to continue: ";
my $STRING_MSG_STA  = ": doesn't appear as visible.";
my $STRING_MSG_UND  = "Not understood.";
my $STRING_MSG_VER  = "Taskwarrior version must be 2.2.0 at least.";
my $STRING_NOW_TXT  = "Now reviewing:";
# ---------------------------------------------------------------------------------- es-ES
#my $STRING_LBL_SEL = "Seleccionadas:";
#my $STRING_MSG_AMB = "es ambiguo, puede ser:";
#my $STRING_MSG_END = "Finalizado.";
#my $STRING_MSG_ERR = "Aviso: no se completa";
#my $STRING_MSG_NON = "\nNinguna\n\n";
#my $STRING_MSG_QIT = "Terminado (tarea ";
#my $STRING_MSG_RET = "Presione [RET] para continuar: ";
#my $STRING_MSG_STA = ": no aparece como visible.";
#my $STRING_MSG_UND = "No comprendido.";
#my $STRING_MSG_VER = "Taskwarrior debe estar al menos en su versión 2.2.0 .";
#my $STRING_NOW_TXT = "Revisando ahora:";

# ---------------------------------------------------------- selection and filter defaults
my $selatt = "active";    # selection attribute
my $on     = "start";     # select action
my $off    = "stop";      # unselect action
my $filter = "";

# < < < < < < < < < < < < < < <  Configuration < < < < < < < < < < < < < < < < < < < < < <

# -------------------------------------------------------------------------- Version check
my ( $major, $minor ) = split( /\./, `task --version` );
if ( $major < 2 || $minor < 2 ) { print "$STRING_MSG_VER\n"; exit(1); }

my $term = Term::ReadLine->new('');
$term->ornaments(0);    # disable prompt default styling (underline)

#my %features = %{$term->Features};
#print "Features supported by ",$term->ReadLine,"\n";
#foreach (sort keys %features) { print "\t$_ => \t$features{$_}\n"; }; exit 0;

# ------------------------------------------------------------------------ Allowed Actions
# These actions don't change the total number of tasks:
my @allow = (
    'annotate',    'append',  'denotate', 'edit',
    'information', 'log',     'prepend',  'start',
    'stop',        'version', 'calendar'
);

# These actions can change the total number of tasks:
my @allowch = ( 'add', 'delete', 'done', 'modify', );    # 'duplicate','undo'

# These actions don't need a task number in the command line:
my @nonumb = ( 'add', 'log', 'version', 'calendar' );

# ---------------------------------------------------------------------- Parsing arguments
my $start  = -1;

if ( scalar(@ARGV) != 0 ) {
    if ( $ARGV[0] =~ m/\+\+(.+)/ )
    {                     # selection attribute requested: matches '++some'
        $selatt = "+$1";           # selection attribute
        $on     = "modify +$1";    # select action
        $off    = "modify -$1";    # unselect action
        shift(@ARGV);              # pulls $ARGV[0] out ; $ARGV[1] => $ARGV[0]
    }

    # if starting task number requested (matches 'digit(s)+'):
    if ( scalar(@ARGV) && $ARGV[0] =~ m/(\d+)\+/ ) {
        $start = $1;
        $filter =~ s/$start//;
        shift(@ARGV);              # pulls $ARGV[0] out ; $ARGV[1] => $ARGV[0]

        # check $start exists (and throwing STDOUT and STDERR)
        my $sysret = system("task $start rc.verbose:off >/dev/null 2>&1");

        # system() returns a false value on success, then:
        if ( $sysret != 0 ) {
            print "$start$STRING_MSG_STA\n";
            exit(2);               # exit on error
        }

    }
    $filter = join( ' ', @ARGV );
}

# ----------------------------------------------------------------------------- gettasks()
{'fraction_non_alphanumeric': 0.276136487517715, 'fraction_numerical': 0.007413060067589666, 'mean_word_length': 1.900411002213089, 'pattern_counts': {'":': 10, '<': 81, '<?xml version=': 0, '>': 97, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1702957', 'n_tokens_mistral': 2902, 'n_tokens_neox': 2842, 'n_words': 798}