pygments-shell-console 0.0.4__tar.gz → 0.0.6__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.0.4 → pygments_shell_console-0.0.6}/PKG-INFO +1 -1
- pygments_shell_console-0.0.6/examples/status.example +17 -0
- {pygments_shell_console-0.0.4 → pygments_shell_console-0.0.6/examples}/test.sh +1 -1
- {pygments_shell_console-0.0.4 → pygments_shell_console-0.0.6}/pyproject.toml +1 -1
- {pygments_shell_console-0.0.4 → pygments_shell_console-0.0.6}/shellconsole_lexer.py +11 -17
- pygments_shell_console-0.0.6/test/test_git_status.py +178 -0
- pygments_shell_console-0.0.4/test/test_git_status.py +0 -73
- {pygments_shell_console-0.0.4 → pygments_shell_console-0.0.6}/.github/workflows/publish-to-pypi.yml +0 -0
- {pygments_shell_console-0.0.4 → pygments_shell_console-0.0.6}/.gitignore +0 -0
- {pygments_shell_console-0.0.4 → pygments_shell_console-0.0.6}/README.md +0 -0
- {pygments_shell_console-0.0.4 → pygments_shell_console-0.0.6/examples}/test.exmpl +0 -0
- {pygments_shell_console-0.0.4 → pygments_shell_console-0.0.6}/git_lexer.py +0 -0
- {pygments_shell_console-0.0.4 → pygments_shell_console-0.0.6}/shellconsole_style.py +0 -0
- {pygments_shell_console-0.0.4 → pygments_shell_console-0.0.6}/test/__init__.py +0 -0
- {pygments_shell_console-0.0.4 → pygments_shell_console-0.0.6}/test/test_git_log.py +0 -0
- {pygments_shell_console-0.0.4 → pygments_shell_console-0.0.6}/test/test_git_show.py +0 -0
- {pygments_shell_console-0.0.4 → pygments_shell_console-0.0.6}/test/test_prompts.py +0 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
joapuiib@FP:~/01_introduccio (main) $ echo
|
|
2
|
+
joapuiib@FP:~/01_introduccio (main) $ git status
|
|
3
|
+
On branch main
|
|
4
|
+
|
|
5
|
+
Changes to be committed:
|
|
6
|
+
(use "git restore --staged <file>..." to unstage)
|
|
7
|
+
modified: README.md
|
|
8
|
+
|
|
9
|
+
joapuiib@FP:~/01_introduccio (main) $ git diff --staged
|
|
10
|
+
diff --git a/README.md b/README.md
|
|
11
|
+
index 6d747b3..f3b3b3e 100644
|
|
12
|
+
--- a/README.md
|
|
13
|
+
+++ b/README.md
|
|
14
|
+
@@ -1,2 +1,3 @@
|
|
15
|
+
# 01 - Introducció a Git
|
|
16
|
+
Estem aprenent a utilitzar Git!
|
|
17
|
+
+Aquesta és una línia nova
|
|
@@ -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 $@
|
|
@@ -49,7 +49,7 @@ class ShellConsoleLexer(Lexer):
|
|
|
49
49
|
r'(?P<command>.*\n?)' # Command
|
|
50
50
|
]
|
|
51
51
|
_ps1rgx = re.compile(r''.join(_ps1_groups))
|
|
52
|
-
print(_ps1rgx.pattern)
|
|
52
|
+
# print(_ps1rgx.pattern)
|
|
53
53
|
|
|
54
54
|
_ps1_tokens = [
|
|
55
55
|
Token.Generic.Prompt.VirtualEnv,
|
|
@@ -94,10 +94,9 @@ class ShellConsoleLexer(Lexer):
|
|
|
94
94
|
m = self._ps1rgx.match(line)
|
|
95
95
|
## If line starts with a prompt
|
|
96
96
|
if m:
|
|
97
|
-
|
|
98
|
-
# needs to be broken by prompts whenever the output lexer
|
|
99
|
-
# changes.
|
|
97
|
+
curcode = ''
|
|
100
98
|
|
|
99
|
+
# If there is output, yield it using the custom lexer
|
|
101
100
|
if output:
|
|
102
101
|
if custom_lexer:
|
|
103
102
|
for i, t, v in custom_lexer.get_tokens_unprocessed(output):
|
|
@@ -105,6 +104,7 @@ class ShellConsoleLexer(Lexer):
|
|
|
105
104
|
yield pos+i, t, v
|
|
106
105
|
else:
|
|
107
106
|
yield pos, Generic.Output, output
|
|
107
|
+
|
|
108
108
|
output = ''
|
|
109
109
|
custom_lexer = None
|
|
110
110
|
|
|
@@ -152,13 +152,6 @@ class ShellConsoleLexer(Lexer):
|
|
|
152
152
|
|
|
153
153
|
# Otherwise, we have a normal line
|
|
154
154
|
else:
|
|
155
|
-
# Add insertions to the current code
|
|
156
|
-
if insertions:
|
|
157
|
-
toks = innerlexer.get_tokens_unprocessed(curcode)
|
|
158
|
-
for i, t, v in do_insertions(insertions, toks):
|
|
159
|
-
# print(f"\n1. yielding pos={pos+i}, t={t}, v={v}")
|
|
160
|
-
yield pos+i, t, v
|
|
161
|
-
|
|
162
155
|
if 'diff' in curcode:
|
|
163
156
|
custom_lexer = difflexer
|
|
164
157
|
elif curcode.startswith('git lg'):
|
|
@@ -169,14 +162,15 @@ class ShellConsoleLexer(Lexer):
|
|
|
169
162
|
custom_lexer = gitshowlexer
|
|
170
163
|
|
|
171
164
|
output += line
|
|
165
|
+
|
|
166
|
+
if not backslash_continuation and insertions:
|
|
167
|
+
for i, t, v in do_insertions(insertions,
|
|
168
|
+
innerlexer.get_tokens_unprocessed(curcode)):
|
|
169
|
+
# print(f"\n4. yielding pos={pos+i}, t={t}, v={v}")
|
|
170
|
+
yield pos+i, t, v
|
|
171
|
+
|
|
172
172
|
insertions = []
|
|
173
|
-
curcode = ''
|
|
174
173
|
|
|
175
|
-
if insertions:
|
|
176
|
-
for i, t, v in do_insertions(insertions,
|
|
177
|
-
innerlexer.get_tokens_unprocessed(curcode)):
|
|
178
|
-
# print(f"\n4. yielding pos={pos+i}, t={t}, v={v}")
|
|
179
|
-
yield pos+i, t, v
|
|
180
174
|
if output:
|
|
181
175
|
if custom_lexer:
|
|
182
176
|
for i, t, v in custom_lexer.get_tokens_unprocessed(output):
|
|
@@ -0,0 +1,178 @@
|
|
|
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_status_modified():
|
|
7
|
+
lexer = ShellConsoleLexer()
|
|
8
|
+
text = (
|
|
9
|
+
"user@host:~/directory (main) $ git status\n"
|
|
10
|
+
"On branch main\n"
|
|
11
|
+
"\n"
|
|
12
|
+
"Changes not staged for commit:\n"
|
|
13
|
+
" (use \"git add <file>...\" to update what will be committed)\n"
|
|
14
|
+
" (use \"git restore <file>...\" to discard changes in working directory)\n"
|
|
15
|
+
" modified: README.md\n"
|
|
16
|
+
"\n"
|
|
17
|
+
"no changes added to commit (use \"git add\" and/or \"git commit -a\")\n"
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
tokens = list(lexer.get_tokens(text))
|
|
21
|
+
|
|
22
|
+
assert tokens == [
|
|
23
|
+
# Prompt
|
|
24
|
+
(Token.Generic.Prompt.UserHost, "user@host"),
|
|
25
|
+
(Token.Generic.Prompt, ":"),
|
|
26
|
+
(Token.Generic.Prompt.Directory, "~/directory"),
|
|
27
|
+
(Token.Text.Whitespace, " "),
|
|
28
|
+
(Token.Generic.Prompt.GitBranch, "(main)"),
|
|
29
|
+
(Token.Text.Whitespace, " "),
|
|
30
|
+
(Token.Generic.Prompt, "$"),
|
|
31
|
+
(Token.Text.Whitespace, " "),
|
|
32
|
+
(Token.Text, "git"),
|
|
33
|
+
(Token.Text.Whitespace, " "),
|
|
34
|
+
(Token.Text, "status"),
|
|
35
|
+
(Token.Text.Whitespace, "\n"),
|
|
36
|
+
# Status
|
|
37
|
+
(Token.Generic.Output, "On branch main\n"),
|
|
38
|
+
(Token.Text.Whitespace, "\n"),
|
|
39
|
+
(Token.Generic.Output, "Changes not staged for commit:\n"),
|
|
40
|
+
(Token.Generic.Output, " (use \"git add <file>...\" to update what will be committed)\n"),
|
|
41
|
+
(Token.Generic.Output, " (use \"git restore <file>...\" to discard changes in working directory)\n"),
|
|
42
|
+
(Token.Text.Whitespace, " "),
|
|
43
|
+
(Token.Git.Modified, "modified: README.md"),
|
|
44
|
+
(Token.Text.Whitespace, "\n"),
|
|
45
|
+
(Token.Text.Whitespace, "\n"),
|
|
46
|
+
(Token.Generic.Output, "no changes added to commit (use \"git add\" and/or \"git commit -a\")\n"),
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def test_full_git_status():
|
|
51
|
+
lexer = ShellConsoleLexer()
|
|
52
|
+
text = (
|
|
53
|
+
"user@host:~/directory (main) $ git status\n"
|
|
54
|
+
"On branch main\n"
|
|
55
|
+
"\n"
|
|
56
|
+
"No commits yet\n"
|
|
57
|
+
"\n"
|
|
58
|
+
"Untracked files:\n"
|
|
59
|
+
" (use \"git add <file>...\" to include in what will be committed)\n"
|
|
60
|
+
" README.md\n"
|
|
61
|
+
"\n"
|
|
62
|
+
"Changes not staged for commit:\n"
|
|
63
|
+
" (use \"git add <file>...\" to update what will be committed)\n"
|
|
64
|
+
" (use \"git restore <file>...\" to discard changes in working directory)\n"
|
|
65
|
+
" deleted: README.md\n"
|
|
66
|
+
" modified: mkdocs.yml\n"
|
|
67
|
+
" modified: requirements.txt\n"
|
|
68
|
+
"\n"
|
|
69
|
+
"Changes to be committed:\n"
|
|
70
|
+
" (use \"git rm --cached <file>...\" to unstage)\n"
|
|
71
|
+
" new file: README.md\n"
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
tokens = list(lexer.get_tokens(text))
|
|
75
|
+
|
|
76
|
+
assert tokens == [
|
|
77
|
+
(Token.Generic.Prompt.UserHost, "user@host"),
|
|
78
|
+
(Token.Generic.Prompt, ":"),
|
|
79
|
+
(Token.Generic.Prompt.Directory, "~/directory"),
|
|
80
|
+
(Token.Text.Whitespace, " "),
|
|
81
|
+
(Token.Generic.Prompt.GitBranch, "(main)"),
|
|
82
|
+
(Token.Text.Whitespace, " "),
|
|
83
|
+
(Token.Generic.Prompt, "$"),
|
|
84
|
+
(Token.Text.Whitespace, " "),
|
|
85
|
+
(Token.Text, "git"),
|
|
86
|
+
(Token.Text.Whitespace, " "),
|
|
87
|
+
(Token.Text, "status"),
|
|
88
|
+
(Token.Text.Whitespace, "\n"),
|
|
89
|
+
(Token.Generic.Output, "On branch main\n"),
|
|
90
|
+
(Token.Text.Whitespace, "\n"),
|
|
91
|
+
(Token.Generic.Output, "No commits yet\n"),
|
|
92
|
+
(Token.Text.Whitespace, "\n"),
|
|
93
|
+
(Token.Generic.Output, "Untracked files:\n"),
|
|
94
|
+
(Token.Generic.Output, " (use \"git add <file>...\" to include in what will be committed)\n"),
|
|
95
|
+
(Token.Text.Whitespace, " "),
|
|
96
|
+
(Token.Git.Untracked, "README.md"),
|
|
97
|
+
(Token.Text.Whitespace, "\n"),
|
|
98
|
+
(Token.Text.Whitespace, "\n"),
|
|
99
|
+
(Token.Generic.Output, "Changes not staged for commit:\n"),
|
|
100
|
+
(Token.Generic.Output, " (use \"git add <file>...\" to update what will be committed)\n"),
|
|
101
|
+
(Token.Generic.Output, " (use \"git restore <file>...\" to discard changes in working directory)\n"),
|
|
102
|
+
(Token.Text.Whitespace, " "),
|
|
103
|
+
(Token.Git.Modified, "deleted: README.md"),
|
|
104
|
+
(Token.Text.Whitespace, "\n"),
|
|
105
|
+
(Token.Text.Whitespace, " "),
|
|
106
|
+
(Token.Git.Modified, "modified: mkdocs.yml"),
|
|
107
|
+
(Token.Text.Whitespace, "\n"),
|
|
108
|
+
(Token.Text.Whitespace, " "),
|
|
109
|
+
(Token.Git.Modified, "modified: requirements.txt"),
|
|
110
|
+
(Token.Text.Whitespace, "\n"),
|
|
111
|
+
(Token.Text.Whitespace, "\n"),
|
|
112
|
+
(Token.Generic.Output, "Changes to be committed:\n"),
|
|
113
|
+
(Token.Generic.Output, " (use \"git rm --cached <file>...\" to unstage)\n"),
|
|
114
|
+
(Token.Text.Whitespace, " "),
|
|
115
|
+
(Token.Git.Staged, "new file: README.md"),
|
|
116
|
+
(Token.Text.Whitespace, "\n"),
|
|
117
|
+
]
|
|
118
|
+
|
|
119
|
+
def test_git_status_after_empty_command():
|
|
120
|
+
lexer = ShellConsoleLexer()
|
|
121
|
+
text = (
|
|
122
|
+
"user@host:~/directory (main) $ git add README.md\n"
|
|
123
|
+
"user@host:~/directory (main) $ git status\n"
|
|
124
|
+
"On branch main\n"
|
|
125
|
+
"\n"
|
|
126
|
+
"Changes not staged for commit:\n"
|
|
127
|
+
" (use \"git add <file>...\" to update what will be committed)\n"
|
|
128
|
+
" (use \"git restore <file>...\" to discard changes in working directory)\n"
|
|
129
|
+
" modified: README.md\n"
|
|
130
|
+
"\n"
|
|
131
|
+
"no changes added to commit (use \"git add\" and/or \"git commit -a\")\n"
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
tokens = list(lexer.get_tokens(text))
|
|
135
|
+
|
|
136
|
+
assert tokens == [
|
|
137
|
+
# Prompt
|
|
138
|
+
(Token.Generic.Prompt.UserHost, "user@host"),
|
|
139
|
+
(Token.Generic.Prompt, ":"),
|
|
140
|
+
(Token.Generic.Prompt.Directory, "~/directory"),
|
|
141
|
+
(Token.Text.Whitespace, " "),
|
|
142
|
+
(Token.Generic.Prompt.GitBranch, "(main)"),
|
|
143
|
+
(Token.Text.Whitespace, " "),
|
|
144
|
+
(Token.Generic.Prompt, "$"),
|
|
145
|
+
(Token.Text.Whitespace, " "),
|
|
146
|
+
(Token.Text, "git"),
|
|
147
|
+
(Token.Text.Whitespace, " "),
|
|
148
|
+
(Token.Text, "add"),
|
|
149
|
+
(Token.Text.Whitespace, " "),
|
|
150
|
+
(Token.Text, "README.md"),
|
|
151
|
+
(Token.Text.Whitespace, "\n"),
|
|
152
|
+
# Prompt
|
|
153
|
+
(Token.Generic.Prompt.UserHost, "user@host"),
|
|
154
|
+
(Token.Generic.Prompt, ":"),
|
|
155
|
+
(Token.Generic.Prompt.Directory, "~/directory"),
|
|
156
|
+
(Token.Text.Whitespace, " "),
|
|
157
|
+
(Token.Generic.Prompt.GitBranch, "(main)"),
|
|
158
|
+
(Token.Text.Whitespace, " "),
|
|
159
|
+
(Token.Generic.Prompt, "$"),
|
|
160
|
+
(Token.Text.Whitespace, " "),
|
|
161
|
+
(Token.Text, "git"),
|
|
162
|
+
(Token.Text.Whitespace, " "),
|
|
163
|
+
(Token.Text, "status"),
|
|
164
|
+
(Token.Text.Whitespace, "\n"),
|
|
165
|
+
# Status
|
|
166
|
+
(Token.Generic.Output, "On branch main\n"),
|
|
167
|
+
(Token.Text.Whitespace, "\n"),
|
|
168
|
+
(Token.Generic.Output, "Changes not staged for commit:\n"),
|
|
169
|
+
(Token.Generic.Output, " (use \"git add <file>...\" to update what will be committed)\n"),
|
|
170
|
+
(Token.Generic.Output, " (use \"git restore <file>...\" to discard changes in working directory)\n"),
|
|
171
|
+
(Token.Text.Whitespace, " "),
|
|
172
|
+
(Token.Git.Modified, "modified: README.md"),
|
|
173
|
+
(Token.Text.Whitespace, "\n"),
|
|
174
|
+
(Token.Text.Whitespace, "\n"),
|
|
175
|
+
(Token.Generic.Output, "no changes added to commit (use \"git add\" and/or \"git commit -a\")\n"),
|
|
176
|
+
]
|
|
177
|
+
|
|
178
|
+
|
|
@@ -1,73 +0,0 @@
|
|
|
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_full_git_status():
|
|
7
|
-
lexer = ShellConsoleLexer()
|
|
8
|
-
text = (
|
|
9
|
-
"user@host:~/directory (main) $ git status\n"
|
|
10
|
-
"On branch main\n"
|
|
11
|
-
"\n"
|
|
12
|
-
"No commits yet\n"
|
|
13
|
-
"\n"
|
|
14
|
-
"Untracked files:\n"
|
|
15
|
-
" (use \"git add <file>...\" to include in what will be committed)\n"
|
|
16
|
-
" README.md\n"
|
|
17
|
-
"\n"
|
|
18
|
-
"Changes not staged for commit:\n"
|
|
19
|
-
" (use \"git add <file>...\" to update what will be committed)\n"
|
|
20
|
-
" (use \"git restore <file>...\" to discard changes in working directory)\n"
|
|
21
|
-
" deleted: README.md\n"
|
|
22
|
-
" modified: mkdocs.yml\n"
|
|
23
|
-
" modified: requirements.txt\n"
|
|
24
|
-
"\n"
|
|
25
|
-
"Changes to be committed:\n"
|
|
26
|
-
" (use \"git rm --cached <file>...\" to unstage)\n"
|
|
27
|
-
" new file: README.md\n"
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
tokens = list(lexer.get_tokens(text))
|
|
31
|
-
|
|
32
|
-
assert tokens == [
|
|
33
|
-
(Token.Generic.Prompt.UserHost, "user@host"),
|
|
34
|
-
(Token.Generic.Prompt, ":"),
|
|
35
|
-
(Token.Generic.Prompt.Directory, "~/directory"),
|
|
36
|
-
(Token.Text.Whitespace, " "),
|
|
37
|
-
(Token.Generic.Prompt.GitBranch, "(main)"),
|
|
38
|
-
(Token.Text.Whitespace, " "),
|
|
39
|
-
(Token.Generic.Prompt, "$"),
|
|
40
|
-
(Token.Text.Whitespace, " "),
|
|
41
|
-
(Token.Text, "git"),
|
|
42
|
-
(Token.Text.Whitespace, " "),
|
|
43
|
-
(Token.Text, "status"),
|
|
44
|
-
(Token.Text.Whitespace, "\n"),
|
|
45
|
-
(Token.Generic.Output, "On branch main\n"),
|
|
46
|
-
(Token.Text.Whitespace, "\n"),
|
|
47
|
-
(Token.Generic.Output, "No commits yet\n"),
|
|
48
|
-
(Token.Text.Whitespace, "\n"),
|
|
49
|
-
(Token.Generic.Output, "Untracked files:\n"),
|
|
50
|
-
(Token.Generic.Output, " (use \"git add <file>...\" to include in what will be committed)\n"),
|
|
51
|
-
(Token.Text.Whitespace, " "),
|
|
52
|
-
(Token.Git.Untracked, "README.md"),
|
|
53
|
-
(Token.Text.Whitespace, "\n"),
|
|
54
|
-
(Token.Text.Whitespace, "\n"),
|
|
55
|
-
(Token.Generic.Output, "Changes not staged for commit:\n"),
|
|
56
|
-
(Token.Generic.Output, " (use \"git add <file>...\" to update what will be committed)\n"),
|
|
57
|
-
(Token.Generic.Output, " (use \"git restore <file>...\" to discard changes in working directory)\n"),
|
|
58
|
-
(Token.Text.Whitespace, " "),
|
|
59
|
-
(Token.Git.Modified, "deleted: README.md"),
|
|
60
|
-
(Token.Text.Whitespace, "\n"),
|
|
61
|
-
(Token.Text.Whitespace, " "),
|
|
62
|
-
(Token.Git.Modified, "modified: mkdocs.yml"),
|
|
63
|
-
(Token.Text.Whitespace, "\n"),
|
|
64
|
-
(Token.Text.Whitespace, " "),
|
|
65
|
-
(Token.Git.Modified, "modified: requirements.txt"),
|
|
66
|
-
(Token.Text.Whitespace, "\n"),
|
|
67
|
-
(Token.Text.Whitespace, "\n"),
|
|
68
|
-
(Token.Generic.Output, "Changes to be committed:\n"),
|
|
69
|
-
(Token.Generic.Output, " (use \"git rm --cached <file>...\" to unstage)\n"),
|
|
70
|
-
(Token.Text.Whitespace, " "),
|
|
71
|
-
(Token.Git.Staged, "new file: README.md"),
|
|
72
|
-
(Token.Text.Whitespace, "\n"),
|
|
73
|
-
]
|
{pygments_shell_console-0.0.4 → pygments_shell_console-0.0.6}/.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
|