1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-03-27 21:49:13 +02:00

BashSession lexer

This commit is contained in:
Patrice Chalin 2021-09-18 21:11:05 -04:00 committed by Alec Thomas
parent 4d7154e8c7
commit 7259f5b254
3 changed files with 53 additions and 0 deletions

27
lexers/b/bashsession.go Normal file
View File

@ -0,0 +1,27 @@
package b
import (
. "github.com/alecthomas/chroma" // nolint
"github.com/alecthomas/chroma/lexers/internal"
)
// BashSession lexer.
var BashSession = internal.Register(MustNewLazyLexer(
&Config{
Name: "BashSession",
Aliases: []string{"bash-session", "console", "shell-session"},
Filenames: []string{".sh-session"},
MimeTypes: []string{"text/x-sh"},
EnsureNL: true,
},
bashsessionRules,
))
func bashsessionRules() Rules {
return Rules{
"root": {
{`(^[#$%>]\s*)(.*\n?)`, ByGroups(GenericPrompt, Using(Bash)), nil},
{`^.+\n?`, GenericOutput, nil},
},
}
}

7
lexers/testdata/bashsession.actual vendored Normal file
View File

@ -0,0 +1,7 @@
$ echo "Hello, world!"
Hello, world!
% pwd
/User/foo
> make -j build
%ls | wc -l
5

19
lexers/testdata/bashsession.expected vendored Normal file
View File

@ -0,0 +1,19 @@
[
{"type":"GenericPrompt","value":"$ "},
{"type":"NameBuiltin","value":"echo"},
{"type":"Text","value":" "},
{"type":"LiteralStringDouble","value":"\"Hello, world!\""},
{"type":"Text","value":"\n"},
{"type":"GenericOutput","value":"Hello, world!\n"},
{"type":"GenericPrompt","value":"%\t"},
{"type":"NameBuiltin","value":"pwd"},
{"type":"Text","value":"\n"},
{"type":"GenericOutput","value":"/User/foo\n"},
{"type":"GenericPrompt","value":"> "},
{"type":"Text","value":"make -j build\n"},
{"type":"GenericPrompt","value":"%"},
{"type":"Text","value":"ls "},
{"type":"Punctuation","value":"|"},
{"type":"Text","value":" wc -l\n"},
{"type":"GenericOutput","value":"5\n"}
]