chroma icon indicating copy to clipboard operation
chroma copied to clipboard

Add console lexer

Open clinta opened this issue 7 years ago • 9 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

clinta avatar Apr 10 '18 16:04 clinta

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

alecthomas avatar Apr 12 '18 11:04 alecthomas

Any schedule?

laowalter avatar Apr 13 '20 00:04 laowalter

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

refparo avatar Feb 05 '21 13:02 refparo

For reference this is the pygments implementation: https://github.com/pygments/pygments/blob/918fced81a57d300042fce413c0d79cfe49d42c0/pygments/lexers/shell.py#L152 https://github.com/pygments/pygments/blob/918fced81a57d300042fce413c0d79cfe49d42c0/pygments/lexers/shell.py#L214

Mic92 avatar Feb 06 '21 12:02 Mic92

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

chalin avatar Sep 19 '21 12:09 chalin

Looks good to me.

Mic92 avatar Sep 19 '21 13:09 Mic92

@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

abey79 avatar Mar 01 '22 13:03 abey79

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 avatar May 10 '22 02:05 nikhilweee

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

theory avatar Jan 17 '24 18:01 theory