pygments-shell-console 0.0.6__tar.gz → 0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pygments_shell_console-0.2/PKG-INFO +27 -0
- pygments_shell_console-0.2/README.md +21 -0
- pygments_shell_console-0.2/examples/git_lg.example +3 -0
- pygments_shell_console-0.2/examples/git_log.example +12 -0
- pygments_shell_console-0.2/examples/git_show.example +16 -0
- {pygments_shell_console-0.0.6 → pygments_shell_console-0.2}/examples/status.example +1 -0
- {pygments_shell_console-0.0.6 → pygments_shell_console-0.2}/git_lexer.py +50 -11
- {pygments_shell_console-0.0.6 → pygments_shell_console-0.2}/pyproject.toml +1 -1
- {pygments_shell_console-0.0.6 → pygments_shell_console-0.2}/shellconsole_lexer.py +14 -4
- {pygments_shell_console-0.0.6 → pygments_shell_console-0.2}/shellconsole_style.py +1 -0
- pygments_shell_console-0.2/test/test_git.py +39 -0
- pygments_shell_console-0.2/test/test_git_branch.py +35 -0
- pygments_shell_console-0.2/test/test_git_log.py +64 -0
- pygments_shell_console-0.0.6/test/test_git_log.py → pygments_shell_console-0.2/test/test_git_pretty_log.py +58 -1
- {pygments_shell_console-0.0.6 → pygments_shell_console-0.2}/test/test_git_status.py +26 -0
- pygments_shell_console-0.0.6/PKG-INFO +0 -15
- pygments_shell_console-0.0.6/README.md +0 -9
- {pygments_shell_console-0.0.6 → pygments_shell_console-0.2}/.github/workflows/publish-to-pypi.yml +0 -0
- {pygments_shell_console-0.0.6 → pygments_shell_console-0.2}/.gitignore +0 -0
- {pygments_shell_console-0.0.6 → pygments_shell_console-0.2}/examples/test.exmpl +0 -0
- {pygments_shell_console-0.0.6 → pygments_shell_console-0.2}/examples/test.sh +0 -0
- {pygments_shell_console-0.0.6 → pygments_shell_console-0.2}/test/__init__.py +0 -0
- {pygments_shell_console-0.0.6 → pygments_shell_console-0.2}/test/test_git_show.py +0 -0
- {pygments_shell_console-0.0.6 → pygments_shell_console-0.2}/test/test_prompts.py +0 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: pygments-shell-console
|
|
3
|
+
Version: 0.2
|
|
4
|
+
Requires-Dist: pygments
|
|
5
|
+
Description-Content-Type: text/markdown
|
|
6
|
+
|
|
7
|
+
# Pygments Shell Console
|
|
8
|
+

|
|
9
|
+
[](https://pypi.org/project/pygments-shell-console/)
|
|
10
|
+
|
|
11
|
+
This Pygments plugin adds new lexers for `shellconsole` output.
|
|
12
|
+
|
|
13
|
+
The lexers are:
|
|
14
|
+
- `ShellConsoleLexer`: Based in [`ShellSessionBaseLexer`](https://github.com/pygments/pygments/blob/master/pygments/lexers/shell.py#L151C7-L151C28),
|
|
15
|
+
extends its behavior to recognize the prompt elements and highlight them.
|
|
16
|
+
|
|
17
|
+
Also, it adds support for highlighting the following commands output:
|
|
18
|
+
- Uses `DiffLexer` to highlight `diff` and `git diff` output.
|
|
19
|
+
- `GitStatusLexer`: Adds support for highlighting `git status` output.
|
|
20
|
+
- `GitShowLexer`: Adds support for highlighting `git show` output.
|
|
21
|
+
- `GitLogLexer`: Adds support for highlighting `git log` output.
|
|
22
|
+
- `GitPrettyLogLexer`: Adds support for highlighting `git log` output, following the format:
|
|
23
|
+
```
|
|
24
|
+
log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)'
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Examples of the result can be found [here](https://joapuiib.github.io/mkdocs-material-joapuiib/features/code_blocks/#shell-block).
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Pygments Shell Console
|
|
2
|
+

|
|
3
|
+
[](https://pypi.org/project/pygments-shell-console/)
|
|
4
|
+
|
|
5
|
+
This Pygments plugin adds new lexers for `shellconsole` output.
|
|
6
|
+
|
|
7
|
+
The lexers are:
|
|
8
|
+
- `ShellConsoleLexer`: Based in [`ShellSessionBaseLexer`](https://github.com/pygments/pygments/blob/master/pygments/lexers/shell.py#L151C7-L151C28),
|
|
9
|
+
extends its behavior to recognize the prompt elements and highlight them.
|
|
10
|
+
|
|
11
|
+
Also, it adds support for highlighting the following commands output:
|
|
12
|
+
- Uses `DiffLexer` to highlight `diff` and `git diff` output.
|
|
13
|
+
- `GitStatusLexer`: Adds support for highlighting `git status` output.
|
|
14
|
+
- `GitShowLexer`: Adds support for highlighting `git show` output.
|
|
15
|
+
- `GitLogLexer`: Adds support for highlighting `git log` output.
|
|
16
|
+
- `GitPrettyLogLexer`: Adds support for highlighting `git log` output, following the format:
|
|
17
|
+
```
|
|
18
|
+
log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)'
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Examples of the result can be found [here](https://joapuiib.github.io/mkdocs-material-joapuiib/features/code_blocks/#shell-block).
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
joapuiib@FP:~/01_introduccio (main) $ git log
|
|
2
|
+
commit c9fc6c856c2d52744b85a6f8d92feac496e60bd6 (HEAD -> main, tag: v1)
|
|
3
|
+
Author: Joan Puigcerver <j.puigcerveribanez@edu.gva.es>
|
|
4
|
+
Date: Mon Oct 16 11:43:20 2023 +0200
|
|
5
|
+
|
|
6
|
+
Added another line to README.md
|
|
7
|
+
|
|
8
|
+
commit 8e702933d5dbec9ee71100a1599ae4491085e1aa (tag: v2)
|
|
9
|
+
Author: Joan Puigcerver <j.puigcerveribanez@edu.gva.es>
|
|
10
|
+
Date: Fri Oct 13 16:06:59 2023 +0200
|
|
11
|
+
|
|
12
|
+
Added Readme.md
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
joapuiib@FP:~/01_introduccio (main) $ git show 8e70293
|
|
2
|
+
commit 8e702933d5dbec9ee71100a1599ae4491085e1aa (HEAD -> main)
|
|
3
|
+
Author: Joan Puigcerver Ibáñez <j.puigcerveribanez@edu.gva.es>
|
|
4
|
+
Date: Fri Oct 13 16:06:59 2023 +0200
|
|
5
|
+
|
|
6
|
+
Added README.md
|
|
7
|
+
|
|
8
|
+
diff --git a/README.md b/README.md
|
|
9
|
+
new file mode 100644
|
|
10
|
+
index 0000000..6d747b3
|
|
11
|
+
--- /dev/null
|
|
12
|
+
+++ b/README.md
|
|
13
|
+
@@ -0,0 +1,2 @@
|
|
14
|
+
+# 01 - Introducció a Git
|
|
15
|
+
+Estem aprenent a utilitzar Git!
|
|
16
|
+
-Deletion
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from pygments.lexer import Lexer
|
|
4
4
|
from pygments.lexer import RegexLexer, ExtendedRegexLexer, include, bygroups, \
|
|
5
|
-
default, using, line_re, do_insertions
|
|
5
|
+
default, using, line_re, do_insertions, inherit
|
|
6
6
|
from pygments.token import Token, Punctuation, Whitespace, \
|
|
7
7
|
Text, Comment, Operator, Keyword, Name, String, Number, Generic
|
|
8
8
|
from pygments.lexers.diff import DiffLexer
|
|
@@ -10,7 +10,13 @@ from pygments.token import STANDARD_TYPES
|
|
|
10
10
|
|
|
11
11
|
import re
|
|
12
12
|
|
|
13
|
-
__all__ = [
|
|
13
|
+
__all__ = [
|
|
14
|
+
'GitLexer',
|
|
15
|
+
'GitStatusLexer',
|
|
16
|
+
'GitPrettyLogLexer',
|
|
17
|
+
'GitLogLexer',
|
|
18
|
+
'GitShowLexer',
|
|
19
|
+
]
|
|
14
20
|
|
|
15
21
|
STANDARD_TYPES.update({
|
|
16
22
|
Token.Git: 'git',
|
|
@@ -19,6 +25,7 @@ STANDARD_TYPES.update({
|
|
|
19
25
|
Token.Git.CommitDate: 'git-cd',
|
|
20
26
|
Token.Git.CommitMessage: 'git-cm',
|
|
21
27
|
Token.Git.CommitAuthor: 'git-ca',
|
|
28
|
+
Token.Git.Hint: 'git-hint',
|
|
22
29
|
Token.Git.Refs: 'git-r',
|
|
23
30
|
Token.Git.Untracked: 'git-untr',
|
|
24
31
|
Token.Git.Modified: 'git-mod',
|
|
@@ -32,12 +39,23 @@ STANDARD_TYPES.update({
|
|
|
32
39
|
Token.Git.Refs.Branch: 'git-b',
|
|
33
40
|
})
|
|
34
41
|
|
|
35
|
-
class
|
|
42
|
+
class GitLexer(RegexLexer):
|
|
36
43
|
name = "Git"
|
|
37
44
|
aliases = ["git"]
|
|
38
45
|
filenames = ['*.git']
|
|
39
46
|
version_added = '1.0'
|
|
40
47
|
|
|
48
|
+
tokens = {
|
|
49
|
+
'root': [
|
|
50
|
+
(r'\n', Whitespace),
|
|
51
|
+
(r'^hint: (.*?)\n', Token.Git.Hint),
|
|
52
|
+
(r'^.*$\n', Generic.Output),
|
|
53
|
+
(r'[^\n]+', Generic.Output),
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
class GitPrettyLogLexer(Lexer):
|
|
41
59
|
_branch_line_rgx = r'([\|\\\/ ]*)'
|
|
42
60
|
_logrgx_groups = [
|
|
43
61
|
_branch_line_rgx, # 1. Branch line
|
|
@@ -54,10 +72,10 @@ class GitLogLexer(Lexer):
|
|
|
54
72
|
r'( +)', # 12. Space
|
|
55
73
|
r'(-)', # 13. Commit separator
|
|
56
74
|
r'( +)', # 14. Space
|
|
57
|
-
r'([0-9A-Za-zÀ-ÖØ-öø-ÿ ]+)', # 15. Author
|
|
58
|
-
r'(
|
|
59
|
-
r'((\([\w ->,:]+\))?)',
|
|
60
|
-
r'
|
|
75
|
+
r'([0-9A-Za-zÀ-ÖØ-öø-ÿ ]*[0-9A-Za-zÀ-ÖØ-öø-ÿ]+)', # 15. Author
|
|
76
|
+
r'( *)', # 16. Space
|
|
77
|
+
r'((\([\w ->,:]+\))?)', # 17. Refs
|
|
78
|
+
r'\n', # End
|
|
61
79
|
]
|
|
62
80
|
|
|
63
81
|
# Combine the regex patterns into a single pattern
|
|
@@ -111,7 +129,7 @@ class GitStatusLexer(RegexLexer):
|
|
|
111
129
|
(r'\s*Untracked files:\n', Generic.Output, 'untracked'),
|
|
112
130
|
(r'\s*Changes not staged for commit:\n', Generic.Output, 'modified'),
|
|
113
131
|
(r'\s*Changes to be committed:\n', Generic.Output, 'staged'),
|
|
114
|
-
(r'^.*\n',
|
|
132
|
+
(r'^.*\n', using(GitLexer)),
|
|
115
133
|
],
|
|
116
134
|
'untracked': [
|
|
117
135
|
(r'^\s*\n', Whitespace, '#pop'),
|
|
@@ -142,13 +160,12 @@ class GitStatusLexer(RegexLexer):
|
|
|
142
160
|
],
|
|
143
161
|
}
|
|
144
162
|
|
|
145
|
-
class
|
|
163
|
+
class GitLogLexer(RegexLexer):
|
|
146
164
|
tokens = {
|
|
147
165
|
'root': [
|
|
148
166
|
(r'^\n', Whitespace),
|
|
149
|
-
(r'^diff .*\n', using(DiffLexer), 'diff'),
|
|
150
167
|
(r'^(commit [0-9a-f]+)', Token.Git.Show.Header, 'header'),
|
|
151
|
-
(r'^.*\n',
|
|
168
|
+
(r'^.*\n', using(GitLexer)),
|
|
152
169
|
],
|
|
153
170
|
'header': [
|
|
154
171
|
(r' +', Whitespace),
|
|
@@ -160,7 +177,29 @@ class GitShowLexer(RegexLexer):
|
|
|
160
177
|
(r'[\w/_-]+', Token.Git.Refs.Branch),
|
|
161
178
|
(r'\n', Whitespace, '#pop'),
|
|
162
179
|
],
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
class GitShowLexer(GitLogLexer):
|
|
184
|
+
tokens = {
|
|
185
|
+
'root': [
|
|
186
|
+
(r'^diff .*\n', using(DiffLexer), 'diff'),
|
|
187
|
+
inherit
|
|
188
|
+
],
|
|
163
189
|
'diff': [
|
|
164
190
|
(r'^.*\n', using(DiffLexer)),
|
|
165
191
|
],
|
|
166
192
|
}
|
|
193
|
+
|
|
194
|
+
class GitBranchLexer(RegexLexer):
|
|
195
|
+
tokens = {
|
|
196
|
+
'root': [
|
|
197
|
+
(r'^\n', Whitespace),
|
|
198
|
+
(r'^(\* )(.*?)(\n)', bygroups(
|
|
199
|
+
using(GitLexer),
|
|
200
|
+
Token.Git.Refs.Branch,
|
|
201
|
+
Whitespace,
|
|
202
|
+
)),
|
|
203
|
+
(r'^.*\n', using(GitLexer)),
|
|
204
|
+
],
|
|
205
|
+
}
|
|
@@ -8,7 +8,8 @@ from pygments.token import Token, Punctuation, Whitespace, \
|
|
|
8
8
|
from pygments.lexers.diff import DiffLexer
|
|
9
9
|
from pygments.lexers.shell import BashLexer
|
|
10
10
|
from pygments.lexers.diff import DiffLexer
|
|
11
|
-
from git_lexer import GitLogLexer,
|
|
11
|
+
from git_lexer import GitLexer, GitLogLexer, GitPrettyLogLexer, \
|
|
12
|
+
GitStatusLexer, GitShowLexer, GitBranchLexer
|
|
12
13
|
from pygments.token import STANDARD_TYPES
|
|
13
14
|
|
|
14
15
|
import re
|
|
@@ -75,9 +76,12 @@ class ShellConsoleLexer(Lexer):
|
|
|
75
76
|
def get_tokens_unprocessed(self, text):
|
|
76
77
|
innerlexer = self._innerLexerCls(**self.options)
|
|
77
78
|
difflexer = DiffLexer()
|
|
78
|
-
|
|
79
|
+
gitlexer = GitLexer()
|
|
80
|
+
git_log_lexer = GitLogLexer()
|
|
81
|
+
git_pretty_log_lexer = GitPrettyLogLexer()
|
|
79
82
|
gitstatuslexer = GitStatusLexer()
|
|
80
83
|
gitshowlexer = GitShowLexer()
|
|
84
|
+
gitbranchlexer = GitBranchLexer()
|
|
81
85
|
|
|
82
86
|
pos = 0
|
|
83
87
|
# Bash command
|
|
@@ -154,12 +158,18 @@ class ShellConsoleLexer(Lexer):
|
|
|
154
158
|
else:
|
|
155
159
|
if 'diff' in curcode:
|
|
156
160
|
custom_lexer = difflexer
|
|
157
|
-
elif curcode.startswith('git lg'):
|
|
158
|
-
custom_lexer =
|
|
161
|
+
elif curcode.startswith('git lg') or curcode.startswith('git log --graph'):
|
|
162
|
+
custom_lexer = git_pretty_log_lexer
|
|
163
|
+
elif curcode.startswith('git log'):
|
|
164
|
+
custom_lexer = git_log_lexer
|
|
159
165
|
elif curcode.startswith('git status'):
|
|
160
166
|
custom_lexer = gitstatuslexer
|
|
161
167
|
elif curcode.startswith('git show'):
|
|
162
168
|
custom_lexer = gitshowlexer
|
|
169
|
+
elif curcode.startswith('git branch'):
|
|
170
|
+
custom_lexer = gitbranchlexer
|
|
171
|
+
elif curcode.startswith('git'):
|
|
172
|
+
custom_lexer = gitlexer
|
|
163
173
|
|
|
164
174
|
output += line
|
|
165
175
|
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from pygments.token import Token
|
|
3
|
+
from shellconsole_lexer import ShellConsoleLexer
|
|
4
|
+
from git_lexer import GitStatusLexer
|
|
5
|
+
|
|
6
|
+
def test_git_command_whit_hint():
|
|
7
|
+
lexer = ShellConsoleLexer()
|
|
8
|
+
text = (
|
|
9
|
+
"user@host:~/directory (main) $ git branch -d desc\n"
|
|
10
|
+
"error: the branch 'desc' is not fully merged.\n"
|
|
11
|
+
"hint: If you are sure you want to delete it, run 'git branch -D desc'.\n"
|
|
12
|
+
"hint: Disable this message with \"git config advice.forceDeleteBranch false\".\n"
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
tokens = list(lexer.get_tokens(text))
|
|
16
|
+
|
|
17
|
+
assert tokens == [
|
|
18
|
+
# Prompt
|
|
19
|
+
(Token.Generic.Prompt.UserHost, "user@host"),
|
|
20
|
+
(Token.Generic.Prompt, ":"),
|
|
21
|
+
(Token.Generic.Prompt.Directory, "~/directory"),
|
|
22
|
+
(Token.Text.Whitespace, " "),
|
|
23
|
+
(Token.Generic.Prompt.GitBranch, "(main)"),
|
|
24
|
+
(Token.Text.Whitespace, " "),
|
|
25
|
+
(Token.Generic.Prompt, "$"),
|
|
26
|
+
(Token.Text.Whitespace, " "),
|
|
27
|
+
(Token.Text, "git"),
|
|
28
|
+
(Token.Text.Whitespace, " "),
|
|
29
|
+
(Token.Text, "branch"),
|
|
30
|
+
(Token.Text.Whitespace, " "),
|
|
31
|
+
(Token.Text, "-d"),
|
|
32
|
+
(Token.Text.Whitespace, " "),
|
|
33
|
+
(Token.Text, "desc"),
|
|
34
|
+
(Token.Text.Whitespace, "\n"),
|
|
35
|
+
# Output
|
|
36
|
+
(Token.Generic.Output, "error: the branch 'desc' is not fully merged.\n"),
|
|
37
|
+
(Token.Git.Hint, "hint: If you are sure you want to delete it, run 'git branch -D desc'.\n"),
|
|
38
|
+
(Token.Git.Hint, "hint: Disable this message with \"git config advice.forceDeleteBranch false\".\n"),
|
|
39
|
+
]
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from pygments.token import Token
|
|
3
|
+
from shellconsole_lexer import ShellConsoleLexer
|
|
4
|
+
from git_lexer import GitStatusLexer
|
|
5
|
+
|
|
6
|
+
def test_git_branch():
|
|
7
|
+
lexer = ShellConsoleLexer()
|
|
8
|
+
text = (
|
|
9
|
+
"user@host:~/directory (main) $ git branch\n"
|
|
10
|
+
"* main\n"
|
|
11
|
+
" desc\n"
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
tokens = list(lexer.get_tokens(text))
|
|
15
|
+
|
|
16
|
+
assert tokens == [
|
|
17
|
+
# Prompt
|
|
18
|
+
(Token.Generic.Prompt.UserHost, "user@host"),
|
|
19
|
+
(Token.Generic.Prompt, ":"),
|
|
20
|
+
(Token.Generic.Prompt.Directory, "~/directory"),
|
|
21
|
+
(Token.Text.Whitespace, " "),
|
|
22
|
+
(Token.Generic.Prompt.GitBranch, "(main)"),
|
|
23
|
+
(Token.Text.Whitespace, " "),
|
|
24
|
+
(Token.Generic.Prompt, "$"),
|
|
25
|
+
(Token.Text.Whitespace, " "),
|
|
26
|
+
(Token.Text, "git"),
|
|
27
|
+
(Token.Text.Whitespace, " "),
|
|
28
|
+
(Token.Text, "branch"),
|
|
29
|
+
(Token.Text.Whitespace, "\n"),
|
|
30
|
+
# Output
|
|
31
|
+
(Token.Generic.Output, "* "),
|
|
32
|
+
(Token.Git.Refs.Branch, "main"),
|
|
33
|
+
(Token.Text.Whitespace, "\n"),
|
|
34
|
+
(Token.Generic.Output, " desc\n"),
|
|
35
|
+
]
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from pygments.token import Token
|
|
3
|
+
from shellconsole_lexer import ShellConsoleLexer
|
|
4
|
+
from git_lexer import GitStatusLexer
|
|
5
|
+
|
|
6
|
+
def test_git_show():
|
|
7
|
+
lexer = ShellConsoleLexer()
|
|
8
|
+
text = (
|
|
9
|
+
"user@host:~/directory (main) $ git show\n"
|
|
10
|
+
"commit c9fc6c856c2d52744b85a6f8d92feac496e60bd6 (HEAD -> main, tag: v1)\n"
|
|
11
|
+
"Author: Author <author@localhost>\n"
|
|
12
|
+
"Date: Mon Oct 16 11:43:20 2023 +0200\n"
|
|
13
|
+
"\n"
|
|
14
|
+
" Added another line to README.md\n"
|
|
15
|
+
"\n"
|
|
16
|
+
"commit 8e702933d5dbec9ee71100a1599ae4491085e1aa\n"
|
|
17
|
+
"Author: Author <author@localhost>\n"
|
|
18
|
+
"Date: Fri Oct 13 16:06:59 2023 +0200\n"
|
|
19
|
+
"\n"
|
|
20
|
+
" Added README.md\n"
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
tokens = list(lexer.get_tokens(text))
|
|
24
|
+
|
|
25
|
+
assert tokens == [
|
|
26
|
+
(Token.Generic.Prompt.UserHost, "user@host"),
|
|
27
|
+
(Token.Generic.Prompt, ":"),
|
|
28
|
+
(Token.Generic.Prompt.Directory, "~/directory"),
|
|
29
|
+
(Token.Text.Whitespace, " "),
|
|
30
|
+
(Token.Generic.Prompt.GitBranch, "(main)"),
|
|
31
|
+
(Token.Text.Whitespace, " "),
|
|
32
|
+
(Token.Generic.Prompt, "$"),
|
|
33
|
+
(Token.Text.Whitespace, " "),
|
|
34
|
+
(Token.Text, "git"),
|
|
35
|
+
(Token.Text.Whitespace, " "),
|
|
36
|
+
(Token.Text, "show"),
|
|
37
|
+
(Token.Text.Whitespace, "\n"),
|
|
38
|
+
# First commit
|
|
39
|
+
(Token.Git.Show.Header, "commit c9fc6c856c2d52744b85a6f8d92feac496e60bd6"),
|
|
40
|
+
(Token.Text.Whitespace, " "),
|
|
41
|
+
(Token.Git.Show.Header, "("),
|
|
42
|
+
(Token.Git.Refs.Head, "HEAD"),
|
|
43
|
+
(Token.Text.Whitespace, " "),
|
|
44
|
+
(Token.Git.Show.Header, "->"),
|
|
45
|
+
(Token.Text.Whitespace, " "),
|
|
46
|
+
(Token.Git.Refs.Branch, "main"),
|
|
47
|
+
(Token.Git.Show.Header, ","),
|
|
48
|
+
(Token.Text.Whitespace, " "),
|
|
49
|
+
(Token.Git.Refs.Tag, "tag: v1"),
|
|
50
|
+
(Token.Git.Show.Header, ")"),
|
|
51
|
+
(Token.Text.Whitespace, "\n"),
|
|
52
|
+
(Token.Generic.Output, "Author: Author <author@localhost>\n"),
|
|
53
|
+
(Token.Generic.Output, "Date: Mon Oct 16 11:43:20 2023 +0200\n"),
|
|
54
|
+
(Token.Text.Whitespace, "\n"),
|
|
55
|
+
(Token.Generic.Output, " Added another line to README.md\n"),
|
|
56
|
+
(Token.Text.Whitespace, "\n"),
|
|
57
|
+
# Second commit
|
|
58
|
+
(Token.Git.Show.Header, "commit 8e702933d5dbec9ee71100a1599ae4491085e1aa"),
|
|
59
|
+
(Token.Text.Whitespace, "\n"),
|
|
60
|
+
(Token.Generic.Output, "Author: Author <author@localhost>\n"),
|
|
61
|
+
(Token.Generic.Output, "Date: Fri Oct 13 16:06:59 2023 +0200\n"),
|
|
62
|
+
(Token.Text.Whitespace, "\n"),
|
|
63
|
+
(Token.Generic.Output, " Added README.md\n"),
|
|
64
|
+
]
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import pytest
|
|
2
2
|
from pygments.token import Token
|
|
3
3
|
from shellconsole_lexer import ShellConsoleLexer
|
|
4
|
-
from git_lexer import
|
|
4
|
+
from git_lexer import GitPrettyLogLexer
|
|
5
5
|
|
|
6
6
|
def test_full_git_log():
|
|
7
7
|
lexer = ShellConsoleLexer()
|
|
@@ -163,3 +163,60 @@ def test_git_log_with_other_command():
|
|
|
163
163
|
(Token.Literal.String.Single, "'Hello, world!'"),
|
|
164
164
|
(Token.Text.Whitespace, "\n"),
|
|
165
165
|
]
|
|
166
|
+
|
|
167
|
+
def test_simple_git_log():
|
|
168
|
+
lexer = ShellConsoleLexer()
|
|
169
|
+
text = (
|
|
170
|
+
"user@host:~/directory (main) $ git lg\n"
|
|
171
|
+
"* f853946 - (7 minutes ago) README: Afegits autors - Mar (main)\n"
|
|
172
|
+
"* 0fb88ef - (29 minutes ago) 1. Primer commit - Joan Puigcerver"
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
tokens = list(lexer.get_tokens(text))
|
|
176
|
+
|
|
177
|
+
assert tokens == [
|
|
178
|
+
(Token.Generic.Prompt.UserHost, "user@host"),
|
|
179
|
+
(Token.Generic.Prompt, ":"),
|
|
180
|
+
(Token.Generic.Prompt.Directory, "~/directory"),
|
|
181
|
+
(Token.Text.Whitespace, " "),
|
|
182
|
+
(Token.Generic.Prompt.GitBranch, "(main)"),
|
|
183
|
+
(Token.Text.Whitespace, " "),
|
|
184
|
+
(Token.Generic.Prompt, "$"),
|
|
185
|
+
(Token.Text.Whitespace, " "),
|
|
186
|
+
(Token.Text, "git"),
|
|
187
|
+
(Token.Text.Whitespace, " "),
|
|
188
|
+
(Token.Text, "lg"),
|
|
189
|
+
(Token.Text.Whitespace, "\n"),
|
|
190
|
+
# First commit
|
|
191
|
+
(Token.Generic.Output, "*",),
|
|
192
|
+
(Token.Text.Whitespace, " "),
|
|
193
|
+
(Token.Git.CommitHash, "f853946"),
|
|
194
|
+
(Token.Text.Whitespace, " "),
|
|
195
|
+
(Token.Generic.Output, "-"),
|
|
196
|
+
(Token.Text.Whitespace, " "),
|
|
197
|
+
(Token.Git.CommitDate, "(7 minutes ago)"),
|
|
198
|
+
(Token.Text.Whitespace, " "),
|
|
199
|
+
(Token.Git.CommitMessage, "README: Afegits autors"),
|
|
200
|
+
(Token.Text.Whitespace, " "),
|
|
201
|
+
(Token.Generic.Output, "-"),
|
|
202
|
+
(Token.Text.Whitespace, " "),
|
|
203
|
+
(Token.Git.CommitAuthor, "Mar"),
|
|
204
|
+
(Token.Text.Whitespace, " "),
|
|
205
|
+
(Token.Git.Refs, "(main)"),
|
|
206
|
+
(Token.Text.Whitespace, "\n"),
|
|
207
|
+
# Second commit
|
|
208
|
+
(Token.Generic.Output, "*"),
|
|
209
|
+
(Token.Text.Whitespace, " "),
|
|
210
|
+
(Token.Git.CommitHash, "0fb88ef"),
|
|
211
|
+
(Token.Text.Whitespace, " "),
|
|
212
|
+
(Token.Generic.Output, "-"),
|
|
213
|
+
(Token.Text.Whitespace, " "),
|
|
214
|
+
(Token.Git.CommitDate, "(29 minutes ago)"),
|
|
215
|
+
(Token.Text.Whitespace, " "),
|
|
216
|
+
(Token.Git.CommitMessage, "1. Primer commit"),
|
|
217
|
+
(Token.Text.Whitespace, " "),
|
|
218
|
+
(Token.Generic.Output, "-"),
|
|
219
|
+
(Token.Text.Whitespace, " "),
|
|
220
|
+
(Token.Git.CommitAuthor, "Joan Puigcerver"),
|
|
221
|
+
(Token.Text.Whitespace, "\n"),
|
|
222
|
+
]
|
|
@@ -175,4 +175,30 @@ def test_git_status_after_empty_command():
|
|
|
175
175
|
(Token.Generic.Output, "no changes added to commit (use \"git add\" and/or \"git commit -a\")\n"),
|
|
176
176
|
]
|
|
177
177
|
|
|
178
|
+
def test_git_status_whit_hint():
|
|
179
|
+
lexer = ShellConsoleLexer()
|
|
180
|
+
text = (
|
|
181
|
+
"user@host:~/directory (main) $ git status\n"
|
|
182
|
+
"hint: You've added another git status command\n"
|
|
183
|
+
"On branch main\n"
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
tokens = list(lexer.get_tokens(text))
|
|
178
187
|
|
|
188
|
+
assert tokens == [
|
|
189
|
+
# Prompt
|
|
190
|
+
(Token.Generic.Prompt.UserHost, "user@host"),
|
|
191
|
+
(Token.Generic.Prompt, ":"),
|
|
192
|
+
(Token.Generic.Prompt.Directory, "~/directory"),
|
|
193
|
+
(Token.Text.Whitespace, " "),
|
|
194
|
+
(Token.Generic.Prompt.GitBranch, "(main)"),
|
|
195
|
+
(Token.Text.Whitespace, " "),
|
|
196
|
+
(Token.Generic.Prompt, "$"),
|
|
197
|
+
(Token.Text.Whitespace, " "),
|
|
198
|
+
(Token.Text, "git"),
|
|
199
|
+
(Token.Text.Whitespace, " "),
|
|
200
|
+
(Token.Text, "status"),
|
|
201
|
+
(Token.Text.Whitespace, "\n"),
|
|
202
|
+
(Token.Git.Hint, "hint: You've added another git status command\n"),
|
|
203
|
+
(Token.Generic.Output, "On branch main\n"),
|
|
204
|
+
]
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.3
|
|
2
|
-
Name: pygments-shell-console
|
|
3
|
-
Version: 0.0.6
|
|
4
|
-
Requires-Dist: pygments
|
|
5
|
-
Description-Content-Type: text/markdown
|
|
6
|
-
|
|
7
|
-
# Pygments Shell Console
|
|
8
|
-
|
|
9
|
-
This Pygments plugin adds new lexers for shell console output. The lexers are:
|
|
10
|
-
- `ShellConsoleLexer`: Based in [`ShellSessionBaseLexer`](https://github.com/pygments/pygments/blob/master/pygments/lexers/shell.py#L151C7-L151C28),
|
|
11
|
-
extends its behavior to recognize the prompt elements and use `DiffLexer` and `GitLexer` for highlighting.
|
|
12
|
-
- `GitLexer`: Adds support for highlighting git log output, following the format:
|
|
13
|
-
```
|
|
14
|
-
log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)'
|
|
15
|
-
```
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
# Pygments Shell Console
|
|
2
|
-
|
|
3
|
-
This Pygments plugin adds new lexers for shell console output. The lexers are:
|
|
4
|
-
- `ShellConsoleLexer`: Based in [`ShellSessionBaseLexer`](https://github.com/pygments/pygments/blob/master/pygments/lexers/shell.py#L151C7-L151C28),
|
|
5
|
-
extends its behavior to recognize the prompt elements and use `DiffLexer` and `GitLexer` for highlighting.
|
|
6
|
-
- `GitLexer`: Adds support for highlighting git log output, following the format:
|
|
7
|
-
```
|
|
8
|
-
log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)'
|
|
9
|
-
```
|
{pygments_shell_console-0.0.6 → pygments_shell_console-0.2}/.github/workflows/publish-to-pypi.yml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|