pygments-shell-console 0.8.2__tar.gz → 0.9.0__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.8.2 → pygments_shell_console-0.9.0}/.github/workflows/publish-to-pypi.yml +9 -5
- pygments_shell_console-0.9.0/PKG-INFO +87 -0
- pygments_shell_console-0.9.0/README.md +76 -0
- pygments_shell_console-0.9.0/docs/example.png +0 -0
- {pygments_shell_console-0.8.2 → pygments_shell_console-0.9.0}/examples/test.sh +1 -1
- pygments_shell_console-0.9.0/pygments_shell_console/__init__.py +5 -0
- pygments_shell_console-0.9.0/pygments_shell_console/git.py +291 -0
- pygments_shell_console-0.9.0/pygments_shell_console/shell.py +213 -0
- pygments_shell_console-0.8.2/shellconsole_style.py → pygments_shell_console-0.9.0/pygments_shell_console/style.py +8 -4
- pygments_shell_console-0.9.0/pyproject.toml +34 -0
- pygments_shell_console-0.9.0/test/test_features.py +113 -0
- {pygments_shell_console-0.8.2 → pygments_shell_console-0.9.0}/test/test_git.py +2 -2
- {pygments_shell_console-0.8.2 → pygments_shell_console-0.9.0}/test/test_git_branch.py +2 -2
- {pygments_shell_console-0.8.2 → pygments_shell_console-0.9.0}/test/test_git_log.py +2 -2
- {pygments_shell_console-0.8.2 → pygments_shell_console-0.9.0}/test/test_git_merge.py +1 -1
- {pygments_shell_console-0.8.2 → pygments_shell_console-0.9.0}/test/test_git_pretty_log.py +63 -2
- {pygments_shell_console-0.8.2 → pygments_shell_console-0.9.0}/test/test_git_show.py +2 -2
- {pygments_shell_console-0.8.2 → pygments_shell_console-0.9.0}/test/test_git_status.py +2 -2
- {pygments_shell_console-0.8.2 → pygments_shell_console-0.9.0}/test/test_prompts.py +1 -1
- pygments_shell_console-0.8.2/PKG-INFO +0 -27
- pygments_shell_console-0.8.2/README.md +0 -21
- pygments_shell_console-0.8.2/git_lexer.py +0 -236
- pygments_shell_console-0.8.2/pyproject.toml +0 -25
- pygments_shell_console-0.8.2/shellconsole_lexer.py +0 -198
- {pygments_shell_console-0.8.2 → pygments_shell_console-0.9.0}/.gitignore +0 -0
- {pygments_shell_console-0.8.2 → pygments_shell_console-0.9.0}/examples/git_lg.example +0 -0
- {pygments_shell_console-0.8.2 → pygments_shell_console-0.9.0}/examples/git_log.example +0 -0
- {pygments_shell_console-0.8.2 → pygments_shell_console-0.9.0}/examples/git_show.example +0 -0
- {pygments_shell_console-0.8.2 → pygments_shell_console-0.9.0}/examples/status.example +0 -0
- {pygments_shell_console-0.8.2 → pygments_shell_console-0.9.0}/examples/test.exmpl +0 -0
- {pygments_shell_console-0.8.2 → pygments_shell_console-0.9.0}/test/__init__.py +0 -0
{pygments_shell_console-0.8.2 → pygments_shell_console-0.9.0}/.github/workflows/publish-to-pypi.yml
RENAMED
|
@@ -13,12 +13,16 @@ jobs:
|
|
|
13
13
|
permissions:
|
|
14
14
|
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
|
|
15
15
|
steps:
|
|
16
|
-
- name:
|
|
17
|
-
uses: actions/checkout@
|
|
18
|
-
- name: Set up Python 3.
|
|
19
|
-
uses: actions/setup-python@
|
|
16
|
+
- name: Check out the repository
|
|
17
|
+
uses: actions/checkout@v4
|
|
18
|
+
- name: Set up Python 3.12
|
|
19
|
+
uses: actions/setup-python@v5
|
|
20
20
|
with:
|
|
21
|
-
python-version: 3.
|
|
21
|
+
python-version: "3.12"
|
|
22
|
+
- name: Run the tests
|
|
23
|
+
run: |
|
|
24
|
+
python -m pip install -e '.[test]'
|
|
25
|
+
python -m pytest
|
|
22
26
|
- name: Install pypa/build
|
|
23
27
|
run: >-
|
|
24
28
|
python -m
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pygments-shell-console
|
|
3
|
+
Version: 0.9.0
|
|
4
|
+
Summary: Pygments lexers for shell console sessions, with highlighted prompts and git output
|
|
5
|
+
Project-URL: Homepage, https://github.com/joapuiib/pygments-shell-console
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Requires-Dist: pygments
|
|
8
|
+
Provides-Extra: test
|
|
9
|
+
Requires-Dist: pytest; extra == 'test'
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
|
|
12
|
+
# Pygments Shell Console
|
|
13
|
+
[](https://www.python.org/)
|
|
14
|
+
[](https://pypi.org/project/pygments-shell-console/)
|
|
15
|
+
|
|
16
|
+
Pygments lexers for shell console sessions: highlighted prompts and git output.
|
|
17
|
+
|
|
18
|
+

|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
pip install pygments-shell-console
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
Use the `shellconsole` lexer with the `shellconsole-style` style:
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
pygmentize -l shellconsole -O style=shellconsole-style session.txt
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
In Markdown (MkDocs, Sphinx...), use `shellconsole` as the code block language:
|
|
35
|
+
|
|
36
|
+
````
|
|
37
|
+
```shellconsole
|
|
38
|
+
user@host:~/project (main) $ git status
|
|
39
|
+
```
|
|
40
|
+
````
|
|
41
|
+
|
|
42
|
+
## Prompt
|
|
43
|
+
|
|
44
|
+
The prompt elements are highlighted separately:
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
(venv) user@host:~/project (main) $
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Virtualenv, `user@host`, directory and git branch. Also supported:
|
|
51
|
+
|
|
52
|
+
- Root prompts (`root@host:~#`) and `[user@host ~]` style prompts.
|
|
53
|
+
- Continuation lines: backslash, trailing `|`, `&&` or `||`, and here-documents.
|
|
54
|
+
|
|
55
|
+
## Output
|
|
56
|
+
|
|
57
|
+
The output lexer is chosen from the command. `sudo` and git global options
|
|
58
|
+
(`-C dir`, `--no-pager`...) are skipped.
|
|
59
|
+
|
|
60
|
+
| Command | Lexer | Alias |
|
|
61
|
+
|---|---|---|
|
|
62
|
+
| `diff`, `git diff`, `git stash show -p` | `DiffLexer` | |
|
|
63
|
+
| `git status` | `GitStatusLexer` | `git-status` |
|
|
64
|
+
| `git status -s`, `--porcelain` | `GitShortStatusLexer` | `git-short-status` |
|
|
65
|
+
| `git show` | `GitShowLexer` | `git-show` |
|
|
66
|
+
| `git log`, `--oneline`, `-p` | `GitLogLexer` | `git-log` |
|
|
67
|
+
| `git lg*`, `git log --graph` | `GitPrettyLogLexer` | `git-pretty-log` |
|
|
68
|
+
| `git branch` | `GitBranchLexer` | `git-branch` |
|
|
69
|
+
| `git merge`, `pull`, `stash show`, `diff --stat` | `GitMergeLexer` | `git-merge` |
|
|
70
|
+
| any other `git` command | `GitLexer` | `git` |
|
|
71
|
+
|
|
72
|
+
The git lexers can also be used on their own through their alias.
|
|
73
|
+
|
|
74
|
+
`git lg*` expects this format:
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
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)'
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
More examples: [mkdocs-material-joapuiib](https://joapuiib.github.io/mkdocs-material-joapuiib/features/blocs_de_codi/#bloc-de-consola).
|
|
81
|
+
|
|
82
|
+
## Development
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
pip install -e '.[test]'
|
|
86
|
+
pytest
|
|
87
|
+
```
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Pygments Shell Console
|
|
2
|
+
[](https://www.python.org/)
|
|
3
|
+
[](https://pypi.org/project/pygments-shell-console/)
|
|
4
|
+
|
|
5
|
+
Pygments lexers for shell console sessions: highlighted prompts and git output.
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
pip install pygments-shell-console
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
Use the `shellconsole` lexer with the `shellconsole-style` style:
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
pygmentize -l shellconsole -O style=shellconsole-style session.txt
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
In Markdown (MkDocs, Sphinx...), use `shellconsole` as the code block language:
|
|
24
|
+
|
|
25
|
+
````
|
|
26
|
+
```shellconsole
|
|
27
|
+
user@host:~/project (main) $ git status
|
|
28
|
+
```
|
|
29
|
+
````
|
|
30
|
+
|
|
31
|
+
## Prompt
|
|
32
|
+
|
|
33
|
+
The prompt elements are highlighted separately:
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
(venv) user@host:~/project (main) $
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Virtualenv, `user@host`, directory and git branch. Also supported:
|
|
40
|
+
|
|
41
|
+
- Root prompts (`root@host:~#`) and `[user@host ~]` style prompts.
|
|
42
|
+
- Continuation lines: backslash, trailing `|`, `&&` or `||`, and here-documents.
|
|
43
|
+
|
|
44
|
+
## Output
|
|
45
|
+
|
|
46
|
+
The output lexer is chosen from the command. `sudo` and git global options
|
|
47
|
+
(`-C dir`, `--no-pager`...) are skipped.
|
|
48
|
+
|
|
49
|
+
| Command | Lexer | Alias |
|
|
50
|
+
|---|---|---|
|
|
51
|
+
| `diff`, `git diff`, `git stash show -p` | `DiffLexer` | |
|
|
52
|
+
| `git status` | `GitStatusLexer` | `git-status` |
|
|
53
|
+
| `git status -s`, `--porcelain` | `GitShortStatusLexer` | `git-short-status` |
|
|
54
|
+
| `git show` | `GitShowLexer` | `git-show` |
|
|
55
|
+
| `git log`, `--oneline`, `-p` | `GitLogLexer` | `git-log` |
|
|
56
|
+
| `git lg*`, `git log --graph` | `GitPrettyLogLexer` | `git-pretty-log` |
|
|
57
|
+
| `git branch` | `GitBranchLexer` | `git-branch` |
|
|
58
|
+
| `git merge`, `pull`, `stash show`, `diff --stat` | `GitMergeLexer` | `git-merge` |
|
|
59
|
+
| any other `git` command | `GitLexer` | `git` |
|
|
60
|
+
|
|
61
|
+
The git lexers can also be used on their own through their alias.
|
|
62
|
+
|
|
63
|
+
`git lg*` expects this format:
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
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)'
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
More examples: [mkdocs-material-joapuiib](https://joapuiib.github.io/mkdocs-material-joapuiib/features/blocs_de_codi/#bloc-de-consola).
|
|
70
|
+
|
|
71
|
+
## Development
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
pip install -e '.[test]'
|
|
75
|
+
pytest
|
|
76
|
+
```
|
|
Binary file
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
|
-
./venv/bin/pygmentize -l shellconsole -O style=shellconsole-style $@
|
|
2
|
+
./venv/bin/pygmentize -l shellconsole -O style=shellconsole-style "$@"
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
"""Lexers for the output of git commands."""
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
|
|
5
|
+
from pygments.lexer import Lexer, RegexLexer, bygroups, default, line_re, \
|
|
6
|
+
using
|
|
7
|
+
from pygments.lexers.diff import DiffLexer
|
|
8
|
+
from pygments.token import STANDARD_TYPES, Comment, Generic, Token, Whitespace
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
'GitLexer',
|
|
12
|
+
'GitStatusLexer',
|
|
13
|
+
'GitShortStatusLexer',
|
|
14
|
+
'GitLogLexer',
|
|
15
|
+
'GitPrettyLogLexer',
|
|
16
|
+
'GitShowLexer',
|
|
17
|
+
'GitBranchLexer',
|
|
18
|
+
'GitMergeLexer',
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
STANDARD_TYPES.update({
|
|
22
|
+
Token.Git: 'git',
|
|
23
|
+
Token.Git.BranchLine: 'git-bl',
|
|
24
|
+
Token.Git.CommitHash: 'git-ch',
|
|
25
|
+
Token.Git.CommitDate: 'git-cd',
|
|
26
|
+
Token.Git.CommitMessage: 'git-cm',
|
|
27
|
+
Token.Git.CommitAuthor: 'git-ca',
|
|
28
|
+
Token.Git.Hint: 'git-hint',
|
|
29
|
+
Token.Git.Warning: 'git-warning',
|
|
30
|
+
Token.Git.Error: 'git-error',
|
|
31
|
+
Token.Git.Fatal: 'git-fatal',
|
|
32
|
+
Token.Git.Refs: 'git-r',
|
|
33
|
+
Token.Git.Untracked: 'git-untr',
|
|
34
|
+
Token.Git.Modified: 'git-mod',
|
|
35
|
+
Token.Git.Unmerged: 'git-unm',
|
|
36
|
+
Token.Git.Staged: 'git-stg',
|
|
37
|
+
Token.Git.Show: 'git-show',
|
|
38
|
+
Token.Git.Show.Header: 'git-show-h',
|
|
39
|
+
Token.Git.Refs.RemoteHead: 'git-rh',
|
|
40
|
+
Token.Git.Refs.Head: 'git-h',
|
|
41
|
+
Token.Git.Refs.Tag: 'git-t',
|
|
42
|
+
Token.Git.Refs.RemoteBranch: 'git-rb',
|
|
43
|
+
Token.Git.Refs.Branch: 'git-b',
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
# Remote names recognised in ref decorations, e.g. "origin/main".
|
|
47
|
+
_REMOTES = r'(?:origin|upstream)'
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class GitLexer(RegexLexer):
|
|
51
|
+
"""Generic git output: highlights error, fatal, hint and warning lines."""
|
|
52
|
+
|
|
53
|
+
name = 'Git'
|
|
54
|
+
aliases = ['git']
|
|
55
|
+
filenames = ['*.git']
|
|
56
|
+
version_added = '1.0'
|
|
57
|
+
|
|
58
|
+
tokens = {
|
|
59
|
+
'root': [
|
|
60
|
+
(r'\n', Whitespace),
|
|
61
|
+
(r'^error:.*\n', Token.Git.Error),
|
|
62
|
+
(r'^fatal:.*\n', Token.Git.Fatal),
|
|
63
|
+
(r'^hint:.*\n', Token.Git.Hint),
|
|
64
|
+
(r'^warning:.*\n', Token.Git.Warning),
|
|
65
|
+
(r'^.*\n', Generic.Output),
|
|
66
|
+
(r'[^\n]+', Generic.Output),
|
|
67
|
+
],
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _status_section(token):
|
|
72
|
+
"""Rules for a `git status` file list, colouring each entry with `token`."""
|
|
73
|
+
return [
|
|
74
|
+
(r'^\s*\n', Whitespace, '#pop'),
|
|
75
|
+
(r'^\s+\(.*\)\n', Generic.Output),
|
|
76
|
+
(r'^(\s*)([^\n]+)(\n)', bygroups(Whitespace, token, Whitespace)),
|
|
77
|
+
]
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class GitStatusLexer(RegexLexer):
|
|
81
|
+
"""Output of `git status`."""
|
|
82
|
+
|
|
83
|
+
name = 'Git Status'
|
|
84
|
+
aliases = ['git-status']
|
|
85
|
+
version_added = '1.0'
|
|
86
|
+
|
|
87
|
+
tokens = {
|
|
88
|
+
'root': [
|
|
89
|
+
(r'^\n', Whitespace),
|
|
90
|
+
(r'\s*Untracked files:\n', Generic.Output, 'untracked'),
|
|
91
|
+
(r'\s*Changes not staged for commit:\n', Generic.Output, 'modified'),
|
|
92
|
+
(r'\s*Changes to be committed:\n', Generic.Output, 'staged'),
|
|
93
|
+
(r'\s*Unmerged paths:\n', Generic.Output, 'unmerged'),
|
|
94
|
+
(r'^.*\n', using(GitLexer)),
|
|
95
|
+
],
|
|
96
|
+
'untracked': _status_section(Token.Git.Untracked),
|
|
97
|
+
'modified': _status_section(Token.Git.Modified),
|
|
98
|
+
'staged': _status_section(Token.Git.Staged),
|
|
99
|
+
'unmerged': _status_section(Token.Git.Unmerged),
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class GitShortStatusLexer(RegexLexer):
|
|
104
|
+
"""Output of `git status --short` / `--porcelain`."""
|
|
105
|
+
|
|
106
|
+
name = 'Git Short Status'
|
|
107
|
+
aliases = ['git-short-status']
|
|
108
|
+
version_added = '1.0'
|
|
109
|
+
|
|
110
|
+
tokens = {
|
|
111
|
+
'root': [
|
|
112
|
+
(r'^\n', Whitespace),
|
|
113
|
+
(r'^(## )(No commits yet on )(\S+)(.*\n)', bygroups(
|
|
114
|
+
Generic.Output, Generic.Output,
|
|
115
|
+
Token.Git.Refs.Branch, Generic.Output,
|
|
116
|
+
)),
|
|
117
|
+
(r'^(## )(\S+?)(?:(\.\.\.)(\S+))?(\s.*\n|\n)', bygroups(
|
|
118
|
+
Generic.Output, Token.Git.Refs.Branch,
|
|
119
|
+
Generic.Output, Token.Git.Refs.RemoteBranch, Generic.Output,
|
|
120
|
+
)),
|
|
121
|
+
(r'^(\?\?)( )(.*)(\n)', bygroups(
|
|
122
|
+
Token.Git.Untracked, Whitespace, Generic.Output, Whitespace,
|
|
123
|
+
)),
|
|
124
|
+
(r'^(DD|AU|UD|UA|DU|AA|UU)( )(.*)(\n)', bygroups(
|
|
125
|
+
Token.Git.Unmerged, Whitespace, Generic.Output, Whitespace,
|
|
126
|
+
)),
|
|
127
|
+
(r'^([MTADRC ])([MTADRC ])( )(.*)(\n)', bygroups(
|
|
128
|
+
Token.Git.Staged, Token.Git.Modified,
|
|
129
|
+
Whitespace, Generic.Output, Whitespace,
|
|
130
|
+
)),
|
|
131
|
+
(r'^.*\n', using(GitLexer)),
|
|
132
|
+
],
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
class GitLogLexer(RegexLexer):
|
|
137
|
+
"""Output of `git log`, including `--oneline` and `-p`."""
|
|
138
|
+
|
|
139
|
+
name = 'Git Log'
|
|
140
|
+
aliases = ['git-log']
|
|
141
|
+
version_added = '1.0'
|
|
142
|
+
|
|
143
|
+
tokens = {
|
|
144
|
+
'root': [
|
|
145
|
+
(r'^\n', Whitespace),
|
|
146
|
+
(r'^commit [0-9a-f]+', Token.Git.Show.Header, 'header'),
|
|
147
|
+
(r'^[0-9a-f]{7,40}(?= )', Token.Git.CommitHash, 'oneline'),
|
|
148
|
+
(r'^diff .*\n', using(DiffLexer), 'diff'),
|
|
149
|
+
(r'^.*\n', using(GitLexer)),
|
|
150
|
+
],
|
|
151
|
+
'header': [
|
|
152
|
+
(r' +', Whitespace),
|
|
153
|
+
(r'\(', Token.Git.Show.Header, 'refs'),
|
|
154
|
+
(r'\n', Whitespace, '#pop'),
|
|
155
|
+
],
|
|
156
|
+
'oneline': [
|
|
157
|
+
(r'( )(\()', bygroups(Whitespace, Token.Git.Show.Header), 'refs'),
|
|
158
|
+
(r'( )(.*)(\n)', bygroups(
|
|
159
|
+
Whitespace, Token.Git.CommitMessage, Whitespace,
|
|
160
|
+
), '#pop'),
|
|
161
|
+
(r'\n', Whitespace, '#pop'),
|
|
162
|
+
],
|
|
163
|
+
'refs': [
|
|
164
|
+
(r' +', Whitespace),
|
|
165
|
+
(r'->|,', Token.Git.Show.Header),
|
|
166
|
+
(r'\)', Token.Git.Show.Header, '#pop'),
|
|
167
|
+
(_REMOTES + r'/HEAD\b', Token.Git.Refs.RemoteHead),
|
|
168
|
+
(r'HEAD\b', Token.Git.Refs.Head),
|
|
169
|
+
(r'tag: [^\s,()]+', Token.Git.Refs.Tag),
|
|
170
|
+
(_REMOTES + r'/[^\s,()]+', Token.Git.Refs.RemoteBranch),
|
|
171
|
+
(r'[^\s,()]+', Token.Git.Refs.Branch),
|
|
172
|
+
],
|
|
173
|
+
# Patch output (`git show`, `git log -p`) lasts until the next commit.
|
|
174
|
+
'diff': [
|
|
175
|
+
(r'^(?!commit [0-9a-f]+).*\n', using(DiffLexer)),
|
|
176
|
+
default('#pop'),
|
|
177
|
+
],
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
class GitShowLexer(GitLogLexer):
|
|
182
|
+
"""Output of `git show`. Same format as `git log -p`."""
|
|
183
|
+
|
|
184
|
+
name = 'Git Show'
|
|
185
|
+
aliases = ['git-show']
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
class GitPrettyLogLexer(Lexer):
|
|
189
|
+
"""Output of `git log --graph` using the format described in the README."""
|
|
190
|
+
|
|
191
|
+
name = 'Git Pretty Log'
|
|
192
|
+
aliases = ['git-pretty-log']
|
|
193
|
+
version_added = '1.0'
|
|
194
|
+
|
|
195
|
+
_branch_line = r'([\|\\\/ _]*)'
|
|
196
|
+
_letters = r'0-9A-Za-zÀ-ÖØ-öø-ÿ'
|
|
197
|
+
_log_re = re.compile(''.join([
|
|
198
|
+
_branch_line, # 1. Branch line
|
|
199
|
+
r'(\*)', # 2. Commit asterisk
|
|
200
|
+
_branch_line, # 3. Branch line
|
|
201
|
+
r'( +)', # 4. Space
|
|
202
|
+
r'([a-f0-9]+)', # 5. Commit hash
|
|
203
|
+
r'( +)', # 6. Space
|
|
204
|
+
r'(-)', # 7. Commit separator
|
|
205
|
+
r'( +)', # 8. Space
|
|
206
|
+
rf'(\([{_letters} ]+\))', # 9. Date
|
|
207
|
+
r'(\s+)', # 10. Space
|
|
208
|
+
r'([^\n]+)', # 11. Commit message
|
|
209
|
+
r'( +)', # 12. Space
|
|
210
|
+
r'(-)', # 13. Commit separator
|
|
211
|
+
r'( +)', # 14. Space
|
|
212
|
+
rf'([{_letters} ]*[{_letters}]+)', # 15. Author
|
|
213
|
+
r'( *)', # 16. Space
|
|
214
|
+
r'(\([\w ->,:/.]+\))?', # 17. Refs
|
|
215
|
+
r'( *)', # 18. Space
|
|
216
|
+
r'(#[^\n]*)?', # 19. Comment
|
|
217
|
+
r'\n',
|
|
218
|
+
]))
|
|
219
|
+
_branch_line_re = re.compile(_branch_line + r'\n?$')
|
|
220
|
+
|
|
221
|
+
_log_tokens = {
|
|
222
|
+
1: Token.Git.BranchLine,
|
|
223
|
+
3: Token.Git.BranchLine,
|
|
224
|
+
4: Whitespace,
|
|
225
|
+
5: Token.Git.CommitHash,
|
|
226
|
+
6: Whitespace,
|
|
227
|
+
8: Whitespace,
|
|
228
|
+
9: Token.Git.CommitDate,
|
|
229
|
+
10: Whitespace,
|
|
230
|
+
11: Token.Git.CommitMessage,
|
|
231
|
+
12: Whitespace,
|
|
232
|
+
14: Whitespace,
|
|
233
|
+
15: Token.Git.CommitAuthor,
|
|
234
|
+
16: Whitespace,
|
|
235
|
+
17: Token.Git.Refs,
|
|
236
|
+
18: Whitespace,
|
|
237
|
+
19: Comment,
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
def get_tokens_unprocessed(self, text):
|
|
241
|
+
for match in line_re.finditer(text):
|
|
242
|
+
line = match.group()
|
|
243
|
+
start = match.start()
|
|
244
|
+
|
|
245
|
+
match_log = self._log_re.match(line)
|
|
246
|
+
if match_log:
|
|
247
|
+
for i in range(1, self._log_re.groups + 1):
|
|
248
|
+
if match_log.group(i):
|
|
249
|
+
token = self._log_tokens.get(i, Generic.Output)
|
|
250
|
+
yield start + match_log.start(i), token, match_log.group(i)
|
|
251
|
+
yield start + match_log.end() - 1, Whitespace, '\n'
|
|
252
|
+
elif self._branch_line_re.match(line):
|
|
253
|
+
yield start, Token.Git.BranchLine, line
|
|
254
|
+
else:
|
|
255
|
+
yield start, Generic.Output, line
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
class GitBranchLexer(RegexLexer):
|
|
259
|
+
"""Output of `git branch`: highlights the current branch."""
|
|
260
|
+
|
|
261
|
+
name = 'Git Branch'
|
|
262
|
+
aliases = ['git-branch']
|
|
263
|
+
version_added = '1.0'
|
|
264
|
+
|
|
265
|
+
tokens = {
|
|
266
|
+
'root': [
|
|
267
|
+
(r'^\n', Whitespace),
|
|
268
|
+
(r'^(\* )(.*?)(\n)', bygroups(
|
|
269
|
+
using(GitLexer), Token.Git.Refs.Branch, Whitespace,
|
|
270
|
+
)),
|
|
271
|
+
(r'^.*\n', using(GitLexer)),
|
|
272
|
+
],
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
class GitMergeLexer(RegexLexer):
|
|
277
|
+
"""Diffstat output, as printed by `git merge`, `git pull`, `--stat`..."""
|
|
278
|
+
|
|
279
|
+
name = 'Git Merge'
|
|
280
|
+
aliases = ['git-merge', 'git-stat']
|
|
281
|
+
version_added = '1.0'
|
|
282
|
+
|
|
283
|
+
tokens = {
|
|
284
|
+
'root': [
|
|
285
|
+
(r'^\n', Whitespace),
|
|
286
|
+
(r'^( \S+ +\| +\d+ )(\+*)(\-*)(\n)', bygroups(
|
|
287
|
+
Generic.Output, Generic.Inserted, Generic.Deleted, Whitespace,
|
|
288
|
+
)),
|
|
289
|
+
(r'^.*\n', using(GitLexer)),
|
|
290
|
+
],
|
|
291
|
+
}
|