Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If/else to case in preview-tui #1009

Merged
merged 2 commits into from
May 14, 2021
Merged

If/else to case in preview-tui #1009

merged 2 commits into from
May 14, 2021

Conversation

luukvbaal
Copy link
Collaborator

Replace if/else clauses with case block in view of optimizations mentioned in #935 (comment). Should maintain exactly the same logic as previously.

I'm not sure how I feel about maintaining preview-tui in the future though. If it were up to me I would just rename preview-tui-ext to preview-tui and let users edit that how they see fit instead of extending the more minimal preview-tui. The extended script works fine without the optional dependencies installed.

Copy link
Collaborator Author

@luukvbaal luukvbaal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leovilok please review if you can

Edit: I'm mostly just looking for other opinions on whether this is actually an improvement over the old code, and comments on the specifics of the implementation. @jarun what do you think since you're the one who initially requested the review. I saw no other problems in preview-tui beside the abundant if/else clauses. To me it is more readable and potentially more performant though that would be hard to verify.

@@ -355,7 +351,8 @@ generate_preview() {
image_preview() {
clear
if [ "$TERMINAL" = "kitty" ]; then
# Kitty terminal users can use the native image preview method.
# Kitty terminal users can use the native image preview method although one might consider
# installing ueberzug and moving the ueberzug clause to the top since it performs alot better.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add note about kitty vs ueberzug performance consideration

else
fifo_pager pager "$1"
fi
handle_mime "$1" "$mimetype" "$ext" "bin"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass "bin" as argument to handle_mime() to maintain the if [ "${encoding#*)}" = "binary" ] condition.

else
fifo_pager pager "$1"
fi ;;
*) handle_ext "$1" "$3" "$4" ;;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If no mimetype matches, check extensions

fifo_pager pager "$1"
fi ;;
pdf) generate_preview "$cols" "$lines" "$1" "pdf" ;;
*) if [ "$3" = "bin" ]; then
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print_bin_info() or pager depending on whether or not we came from if [ "${encoding#*)}" = "binary" ]

@Kabouik
Copy link
Collaborator

Kabouik commented May 14, 2021

Thanks for picking that up @luukvbaal. Seeing how a simple change like 1004 can be hectic if I'm the one doing it, I'm glad you stepped forward!

I feel the same about preview-tui. I know its merits are it's simpler than preview-tui-ext, but we're talking about 11.3 and 17.2 KB files, respectively, and a single 17.2 KB file is lighter than the two combined. Also, of course users should only customize the one they intend to use, but I feel uneasy editing preview-tui-ext to my liking and leaving preview-tui out of sync, so I end up patching both for no reason even when there's no PR planned.

@Kabouik
Copy link
Collaborator

Kabouik commented May 14, 2021

Unless I am missing some magic Github feature that would automatically merge, those two preview-tui* plugins are pre-#1004 (i.e., bat changes), are they not?

@luukvbaal
Copy link
Collaborator Author

Correct, I was working pre-#1004. It will merge fine since there are no merge conflicts, I'll rebase though.

@Kabouik
Copy link
Collaborator

Kabouik commented May 14, 2021

Correct, I was working pre-#1004. It will merge fine since there are no merge conflicts, I'll rebase though.

Since #1008 is rather small, maybe take that into account at the same time and scrap #1008 before it's merged?

@luukvbaal
Copy link
Collaborator Author

As you want, if you close it I'll add it here

@Kabouik
Copy link
Collaborator

Kabouik commented May 14, 2021

Thanks!

@jarun jarun merged commit bb37c9d into jarun:master May 14, 2021
@jarun
Copy link
Owner

jarun commented May 14, 2021

Thank you!

@luukvbaal
Copy link
Collaborator Author

I'm not sure how I feel about maintaining preview-tui in the future though. If it were up to me I would just rename preview-tui-ext to preview-tui and let users edit that how they see fit instead of extending the more minimal preview-tui. The extended script works fine without the optional dependencies installed.

@jarun thoughs on this?

@jarun
Copy link
Owner

jarun commented May 14, 2021

After the next release.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants