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

Add support for more complex command prompts #583

Merged
merged 4 commits into from Dec 20, 2021

Conversation

qtc-de
Copy link
Contributor

@qtc-de qtc-de commented Dec 19, 2021

The bashsession lexer did only recognize command prompts starting with
one of the characters #$%>. This commit adds support for a prefixed
block of the form [.*], which is a common layout for command prompts.

The highlighting could accidentally trigger on text starting with something like [+] $ but I guess this is okay. To make it more restrictive, one could also thing about removing the spaces between the last closing bracket and the special prompt character #$%>. If this is desired, I could change it.

Furthermore, one could also think about changing the highlighting of the command output. The current highlighting for the command output is GenericOutput, which seems to leave the output just in ordinary text color. This makes it hard to distinguish from surrounding text. Maybe it would be better to choose a dedicated highlighting for that, as it is done by GitHub:

[test@test]$ echo 'Hello World'  # echoed text appears in blue
Hello World 

However, I'm not familiar with your default styles and themes and not sure which highlighting option would be the best. If you have a suggestion, just mention it and I will add it to this PR :)

Best regards,
Tobias

The bashsession lexer did only recognized command prompts starting with
one of the characters '#$%>'. This commit adds support for a prefixed
block of the form [.*], which is a common layout for command prompts.
@alecthomas
Copy link
Owner

Can you add a test for this please? See lexers/README for details.

@alecthomas
Copy link
Owner

The command output is highlighted by the bash lexer. eg. if you use $ echo "hello world" you will see the quoted string highlighted. Any improvements should go into that lexer.

To avoid false positives, the regex to detect a command prompt was made
more restrictive. It now enforces an '@' character within a [...] block
and only allows one optional space before the prompt special character.
Leading spaces within a command were simply ignored by the bashsession
lexer. This is now changed and the spaces are assigned to the Text
group.
Added a few test cases to test the detection of [...] blocks in front of
command prompts.
@alecthomas
Copy link
Owner

Sorry I misread, I see you were referring to output. It's up to the theme what to do with the tokens and I think GenericOutput is pretty accurate. You should be able to override it in CSS if you wish.

@alecthomas alecthomas merged commit ac2891f into alecthomas:master Dec 20, 2021
@alecthomas
Copy link
Owner

Thanks!

@qtc-de
Copy link
Contributor Author

qtc-de commented Dec 20, 2021

Added test cases as requested.

Concerning the highlighting of the command output: I actually mean the output of the command, not the command itself (e.g. just the Hello World in the second line. However, I noticed that my assumption was wrong here. The GenericOutput group seems to be implemented exactly for this case. The problem was that my selected theme did not add a special color for it.

Is there any reason why certain themes do not add colors to specific syntax groups? Would it make sense to add a default color in these themes or is that not desired?

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.

None yet

2 participants