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

feat(scoop-cat): Use bat to pretty-print JSON #4742

Merged
merged 7 commits into from
Feb 17, 2022
Merged

feat(scoop-cat): Use bat to pretty-print JSON #4742

merged 7 commits into from
Feb 17, 2022

Conversation

rashil2000
Copy link
Member

@rashil2000 rashil2000 commented Feb 16, 2022

Description

Silly new feature of scoop-cat 🤣

Motivation and Context

Your manifest looks cute now xD

How Has This Been Tested?

Before

image

After

image

Checklist:

  • I have read the Contributing Guide.
  • I have updated the documentation accordingly.
  • I have updated the tests accordingly.

@niheaven
Copy link
Member

Since 'bat' is somehow slower, use config option such as CAT_USE_BAT or VIEW_USE_BAT to determine whether using bat even if existed.

Add bat option --style=grid,numbers to not show STDIN file name. (Have you set BAT_STYLE?)

image

@rashil2000
Copy link
Member Author

rashil2000 commented Feb 17, 2022

Since 'bat' is somehow slower,

Will it really matter? We just show one json file at a time, which is hardly 2-3KB (in worst case)

use config option such as CAT_USE_BAT or VIEW_USE_BAT to determine whether using bat even if existed.

I can't find any docs on them. How to use them?

Add bat option --style=grid,numbers to not show STDIN file name. (Have you set BAT_STYLE?)

Haha yes, I forgot that I had a bat config file.
Will fix.
(I will use the -pp option to keep it visually similar to how it was before.)

@niheaven
Copy link
Member

niheaven commented Feb 17, 2022

If it looks the same, why use bat? line numbers and grid line are pretty 😄 , but yes, highlighting is the most wonderful one and existed. (Hmm, why your terminal doesn't show color? BAT_STYLE?)

image

For the speed, in my PC (i5-8500/32G), bat is slower 20x-30x, i.e., direct output take milliseconds while bat take seconds.

I can't find any docs on them. How to use them?

I mean add new config option to switch the background scoop cat uses, i.e., check the config is TRUE and bat existed, while the config's default is FALSE.

@rashil2000
Copy link
Member Author

If it looks the same, why use bat? line numbers and grid line are pretty 😄 , but yes, highlighting is the most wonderful one and existed. (Hmm, why your terminal doesn't show color? BAT_STYLE?)

Grid lines and splits are useful for git output and multiple files. I suppose line numbers are useful, but I don't like them personally.

My terminal is showing colors (notice the escaped backslashes). I'm using --theme=ansi (because it works in both light and dark terminals).

For the speed, in my PC (i5-8500/32G), bat is slower 20x-30x, i.e., direct output take milliseconds while bat take seconds.

I mean add new config option to switch the background scoop cat uses, i.e., check the config is TRUE and bat existed, while the config's default is FALSE.

I think I have a genius solution to both these problems: a config variable called cat_style. The value of this variable can be:

  • empty: in this case bat will not be used.
  • not empty: if set to any of the supported bat styles (see below), it will use bat and pass this value as --style.

image

How does that sound?

@niheaven
Copy link
Member

And bat should be installed if cat_style is set.

BTW, it should be named CAT_STYLE, cat_style or cat-style? The scoop option names now are a bit messy.

@rashil2000
Copy link
Member Author

And bat should be installed if cat_style is set.

I'm not sure if we should do this automatically. What if the user doesn't have internet, and just wants to see local manifests? Downloading something for a local functionality seems bad. We can just detect if doesn't exist and use the normal Write-Output in that case.

BTW, it should be named CAT_STYLE, cat_style or cat-style? The scoop option names now are a bit messy.

To stick with a convention, I think we should use small case and underscores from now on.

@niheaven
Copy link
Member

Just like aria2, there're two choices. One for automatic enable bat unless explicit disabled, while another disable bat by default and user could enable it.

For the ones that don't have Internet access, why they want to set cat_style? Make notes for this option that it needs Internet.

Treat it just as existed ones, e.g., aria2 and lessmsi. The former is enabled by default, while the latter is enabled by option.

@rashil2000
Copy link
Member Author

aria2 and lessmsi are used for downloading and installing apps, which automatically needs internet connection.

I'm against the idea of making an offline functionality require being "online" (even if it's just one time setup).

In the config, I will mention that bat is mandatory if the bat_style option is set (I will also mention in the docs that This option requires bat. Do 'scoop install bat' to install it. We also show a similar message for 'sudo' during scoop-checkup.)

@niheaven
Copy link
Member

Okay, that works fine. Besides, if user has bat installed, it should be enabled by default or manually? i.e., the option should be an enable one (lessmsi) or disable one (aria2)?

@rashil2000
Copy link
Member Author

I was initially going for enabled by default, but as you mentioned that bat might be slow on some PCs, we should make it manually enabled.

@niheaven
Copy link
Member

Okay, please make changes and I'll review again.

@rashil2000
Copy link
Member Author

Done

@niheaven
Copy link
Member

Hmm, could you please separate config underscores to another PR?

@rashil2000
Copy link
Member Author

Okay sure

This reverts commit 46524fc.
lib/install.ps1 Outdated Show resolved Hide resolved
lib/install.ps1 Outdated Show resolved Hide resolved
libexec/scoop-cat.ps1 Outdated Show resolved Hide resolved
Co-authored-by: Hsiao-nan Cheung <niheaven@gmail.com>
@rashil2000 rashil2000 merged commit e1f569b into develop Feb 17, 2022
@rashil2000 rashil2000 deleted the bat-json branch February 17, 2022 17:27
se35710 pushed a commit to se35710/scoop that referenced this pull request Mar 8, 2022
* feat(scoop-cat): Use `bat` to pretty-print JSON

* update changelog

* hide filename and line numbers

* Add `cat_style` config option

* use underscores

* Revert "use underscores"

This reverts commit 46524fc.

* Apply suggestions from code review

Co-authored-by: Hsiao-nan Cheung <niheaven@gmail.com>

Co-authored-by: Hsiao-nan Cheung <niheaven@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants