Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Alad Wenter
aurutils
Commits
ff6c24e4
Commit
ff6c24e4
authored
May 26, 2022
by
Alad Wenter
Browse files
WIP: aur-search--format
parent
fb4a0890
Changes
1
Hide whitespace changes
Inline
Side-by-side
lib/aur-search--format
View file @
ff6c24e4
...
...
@@ -14,6 +14,8 @@ if (exists($ENV{AUR_DEBUG})) {
}
use
Term::
ANSIColor
qw(:constants)
;
use
Data::
Dumper
;
# date formatting
use
POSIX
qw(strftime locale_h)
;
setlocale
(
LC_NUMERIC
,
"
C
");
...
...
@@ -98,14 +100,15 @@ def sel_join:
EOF
my
@g_jq
=
('
jq
',
'
-r
',
'
--arg
',
'
key
',
$opt_key
,
'
--arg
',
'
delim
',
$opt_delim
,
$g_jq_tsv
);
# Recover the labels so that handlers can operate on an array,
# instead of a tsv row with an assumed ordering.
my
@g_jq_labels
=
$g_jq_tsv
=~
/\.((?:[A-Z]{1}[a-z]+)+)/g
;
# Recover the labels so that handlers can operate on an array, instead of a tsv
# row with an assumed ordering.
# XXX: use a less fragile way than a regular expression
my
@g_jq_labels
=
$g_jq_tsv
=~
/\.([A-Z]{1}[A-z]+)/g
;
# subroutines
sub
info_short
(\%$)
{
sub
info_short
{
my
%pkg
=
%
{
$_
[
0
]};
my
$ood
;
my
$ood
=
""
;
if
(
length
(
$pkg
{'
OutOfDate
'}))
{
$ood
=
strftime
("
%d %B %Y
",
gmtime
(
$pkg
{'
OutOfDate
'}));
...
...
@@ -120,7 +123,7 @@ sub info_short(\%$) {
say
("
",
$pkg
{'
Description
'});
}
sub
info_long
(\%$)
{
sub
info_long
{
my
%pkg
=
%
{
$_
[
0
]};
my
$count
=
$_
[
1
];
...
...
@@ -130,34 +133,35 @@ sub info_long(\%$) {
my
$label_url
=
sprintf
("
%-14s
",
"
AUR URL:
");
say
(
BOLD
,
$label_url
,
RESET
,
"
\t
",
$aur_location
.
"
/packages/
"
.
$pkg
{'
Name
'},
RESET
);
for
(
0
..
$#g_jq_labels
)
{
my
$label
=
$g_jq_labels
[
$
_
];
for
my
$i
(
0
..
$#g_jq_labels
)
{
my
$label
=
$g_jq_labels
[
$
i
];
my
$label_fmt
=
sprintf
("
%-14s
",
$label
.
"
:
");
my
$value_fmt
=
length
(
$pkg
{
$label
})
?
$pkg
{
$label
}
:
"
None
";
my
$value_fmt
=
length
(
$pkg
{
$label
})
?
$pkg
{
$label
}
:
"
-
";
say
(
BOLD
,
$label_fmt
,
RESET
,
"
\t
",
$value_fmt
);
}
}
sub
info_format
(\%$)
{
sub
info_format
{
my
%pkg
=
%
{
$_
[
0
]};
length
(
$opt_format
)
or
die
$argv0
.
'
: empty format specified
';
my
@tokens
=
split
('
%
',
$opt_format
);
# omit trailing empty fields
shift
@tokens
;
# split("%a%b") -> ("", 'a', 'b')
my
@tokens
=
split
('
%
',
$opt_format
);
# omit trailing empty fields
my
$prefix
=
$tokens
[
0
];
# split("%a%b") -> ("", 'a', 'b')
shift
@tokens
;
print
Dumper
(
\
@tokens
);
# Expand tokens to AUR data
# TODO: support color constants? (or use default colors for fields, cf. package-query)
my
@fmt
;
for
(
0
..
$#tokens
)
{
my
$token
=
$tokens
[
$
_
];
for
my
$i
(
0
..
$#tokens
)
{
my
$token
=
$tokens
[
$
i
];
if
(
length
(
$token
))
{
# Expand first character, preserve the rest
my
$token_1
=
substr
(
$token
,
0
,
1
);
if
(
$token_1
eq
'
G
')
{
$fmt
[
$
_
]
=
$aur_location
.
"
/
"
.
$pkg
{'
Name
'}
.
"
.git
";
$fmt
[
$
i
]
=
$aur_location
.
"
/
"
.
$pkg
{'
Name
'}
.
"
.git
";
}
else
{
my
$label
=
$g_formats
{
$token_1
};
length
(
$label
)
or
die
$argv0
.
'
: invalid format key specified
';
...
...
@@ -165,13 +169,14 @@ sub info_format(\%$) {
if
(
$opt_verbose
and
$pkg
{
$label
}
eq
"")
{
$pkg
{
$label
}
=
"
None
";
}
$fmt
[
$
_
]
=
$pkg
{
$label
}
.
substr
(
$token
,
1
);
$fmt
[
$
i
]
=
$pkg
{
$label
}
.
substr
(
$token
,
1
);
}
}
else
{
$fmt
[
$
_
]
=
"
%
";
$fmt
[
$
i
]
=
"
%
";
}
}
my
$fmt_string
=
join
('',
@fmt
);
my
$fmt_string
=
join
('',
$prefix
,
@fmt
);
print
Dumper
(
$fmt_string
);
print
(
$fmt_string
);
# interpolates escape sequences
}
...
...
@@ -190,7 +195,7 @@ sub from_json {
@aur_map
{
@g_jq_labels
}
=
split
('
\t
',
$row
,
scalar
(
@g_jq_labels
));
# Hashes do not preserve order, so pass on the labels as well
$handler
->
(
%aur_map
,
$count
);
$handler
->
(
\
%aur_map
,
$count
);
$count
++
;
}
waitpid
$child_pid
,
0
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment