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-codes opened this Issue Nov 25, 2014 · 8 comments

Comments

Projects
None yet
3 participants
@geoff-codes
Contributor

geoff-codes 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

This comment has been minimized.

Show comment
Hide comment
@zanchey

zanchey Nov 25, 2014

Member

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

Member

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-codes

This comment has been minimized.

Show comment
Hide comment
@geoff-codes

geoff-codes Nov 25, 2014

Contributor

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.

Contributor

geoff-codes 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-codes geoff-codes changed the title from Help: Print natively syntax-highlighted code to stdout? (feature request?) to Feature Request: Print natively syntax-highlighted code to stdout. Nov 25, 2014

@ridiculousfish

This comment has been minimized.

Show comment
Hide comment
@ridiculousfish

ridiculousfish Dec 24, 2014

Member

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

Member

ridiculousfish commented Dec 24, 2014

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

@geoff-codes

This comment has been minimized.

Show comment
Hide comment
@geoff-codes

geoff-codes Dec 24, 2014

Contributor

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>.)

Contributor

geoff-codes 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

This comment has been minimized.

Show comment
Hide comment
@ridiculousfish

ridiculousfish Dec 24, 2014

Member

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

Member

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

@ridiculousfish

This comment has been minimized.

Show comment
Hide comment
@ridiculousfish

ridiculousfish Dec 24, 2014

Member

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

Member

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

This comment has been minimized.

Show comment
Hide comment
@zanchey

zanchey Dec 28, 2014

Member

Closing as now implemented. Hooray!

Member

zanchey commented Dec 28, 2014

Closing as now implemented. Hooray!

@zanchey zanchey closed this Dec 28, 2014

@geoff-codes

This comment has been minimized.

Show comment
Hide comment
@geoff-codes

geoff-codes Jan 14, 2015

Contributor

Forgot to say thanks for this!

Contributor

geoff-codes commented Jan 14, 2015

Forgot to say thanks for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment