pygments-shell-console 0.0.5__tar.gz → 0.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.
Files changed (21) hide show
  1. {pygments_shell_console-0.0.5 → pygments_shell_console-0.1}/PKG-INFO +1 -1
  2. pygments_shell_console-0.1/examples/git_lg.example +3 -0
  3. pygments_shell_console-0.1/examples/git_log.example +12 -0
  4. pygments_shell_console-0.1/examples/git_show.example +16 -0
  5. pygments_shell_console-0.1/examples/status.example +17 -0
  6. {pygments_shell_console-0.0.5 → pygments_shell_console-0.1/examples}/test.sh +1 -1
  7. {pygments_shell_console-0.0.5 → pygments_shell_console-0.1}/git_lexer.py +16 -8
  8. {pygments_shell_console-0.0.5 → pygments_shell_console-0.1}/pyproject.toml +1 -1
  9. {pygments_shell_console-0.0.5 → pygments_shell_console-0.1}/shellconsole_lexer.py +17 -20
  10. pygments_shell_console-0.1/test/test_git_log.py +64 -0
  11. pygments_shell_console-0.0.5/test/test_git_log.py → pygments_shell_console-0.1/test/test_git_pretty_log.py +58 -1
  12. pygments_shell_console-0.1/test/test_git_status.py +178 -0
  13. pygments_shell_console-0.0.5/test/test_git_status.py +0 -73
  14. {pygments_shell_console-0.0.5 → pygments_shell_console-0.1}/.github/workflows/publish-to-pypi.yml +0 -0
  15. {pygments_shell_console-0.0.5 → pygments_shell_console-0.1}/.gitignore +0 -0
  16. {pygments_shell_console-0.0.5 → pygments_shell_console-0.1}/README.md +0 -0
  17. {pygments_shell_console-0.0.5 → pygments_shell_console-0.1/examples}/test.exmpl +0 -0
  18. {pygments_shell_console-0.0.5 → pygments_shell_console-0.1}/shellconsole_style.py +0 -0
  19. {pygments_shell_console-0.0.5 → pygments_shell_console-0.1}/test/__init__.py +0 -0
  20. {pygments_shell_console-0.0.5 → pygments_shell_console-0.1}/test/test_git_show.py +0 -0
  21. {pygments_shell_console-0.0.5 → pygments_shell_console-0.1}/test/test_prompts.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: pygments-shell-console
3
- Version: 0.0.5
3
+ Version: 0.1
4
4
  Requires-Dist: pygments
5
5
  Description-Content-Type: text/markdown
6
6
 
@@ -0,0 +1,3 @@
1
+ joapuiib@FP:~/01_introduccio (main) $ git lg
2
+ * c9fc6c8 - (2 minutes ago) Added another line to README.md - Joan Puigcerver (HEAD -> main)
3
+ * 8e70293 - (3 days ago) Added README.md - Joan Puigcerver
@@ -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
@@ -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 test.exmpl $@
2
+ ./venv/bin/pygmentize -l shellconsole -O style=shellconsole-style $@
@@ -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
@@ -32,7 +32,7 @@ STANDARD_TYPES.update({
32
32
  Token.Git.Refs.Branch: 'git-b',
33
33
  })
34
34
 
35
- class GitLogLexer(Lexer):
35
+ class GitPrettyLogLexer(Lexer):
36
36
  name = "Git"
37
37
  aliases = ["git"]
38
38
  filenames = ['*.git']
@@ -54,10 +54,10 @@ class GitLogLexer(Lexer):
54
54
  r'( +)', # 12. Space
55
55
  r'(-)', # 13. Commit separator
56
56
  r'( +)', # 14. Space
57
- r'([0-9A-Za-zÀ-ÖØ-öø-ÿ ]+)', # 15. Author
58
- r'( +)', # 16. Space
59
- r'((\([\w ->,:]+\))?)', # 17. Refs
60
- r'$', # End
57
+ r'([0-9A-Za-zÀ-ÖØ-öø-ÿ ]*[0-9A-Za-zÀ-ÖØ-öø-ÿ]+)', # 15. Author
58
+ r'( *)', # 16. Space
59
+ r'((\([\w ->,:]+\))?)', # 17. Refs
60
+ r'\n', # End
61
61
  ]
62
62
 
63
63
  # Combine the regex patterns into a single pattern
@@ -142,11 +142,10 @@ class GitStatusLexer(RegexLexer):
142
142
  ],
143
143
  }
144
144
 
145
- class GitShowLexer(RegexLexer):
145
+ class GitLogLexer(RegexLexer):
146
146
  tokens = {
147
147
  'root': [
148
148
  (r'^\n', Whitespace),
149
- (r'^diff .*\n', using(DiffLexer), 'diff'),
150
149
  (r'^(commit [0-9a-f]+)', Token.Git.Show.Header, 'header'),
151
150
  (r'^.*\n', Generic.Output),
152
151
  ],
@@ -160,6 +159,15 @@ class GitShowLexer(RegexLexer):
160
159
  (r'[\w/_-]+', Token.Git.Refs.Branch),
161
160
  (r'\n', Whitespace, '#pop'),
162
161
  ],
162
+ }
163
+
164
+
165
+ class GitShowLexer(GitLogLexer):
166
+ tokens = {
167
+ 'root': [
168
+ (r'^diff .*\n', using(DiffLexer), 'diff'),
169
+ inherit
170
+ ],
163
171
  'diff': [
164
172
  (r'^.*\n', using(DiffLexer)),
165
173
  ],
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "pygments-shell-console" # change this to a package name for your plugin
7
- version = "0.0.5"
7
+ version = "0.1"
8
8
  dependencies = ["pygments"]
9
9
  readme = "README.md"
10
10
 
@@ -8,7 +8,7 @@ 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, GitStatusLexer, GitShowLexer
11
+ from git_lexer import GitLogLexer, GitPrettyLogLexer, GitStatusLexer, GitShowLexer
12
12
  from pygments.token import STANDARD_TYPES
13
13
 
14
14
  import re
@@ -75,7 +75,8 @@ class ShellConsoleLexer(Lexer):
75
75
  def get_tokens_unprocessed(self, text):
76
76
  innerlexer = self._innerLexerCls(**self.options)
77
77
  difflexer = DiffLexer()
78
- gitloglexer = GitLogLexer()
78
+ git_log_lexer = GitLogLexer()
79
+ git_pretty_log_lexer = GitPrettyLogLexer()
79
80
  gitstatuslexer = GitStatusLexer()
80
81
  gitshowlexer = GitShowLexer()
81
82
 
@@ -94,10 +95,9 @@ class ShellConsoleLexer(Lexer):
94
95
  m = self._ps1rgx.match(line)
95
96
  ## If line starts with a prompt
96
97
  if m:
97
- # To support output lexers (say diff output), the output
98
- # needs to be broken by prompts whenever the output lexer
99
- # changes.
98
+ curcode = ''
100
99
 
100
+ # If there is output, yield it using the custom lexer
101
101
  if output:
102
102
  if custom_lexer:
103
103
  for i, t, v in custom_lexer.get_tokens_unprocessed(output):
@@ -105,6 +105,7 @@ class ShellConsoleLexer(Lexer):
105
105
  yield pos+i, t, v
106
106
  else:
107
107
  yield pos, Generic.Output, output
108
+
108
109
  output = ''
109
110
  custom_lexer = None
110
111
 
@@ -152,31 +153,27 @@ class ShellConsoleLexer(Lexer):
152
153
 
153
154
  # Otherwise, we have a normal line
154
155
  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
156
  if 'diff' in curcode:
163
157
  custom_lexer = difflexer
164
- elif curcode.startswith('git lg'):
165
- custom_lexer = gitloglexer
158
+ elif curcode.startswith('git lg') or curcode.startswith('git log --graph'):
159
+ custom_lexer = git_pretty_log_lexer
160
+ elif curcode.startswith('git log'):
161
+ custom_lexer = git_log_lexer
166
162
  elif curcode.startswith('git status'):
167
163
  custom_lexer = gitstatuslexer
168
164
  elif curcode.startswith('git show'):
169
165
  custom_lexer = gitshowlexer
170
166
 
171
167
  output += line
168
+
169
+ if not backslash_continuation and insertions:
170
+ for i, t, v in do_insertions(insertions,
171
+ innerlexer.get_tokens_unprocessed(curcode)):
172
+ # print(f"\n4. yielding pos={pos+i}, t={t}, v={v}")
173
+ yield pos+i, t, v
174
+
172
175
  insertions = []
173
- curcode = ''
174
176
 
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
177
  if output:
181
178
  if custom_lexer:
182
179
  for i, t, v in custom_lexer.get_tokens_unprocessed(output):
@@ -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 GitLogLexer
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
+ ]
@@ -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
- ]