Closed Darukutsu closed 1 year ago
Hmm, Well there is a bit of history in regards to this actually. See issue #9 The workaround was to specify to trackma how big the output has to be; in watching cases is this line: https://github.com/RaitaroH/adl/blob/4e95346fbc215af40b68b81652685b6b321e79ab/adl#L191
So if I remove the LINES and COLUMNS I get the trackma default, which can still be too wide. As such the COLUMN has to be changed manually, but you see... then it looks kinda cramped on bigger terminal sizes. For simplicity I can suggest to you to simply change the COLUMNS value to fit your needs.
I like your approach to change how the output looks like in the first place, though this will also require changes in other places like process_list, frece, and exception checking (some anime have . at the end of their names). If you are capable, please make a PR; I might look into this as well.
So you know, I have opened an issue on trackma side: https://github.com/z411/trackma/issues/660 I don't know python to be able to make a PR for trackma itself, which would solve the exception issue.
Well, this is weird when we do something like this in terminal, output will be formatted:
but redirecting output, piping it etc. will break formatting:
This is certainly problem of some python code in trackma.
Anyway, I was thinking about some solutions and possibly we could do:
tlist=$(LINES=25 COLUMNS=$(tput cols) trackma -a "$account" list | head -n -2 | tail -n +2)
this will work in cases when name isn't cut (red ones):
A workaround could be using arrays instead of variable to store values. For example, formatted array with tput will be printed and then search will be provided with "$arr2[n]" in watch()
. I will try something, if it works, I open PR.
Most certainly the tput cols
option does not work. The name is truncated not just in fzf, but overall. As such streams and especially local folders will not work properly.
I am not opposed to the idea of processing the trackma output before sending in to fzf as in your previous example. If we do this then the process_list function has to change. So it will be more like:
entry="$(echo "$tlist" | process_list | fzf_select)"
or even
entry="$(echo "$tlist" | pre_process_list | fzf_select | post_process_list)"
Like in your example. Just that in this case process_list simply has to change.
entry="$(echo "$tlist" | sed 's#\(\. \+[0-9]\+ / [0-9]\+ \+[0-9]\+\)\|\.\||##g' | fzf_select | process_list)"
This processing should also take in consideration the exceptions array.
Alternatively we could take inspiration from this: https://github.com/justchokingaround/trackma-wrapper. In this case he is using this function, which we just need the index from trackma. This also solves my exceptions workaround:
trackma -a 1 info "1" | head -n1
Initially I was against this as trackma can be rather slow in my experience. Not sure why, maybe python. Pre-caching the info also kinda doesn't work on larger lists, as the initial creation will be very very slow.
I personally think a combination of this 2 things can be the solution to this issue. Also yeah, I am very aware of the weirdness when | or > or tee-ing the output.
What do you think about output? I tried Hige Wo Soru... it's playing
process_list() {
#perl -pe 's/\x1b\[[0-9;]*m//g ; s/^.+?[^\s]\s+(.+?(?=\.\.))\.+\ +(\d+).[^\d]\ (\d+|\?)\s+(\d*[.]?\d+).+$/\1|\2|\3|\4|/g'
perl -pe 's/^.+? +(\d+) \/ (\d+) +(\d) +(.*)/\4|\1|\2|\3|/g'
}
...
pre_process_list() {
# not sure if use \d or [[:digit:]] or [0-9] POSIX reasons...
# https://unix.stackexchange.com/a/414230/482125
# or maybe switch to perl since this piping is one big mess
#@1
sed 's#^\(| \+\)#@#' |\
# move end stats after @1 but before name
sed 's#\(@.*\.\)\(\. \+[0-9]\+ / [0-9]\+ \+ [0-9]\+\)#\2\1#' |\
sed 's#\(.*\)\(@[0-9]\+\)#\2\1#' |\
# remove excess dots and pipes
sed 's#\.\||##g'
}
...
entry="$(echo "$tlist" | pre_process_list | fzf_select | process_list)"
...
It will need some stylish changes, I forget about multiple digit entries.
sorry for multiple edits... i have habbit to do ctrl+enter for new line.
I will have to test this for things such as:
As per your last comment, it fails decimal scores, ? number of last episodes too: I will look into this
I have a much better idea.
The process_list
function I wrote is already good enough, and prints output like so:
Blue Lock|12|24|5.5|
Flying Witch|0|12|0|
Isekai Oji-san|12|13|6.5|
Love Live! School idol project|5|13|0|
Mairimashita! Iruma-kun 3|12|21|5|
Meitantei Conan|1067|?|7.5|
Musekinin Kanchou Tylor|12|26|7.5|
As such I can do something like this (keep color) with awk:
$ cat /tmp/trackma | perl -pe 's/^.+?[^\s]\s+(.+?(?=\.\.))\.+\ +(\d+).[^\d]\ (\d+|\?)\s+(\d*[.]?\d+).+$/\1|\2|\3|\4|/g' | awk -F'|' '{print "@" NR-1 " - " $2" / "$3 " - " $4 " - " $1}'
@0 - 12 / 24 - 5.5 - Blue Lock
@1 - 0 / 12 - 0 - Flying Witch
@2 - 12 / 13 - 6.5 - Isekai Oji-san
@3 - 5 / 13 - 0 - Love Live! School idol project
@4 - 12 / 21 - 5 - Mairimashita! Iruma-kun 3
@5 - 1067 / ? - 7.5 - Meitantei Conan
@6 - 12 / 26 - 7.5 - Musekinin Kanchou Tylor
I just need to use printf align with awk
Consider the following:
trackma -a 1 list | head -n -2 | tail -n +2 >> /tmp/trackma
Then:
cat /tmp/trackma | perl -pe 's/^.+?[^\s]\s+(.+?(?=\.\.))\.+\ +(\d+).[^\d]\ (\d+|\?)\s+(\d*[.]?\d+).+$/\1|\2|\3|\4|/g' | awk -F'|' '{printf "@%s",NR-1} {printf "%8s - %-5s",$2,$3} {printf " %-6s %s\n",$4,$1}'
Consider the following:
trackma -a 1 list | head -n -2 | tail -n +2 >> /tmp/trackma
Then:
cat /tmp/trackma | perl -pe 's/^.+?[^\s]\s+(.+?(?=\.\.))\.+\ +(\d+).[^\d]\ (\d+|\?)\s+(\d*[.]?\d+).+$/\1|\2|\3|\4|/g' | awk -F'|' '{printf "@%s",NR-1} {printf "%8s - %-5s",$2,$3} {printf " %-6s %s\n",$4,$1}'
Your perl is broking some of the entries, my tmp/trackma:
Ah yes, that isn't my perl regex, but instead the trackma output getting cutoff. I am working right now on a different branch you can test.
echo -e "filter completed\nlist\nexit" | COLUMNS=250 trackma | sed -n '/[[:space:]].1/,${p;/results/q}' | head -n -1 >> /tmp/trackma && cat /tmp/trackma | perl -pe 's/^.+?[^\s]\s+(.+?(?=\.\.))\.+\ +(\d+).[^\d]\ (\d+|\?)\s+(\d*[.]?\d+).+$/\1|\2|\3|\4|/g' | awk -F'|' '{printf "@%s",NR} {printf "%8s - %-5s",$2,$3} {printf " %-6s %s\n",$4,$1}'
Try using COLUMNS. Why indexing from 0 when can from 1?
Yeah the NR-1 was just a copy paste. Don't worry I have fixed it. And yeah, the COLUMNS has to be increased.
@Darukutsu test this new branch.
I have played around with awk with BEGIN {printf "%s %6s %9s %6s\n", "Index", "Count", "Score", "Title"}
but I think that fzf prompt actually looks better.
Does work on pretty small size, but you know, the choices and animdl outputs can be an issue:
As my code needs the ||||
format I decided to just do this:
process_list() {
perl -pe "s/\x1b\[[0-9;]*m//g ; s/${regex}/g"
}
fzf_process_list() {
perl -pe "s/${regex}/g" |\
awk -F'|' '{printf "%-2s",NR} {printf "%6s - %-5s",$2,$3} {printf " %-6s %s\n",$4,$1}'
# print columns in the format INDEX CURRENT - LAST SCORE TITLE with proper padding
}
get_entry() {
debug_print "get_entry()"
fzf_selection="$(echo "$tlist" | fzf_process_list | fzf_select )"
# now get the line number from selection
line_nr=$(echo "$fzf_selection" | awk '{print $1}')
# find the entry from tlist that has that number so we have the expected |||| format
entry="$(echo "$tlist" | sed -n "$line_nr p" | process_list)"
present=""
debug_print_vars "fzf_selection" "line_nr" "entry"
}
Basically after you pick something, I am going through trackma output again (tlist) find the corresponding index line and process it as before.
adl -c
now don't display pictures.
After pressing ESC
first episode is selected + there is no option to switch list now (apart from adl -q query
).
I fixed the ESC
thing.
For adl -c
I forgot to modify this regex:
https://github.com/RaitaroH/adl/blob/d94ed157e0e41508f3c7bc05a639ce24dc159df4/adl#L251
Considering a format like so it has to print just the titles
1083 1067 - 2000 10.5 Meitantei Conan
1084 12 - 26 7.5 Musekinin Kanchou Tylor
I have fixed the issues.
I think adl -c
should be fine now. I cannot properly test as I don't have ueberzug installed on this machine.
I will keep that branch unmerged for now.
I like your changes. Seems that everything is working.
Also, I would do instead of this https://github.com/RaitaroH/adl/blob/21417a9638c686b2b07c723bd105cd626c2fb49e/adl#L213 this
awk -F'|' '{printf "%-4s",NR} {printf "%6s - %-5s",$2,$3} {printf " %-6s %s\n",$4,$1}'
The query changing seems to have been broken from before. Fixed now.
Does the awk change look better in your opinion? Or you have another reason?
Just space indentation:
I was about to send that you forget
watch_another "$ans_loop"
and then reference $1
:D but you fixed it already
The script has become rather complex so even I forget some functions 😅
On my end '%-2s' looks better than 4, maybe because I have scores with .5
(note that I have not adjusted the prompt spacing)
Anyhow, I will close this issue for now. If you find anything broken please reopen. I will keep the branch unmerged for now.
On my end '%-2s' looks better than 4, maybe because I have scores with .5
(note that I have not adjusted the prompt spacing)
This is not problem until 3 digit numbers appear and then indentation is off:
I will make the change.
@Baitinq if you like test this new branch.
When having smaller sizes of terminal, output is not properly displayed due to its length. Maybe getting rid of excess dots or switching position of elements...
I didn't read through the whole code, this will break scraping.
Some of the ideas:
Or maybe come with other solutions since
trackma
is displaying list correctly with any sizes:I don't think it's important at all. I personally like trackma style.