Skip to content

Commit

Permalink
BashSession lexer
Browse files Browse the repository at this point in the history
  • Loading branch information
chalin authored and alecthomas committed Sep 19, 2021
1 parent 4d7154e commit 7259f5b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lexers/b/bashsession.go
Original file line number Diff line number Diff line change
@@ -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 changes: 7 additions & 0 deletions lexers/testdata/bashsession.actual
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
$ echo "Hello, world!"
Hello, world!
% pwd
/User/foo
> make -j build
%ls | wc -l
5
19 changes: 19 additions & 0 deletions lexers/testdata/bashsession.expected
Original file line number Diff line number Diff line change
@@ -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"}
]

0 comments on commit 7259f5b

Please sign in to comment.