pygments-shell-console 0.1__tar.gz → 0.2.1__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.1/PKG-INFO +27 -0
- pygments_shell_console-0.2.1/README.md +21 -0
- {pygments_shell_console-0.1 → pygments_shell_console-0.2.1}/examples/status.example +1 -0
- {pygments_shell_console-0.1 → pygments_shell_console-0.2.1}/git_lexer.py +35 -4
- {pygments_shell_console-0.1 → pygments_shell_console-0.2.1}/pyproject.toml +1 -1
- {pygments_shell_console-0.1 → pygments_shell_console-0.2.1}/shellconsole_lexer.py +8 -1
- {pygments_shell_console-0.1 → pygments_shell_console-0.2.1}/shellconsole_style.py +1 -0
- pygments_shell_console-0.2.1/test/test_git.py +73 -0
- pygments_shell_console-0.2.1/test/test_git_branch.py +35 -0
- {pygments_shell_console-0.1 → pygments_shell_console-0.2.1}/test/test_git_status.py +26 -0
- pygments_shell_console-0.1/PKG-INFO +0 -15
- pygments_shell_console-0.1/README.md +0 -9
- {pygments_shell_console-0.1 → pygments_shell_console-0.2.1}/.github/workflows/publish-to-pypi.yml +0 -0
- {pygments_shell_console-0.1 → pygments_shell_console-0.2.1}/.gitignore +0 -0
- {pygments_shell_console-0.1 → pygments_shell_console-0.2.1}/examples/git_lg.example +0 -0
- {pygments_shell_console-0.1 → pygments_shell_console-0.2.1}/examples/git_log.example +0 -0
- {pygments_shell_console-0.1 → pygments_shell_console-0.2.1}/examples/git_show.example +0 -0
- {pygments_shell_console-0.1 → pygments_shell_console-0.2.1}/examples/test.exmpl +0 -0
- {pygments_shell_console-0.1 → pygments_shell_console-0.2.1}/examples/test.sh +0 -0
- {pygments_shell_console-0.1 → pygments_shell_console-0.2.1}/test/__init__.py +0 -0
- {pygments_shell_console-0.1 → pygments_shell_console-0.2.1}/test/test_git_log.py +0 -0
- {pygments_shell_console-0.1 → pygments_shell_console-0.2.1}/test/test_git_pretty_log.py +0 -0
- {pygments_shell_console-0.1 → pygments_shell_console-0.2.1}/test/test_git_show.py +0 -0
- {pygments_shell_console-0.1 → pygments_shell_console-0.2.1}/test/test_prompts.py +0 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: pygments-shell-console
|
|
3
|
+
Version: 0.2.1
|
|
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).
|
|
@@ -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
|
|
@@ -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'),
|
|
@@ -147,7 +165,7 @@ class GitLogLexer(RegexLexer):
|
|
|
147
165
|
'root': [
|
|
148
166
|
(r'^\n', Whitespace),
|
|
149
167
|
(r'^(commit [0-9a-f]+)', Token.Git.Show.Header, 'header'),
|
|
150
|
-
(r'^.*\n',
|
|
168
|
+
(r'^.*\n', using(GitLexer)),
|
|
151
169
|
],
|
|
152
170
|
'header': [
|
|
153
171
|
(r' +', Whitespace),
|
|
@@ -172,3 +190,16 @@ class GitShowLexer(GitLogLexer):
|
|
|
172
190
|
(r'^.*\n', using(DiffLexer)),
|
|
173
191
|
],
|
|
174
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, GitPrettyLogLexer,
|
|
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,10 +76,12 @@ class ShellConsoleLexer(Lexer):
|
|
|
75
76
|
def get_tokens_unprocessed(self, text):
|
|
76
77
|
innerlexer = self._innerLexerCls(**self.options)
|
|
77
78
|
difflexer = DiffLexer()
|
|
79
|
+
gitlexer = GitLexer()
|
|
78
80
|
git_log_lexer = GitLogLexer()
|
|
79
81
|
git_pretty_log_lexer = GitPrettyLogLexer()
|
|
80
82
|
gitstatuslexer = GitStatusLexer()
|
|
81
83
|
gitshowlexer = GitShowLexer()
|
|
84
|
+
gitbranchlexer = GitBranchLexer()
|
|
82
85
|
|
|
83
86
|
pos = 0
|
|
84
87
|
# Bash command
|
|
@@ -163,6 +166,10 @@ class ShellConsoleLexer(Lexer):
|
|
|
163
166
|
custom_lexer = gitstatuslexer
|
|
164
167
|
elif curcode.startswith('git show'):
|
|
165
168
|
custom_lexer = gitshowlexer
|
|
169
|
+
elif curcode.startswith('git branch'):
|
|
170
|
+
custom_lexer = gitbranchlexer
|
|
171
|
+
elif curcode.startswith('git'):
|
|
172
|
+
custom_lexer = gitlexer
|
|
166
173
|
|
|
167
174
|
output += line
|
|
168
175
|
|
|
@@ -0,0 +1,73 @@
|
|
|
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_with_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
|
+
]
|
|
40
|
+
|
|
41
|
+
def test_git_command_with_empty_hint():
|
|
42
|
+
lexer = ShellConsoleLexer()
|
|
43
|
+
text = (
|
|
44
|
+
"user@host:~/directory $ git init\n"
|
|
45
|
+
"hint: Using 'master' as the name for the initial branch. This default branch name\n"
|
|
46
|
+
"hint: is subject to change. To configure the initial branch name to use in all\n"
|
|
47
|
+
"hint: of your new repositories, which will suppress this warning, call:\n"
|
|
48
|
+
"hint:\n"
|
|
49
|
+
"hint: git config --global init.defaultBranch <name>\n"
|
|
50
|
+
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
tokens = list(lexer.get_tokens(text))
|
|
54
|
+
|
|
55
|
+
assert tokens == [
|
|
56
|
+
# Prompt
|
|
57
|
+
(Token.Generic.Prompt.UserHost, "user@host"),
|
|
58
|
+
(Token.Generic.Prompt, ":"),
|
|
59
|
+
(Token.Generic.Prompt.Directory, "~/directory"),
|
|
60
|
+
(Token.Text.Whitespace, " "),
|
|
61
|
+
(Token.Generic.Prompt, "$"),
|
|
62
|
+
(Token.Text.Whitespace, " "),
|
|
63
|
+
(Token.Text, "git"),
|
|
64
|
+
(Token.Text.Whitespace, " "),
|
|
65
|
+
(Token.Text, "init"),
|
|
66
|
+
(Token.Text.Whitespace, "\n"),
|
|
67
|
+
# Output
|
|
68
|
+
(Token.Git.Hint, "hint: Using 'master' as the name for the initial branch. This default branch name\n"),
|
|
69
|
+
(Token.Git.Hint, "hint: is subject to change. To configure the initial branch name to use in all\n"),
|
|
70
|
+
(Token.Git.Hint, "hint: of your new repositories, which will suppress this warning, call:\n"),
|
|
71
|
+
(Token.Git.Hint, "hint:\n"),
|
|
72
|
+
(Token.Git.Hint, "hint: git config --global init.defaultBranch <name>\n"),
|
|
73
|
+
]
|
|
@@ -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
|
+
]
|
|
@@ -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.1
|
|
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.1 → pygments_shell_console-0.2.1}/.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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|