alecthomas / chroma

A general purpose syntax highlighter in pure Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add console lexer

clinta opened this issue · comments

It looks like the shell session lexers are a bit more difficult than using pygments2chroma, but these lexers are very nice for writing tutorials with example shell commands, especially BashSessionLexer.

Example of the difference:

console

$ sudo su
# echo "foo"
foo

bash

$ sudo su
# echo "foo"
foo

Sounds good. This should be relatively straightforward, though may require a tiny bit of refactoring. I'd happily accept PRs.

Any schedule?

commented

Also doscon tcshcon ps1con as is supported by Pygments (documents).

@clinta, @alecthomas et al.: #551 offers a basic bash-session lexer, possibly good enough to consider this issue closed?

Looks good to me.

@chalin though it's a start, it appears that this simple lexer requires the $ to be at the beginning of the line. This precludes scenario like:

~/src $ cd my_project
~/src/my_project $ source venv/bin/activate
(venv) ~/src/my_project $ python setup.py install

Another use case that comes to mind is anything related to git, where showing the current branch in the prompt would be very useful for examples/tutorial material.

Edit: another aspect that isn't covered at all by the current lexer is multi-line commands:

$ echo This is a very long \
    command that wont fit \
    on a single line

I'm also wondering if there is a better way to differentiate between the root prompt and a comment? For now I have settled to appending a $ before a comment.

$ # regular user
$ sudo su
$ # superuser
# exit

@nikhilweee From #551, the prompt regex is ^[#$%>], so it looks like you can use #.

I tried the console parser in Hugo and it worked, although I had to manually add the .gp (GenericPrompt) CSS selector to style the prompt. hugo gen chromastyles didn't emit it.