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

Feature Request: Print natively syntax-highlighted code to stdout. #1827

Closed
geoff-nixon opened this issue Nov 25, 2014 · 8 comments
Closed

Feature Request: Print natively syntax-highlighted code to stdout. #1827

geoff-nixon opened this issue Nov 25, 2014 · 8 comments
Labels
Milestone

Comments

@geoff-nixon
Copy link
Contributor

@geoff-nixon geoff-nixon commented Nov 25, 2014

I feel like there must already be a way to do this, but I just can't figure it out.

What I'd like to do is have a function, lets call it, um, catfish, which will print an arbitrary snippet of syntax-highlighted fish code (from file, or from stdin) to stdout, escape-sequences and all, so that if I redirect it to file and later cat file, it will be syntax-highlighted. (If you have pygments installed, this is basically the exact same functionality as pygmentize -g [-f 256], but for fish syntax, of course.)

I know there's functionality close to this already — commandline (cat script.fish), funced — but for my life I can't figure out how to trick it into redirecting to a fd or file.

Is this possible?

@zanchey
Copy link
Member

@zanchey zanchey commented Nov 25, 2014

I don't think there's a way of doing this at present. It would be good to teach fish_indent how to colorise.

@zanchey zanchey added the enhancement label Nov 25, 2014
@zanchey zanchey added this to the fish-future milestone Nov 25, 2014
@geoff-nixon
Copy link
Contributor Author

@geoff-nixon geoff-nixon commented Nov 25, 2014

It would be good to teach fish_indent how to colorize.

Yeah, I thought of that as well.

I think #1812 shows I'm not the only one who'd like to have their fish scripts syntax highlighted outside the interactive shell.

@geoff-nixon geoff-nixon changed the title Help: Print natively syntax-highlighted code to stdout? (feature request?) Feature Request: Print natively syntax-highlighted code to stdout. Nov 25, 2014
@ridiculousfish
Copy link
Member

@ridiculousfish ridiculousfish commented Dec 24, 2014

fish_indent can colorize with the changes in 8ba0ab2 . fish_indent --ansi < script.fish

@geoff-nixon
Copy link
Contributor Author

@geoff-nixon geoff-nixon commented Dec 24, 2014

Thanks for doing this @ridiculousfish! Three things:

  1. fish_indent --ansi < fish_indent.fish Just gives me
    Assertion failed: (type == type_rgb), function to_term256_index, file color.cpp, line 300.
    I'm using iTerm2 (latest/nightly). Solarized theme.
    Declares xterm-256color. Nothing too special, I don't think?

  2. I tried to drill down into color.cpp, and didn't spot an easily identifiable bug, but i did notice:
    color24_t rgb_color_t::to_color24() ...

    Does fish support 24-bit color!? I actually use the 24-bit color functionality of iTerm2 a lot in a couple of projects, since its so easy to map to CSS RGB color schemes. (\x1b[38:2:255:255:255m \x1b[48:2:0:0:0m), etc.

  3. And speaking of CSS, is there a full list of classes used, so I can create a stylesheet for --html? (Which does work for fine me, although myself I'd probably make it <pre><code> ... </code></pre>.)

@ridiculousfish
Copy link
Member

@ridiculousfish ridiculousfish commented Dec 24, 2014

The assertion failure should be fixed as 77a7dd8 - thanks for reporting it.

Yes, fish has some experimental support for 24-bit color, in the style used by iTerm2 and Konsole, as of b8181f9. Unfortunately there's no good way to check if the term supports it, so it's off by default for now. You can enable it by setting the variable fish_term24bit to 1.

The CSS class names for colors are the same as the variable names, e.g. fish_color_comment

ridiculousfish added a commit that referenced this issue Dec 24, 2014
As suggested in #1827
@ridiculousfish
Copy link
Member

@ridiculousfish ridiculousfish commented Dec 24, 2014

e5a2343 switches to <pre><code> as you suggested.

@zanchey zanchey modified the milestones: next-minor, fish-future Dec 28, 2014
@zanchey
Copy link
Member

@zanchey zanchey commented Dec 28, 2014

Closing as now implemented. Hooray!

@zanchey zanchey closed this Dec 28, 2014
@geoff-nixon
Copy link
Contributor Author

@geoff-nixon geoff-nixon commented Jan 14, 2015

Forgot to say thanks for this!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.