pygments-shell-console 0.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.
@@ -0,0 +1,36 @@
1
+ name: Publish Python 🐍 distributions 📦 to PyPI
2
+ on:
3
+ push:
4
+ tags:
5
+ - "*"
6
+ jobs:
7
+ build-n-publish:
8
+ runs-on: ubuntu-latest
9
+ name: Build and publish Python 🐍 distributions 📦 to PyPI
10
+ environment:
11
+ name: pypi
12
+ url: https://pypi.org/p/pygments-shell-console
13
+ permissions:
14
+ id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
15
+ steps:
16
+ - name: Set up Python 3.8
17
+ uses: actions/checkout@master
18
+ - name: Set up Python 3.8
19
+ uses: actions/setup-python@v1
20
+ with:
21
+ python-version: 3.8
22
+ - name: Install pypa/build
23
+ run: >-
24
+ python -m
25
+ pip install
26
+ build
27
+ --user
28
+ - name: Build a binary wheel and a source tarball
29
+ run: >-
30
+ python -m
31
+ build
32
+ --sdist
33
+ --wheel
34
+ --outdir dist/
35
+ - name: Publish package distributions to PyPI
36
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,162 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
110
+ .pdm.toml
111
+ .pdm-python
112
+ .pdm-build/
113
+
114
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
115
+ __pypackages__/
116
+
117
+ # Celery stuff
118
+ celerybeat-schedule
119
+ celerybeat.pid
120
+
121
+ # SageMath parsed files
122
+ *.sage.py
123
+
124
+ # Environments
125
+ .env
126
+ .venv
127
+ env/
128
+ venv/
129
+ ENV/
130
+ env.bak/
131
+ venv.bak/
132
+
133
+ # Spyder project settings
134
+ .spyderproject
135
+ .spyproject
136
+
137
+ # Rope project settings
138
+ .ropeproject
139
+
140
+ # mkdocs documentation
141
+ /site
142
+
143
+ # mypy
144
+ .mypy_cache/
145
+ .dmypy.json
146
+ dmypy.json
147
+
148
+ # Pyre type checker
149
+ .pyre/
150
+
151
+ # pytype static type analyzer
152
+ .pytype/
153
+
154
+ # Cython debug symbols
155
+ cython_debug/
156
+
157
+ # PyCharm
158
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
159
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
160
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
161
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
162
+ #.idea/
@@ -0,0 +1,15 @@
1
+ Metadata-Version: 2.3
2
+ Name: pygments-shell-console
3
+ Version: 0.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
+ ```
@@ -0,0 +1,9 @@
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
+ ```
@@ -0,0 +1,82 @@
1
+ """An example plugin lexer for Pygments."""
2
+
3
+ from pygments.lexer import Lexer
4
+ from pygments.lexer import RegexLexer, ExtendedRegexLexer, include, bygroups, \
5
+ default, using, line_re, do_insertions
6
+ from pygments.token import Token, Punctuation, Whitespace, \
7
+ Text, Comment, Operator, Keyword, Name, String, Number, Generic
8
+ from pygments.lexers.diff import DiffLexer
9
+ from pygments.token import STANDARD_TYPES
10
+
11
+ import re
12
+
13
+ __all__ = ['GitLexer']
14
+
15
+ STANDARD_TYPES.update({
16
+ Token.Git: 'git',
17
+ Token.Git.BranchLine: 'git-bl',
18
+ Token.Git.CommitHash: 'git-ch',
19
+ Token.Git.CommitDate: 'git-cd',
20
+ Token.Git.CommitMessage: 'git-cm',
21
+ Token.Git.CommitAuthor: 'git-ca',
22
+ Token.Git.Refs: 'git-r',
23
+ })
24
+
25
+ class GitLexer(Lexer):
26
+ name = "Git"
27
+ aliases = ["git"]
28
+ filenames = ['*.git']
29
+ version_added = '1.0'
30
+
31
+ _branch_line_rgx = r'([\|\\\/ ]*)'
32
+ _logrgx_groups = [
33
+ _branch_line_rgx, # Branch line
34
+ r'(\*)', # Commit asterisk
35
+ _branch_line_rgx, # Branch line
36
+ r'( +)', # Space
37
+ r'([a-f0-9]+)', # Commit hash
38
+ r'( +- +)', # Commit separator
39
+ r'(\([0-9A-Za-zÀ-ÖØ-öø-ÿ ]+\))', # Date
40
+ r'(\s+[0-9A-Za-zÀ-ÖØ-öø-ÿ \.\:\_\'\"\!\?\(\)\\\/\-]+ +- +)', # Commit message
41
+ r'([0-9A-Za-zÀ-ÖØ-öø-ÿ ]+)', # Author
42
+ r'((\([\w ->,:]+\))?)', # Refs
43
+ r'$', # End
44
+ ]
45
+
46
+ # Combine the regex patterns into a single pattern
47
+ _logrgx = re.compile(r''.join(_logrgx_groups))
48
+
49
+ _log_tokens = {
50
+ 1: Token.Git.BranchLine,
51
+ 3: Token.Git.BranchLine,
52
+ 4: Whitespace,
53
+ 5: Token.Git.CommitHash,
54
+ 7: Token.Git.CommitDate,
55
+ 8: Token.Git.CommitMessage,
56
+ 9: Token.Git.CommitAuthor,
57
+ 10: Token.Git.Refs,
58
+ }
59
+
60
+ def get_tokens_unprocessed(self, text):
61
+ pos = 0
62
+
63
+ for match in line_re.finditer(text):
64
+ line = match.group()
65
+
66
+ match_log = self._logrgx.match(line)
67
+ match_branch_line = re.match(r'^' + self._branch_line_rgx + r'$', line)
68
+
69
+ ## Line is log
70
+ if match_log:
71
+ for i in range(1, len(match_log.groups())):
72
+ if match_log.group(i):
73
+ if self._log_tokens.get(i):
74
+ yield match_log.start(i), self._log_tokens[i], match_log.group(i)
75
+ else:
76
+ yield match_log.start(i), Generic.Output, match_log.group(i)
77
+ yield match.end(), Whitespace, '\n'
78
+ elif match_branch_line:
79
+ yield match.start(), Token.Git.BranchLine, line
80
+
81
+ else:
82
+ yield match.start(), Generic.Output, line
@@ -0,0 +1,25 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "pygments-shell-console" # change this to a package name for your plugin
7
+ version = "0.0.1"
8
+ dependencies = ["pygments"]
9
+ readme = "README.md"
10
+
11
+
12
+ [project.entry-points."pygments.lexers"]
13
+ shellconsole_lexer = "shellconsole_lexer:ShellConsoleLexer"
14
+
15
+ # [project.entry-points."pygments.formatters"]
16
+ # example_formatter = "example_formatter:ExampleFormatter"
17
+
18
+ [project.entry-points."pygments.styles"]
19
+ shellconsole-style = "shellconsole_style:ShellConsoleStyle"
20
+
21
+ # [project.entry-points."pygments.filters"]
22
+ # example-filter = "example_filter:ExampleFilter"
23
+
24
+ [tool.hatch.build.targets.wheel]
25
+ packages = ["."]
@@ -0,0 +1,150 @@
1
+ """An example plugin lexer for Pygments."""
2
+
3
+ from pygments.lexer import Lexer
4
+ from pygments.lexer import RegexLexer, ExtendedRegexLexer, include, bygroups, \
5
+ default, using, line_re, do_insertions
6
+ from pygments.token import Token, Punctuation, Whitespace, \
7
+ Text, Comment, Operator, Keyword, Name, String, Number, Generic
8
+ from pygments.lexers.diff import DiffLexer
9
+ from pygments.lexers.shell import BashLexer
10
+ from pygments.lexers.diff import DiffLexer
11
+ from git_lexer import GitLexer
12
+ from pygments.token import STANDARD_TYPES
13
+
14
+ import re
15
+
16
+ __all__ = ['ShellConsoleLexer']
17
+
18
+ STANDARD_TYPES.update({
19
+ Token.Generic.Prompt.UserHost: 'gp-uh',
20
+ Token.Generic.Prompt.Directory: 'gp-d',
21
+ Token.Generic.Prompt.GitBranch: 'gp-gb',
22
+ Token.Generic.Prompt.VirtualEnv: 'gp-ve',
23
+ })
24
+
25
+ class ShellConsoleLexer(Lexer):
26
+ name = "Shell Console"
27
+ aliases = ["shellconsole", "shell-console", "shell", "console"]
28
+ filenames = ['*.sh-session', '*.shell-session']
29
+ mimetypes = ['application/x-shell-session', 'application/x-sh-session']
30
+ url = 'https://en.wikipedia.org/wiki/Unix_shell'
31
+ version_added = '1.0'
32
+
33
+ _bare_continuation = False
34
+ _venv = re.compile(r'^(\([^)]*\))(\s*)')
35
+
36
+ _ps1rgx = re.compile(
37
+ r'^\[?(?P<user_host>[^\s@]+@[^\s]+?)(?:\s+|\:)(?P<current_dir>[^\s\]]+)(?:\s+(?P<git_branch>\([^)]+\)))?\]?\s*[$#%]\s*(?P<command>.*\n?)')
38
+ _ps1_groups = [Token.Generic.Prompt.UserHost, Token.Generic.Prompt.Directory, Token.Generic.Prompt.GitBranch]
39
+
40
+
41
+ _ps2 = '> '
42
+ _innerLexerCls = BashLexer
43
+
44
+
45
+ def get_tokens_unprocessed(self, text):
46
+ innerlexer = self._innerLexerCls(**self.options)
47
+ difflexer = DiffLexer()
48
+ gitlexer = GitLexer()
49
+
50
+ pos = 0
51
+ # Bash command
52
+ curcode = ''
53
+ insertions = []
54
+ backslash_continuation = False
55
+ diff_continuation = False
56
+ git_continuation = False
57
+
58
+ for match in line_re.finditer(text):
59
+ line = match.group()
60
+
61
+ # Check for virtualenv prompt
62
+ venv_match = self._venv.match(line)
63
+ if venv_match:
64
+ venv = venv_match.group(1)
65
+ venv_whitespace = venv_match.group(2)
66
+ insertions.append((len(curcode),
67
+ [(0, Generic.Prompt.VirtualEnv, venv)]))
68
+ if venv_whitespace:
69
+ insertions.append((len(curcode),
70
+ [(0, Text, venv_whitespace)]))
71
+ line = line[venv_match.end():]
72
+
73
+ m = self._ps1rgx.match(line)
74
+ ## If line starts with a prompt
75
+ if m:
76
+ # To support output lexers (say diff output), the output
77
+ # needs to be broken by prompts whenever the output lexer
78
+ # changes.
79
+ diff_continuation = False
80
+ git_continuation = False
81
+
82
+ if not insertions:
83
+ pos = match.start()
84
+
85
+ prompt_pos = 0
86
+ for i, t in enumerate(self._ps1_groups):
87
+ if m.group(i + 1):
88
+ group_pos = m.start(i + 1)
89
+ before_content = line[prompt_pos:group_pos]
90
+ insertions.append((len(curcode), [(0, Generic.Prompt, before_content)]))
91
+
92
+ insertions.append((len(curcode), [(0, t, m.group(i + 1))]))
93
+ prompt_pos += len(before_content) + len(m.group(i+1))
94
+
95
+ group_pos = m.start(4)
96
+ before_content = line[prompt_pos:group_pos]
97
+ insertions.append((len(curcode), [(0, Generic.Prompt, before_content)]))
98
+
99
+ curcode += m.group(4)
100
+ backslash_continuation = curcode.endswith('\\\n')
101
+
102
+ # If line is a continuation of a previous line
103
+ elif backslash_continuation:
104
+ # If there is a continuation prompt, insert it
105
+ if line.startswith(self._ps2):
106
+ insertions.append((len(curcode),
107
+ [(0, Generic.Prompt,
108
+ line[:len(self._ps2)])]))
109
+ curcode += line[len(self._ps2):]
110
+ else:
111
+ curcode += line
112
+ backslash_continuation = curcode.endswith('\\\n')
113
+
114
+ # If line is a continuation of a previous line with bare_continuation
115
+ elif self._bare_continuation and line.startswith(self._ps2):
116
+ insertions.append((len(curcode),
117
+ [(0, Generic.Prompt,
118
+ line[:len(self._ps2)])]))
119
+ curcode += line[len(self._ps2):]
120
+
121
+ # Otherwise, we have a normal line
122
+ else:
123
+ # Add insertions to the current code
124
+ if insertions:
125
+ toks = innerlexer.get_tokens_unprocessed(curcode)
126
+ for i, t, v in do_insertions(insertions, toks):
127
+ # print(f"\n1. yielding pos={pos+i}, t={t}, v={v}")
128
+ yield pos+i, t, v
129
+
130
+ if line.startswith('diff ') or diff_continuation:
131
+ diff_continuation = True
132
+ for i, t, v in difflexer.get_tokens_unprocessed(line):
133
+ # print(f"\n2. yielding pos={match.start()+i}, t={t}, v={v}")
134
+ yield match.start()+i, t, v
135
+ elif curcode.startswith('git') or git_continuation:
136
+ git_continuation = True
137
+ for i, t, v in gitlexer.get_tokens_unprocessed(line):
138
+ # print(f"\n2. yielding pos={match.start()+i}, t={t}, v={v}")
139
+ yield match.start()+i, t, v
140
+ else:
141
+ # print(f"\n3. yielding pos={match.start()}, t={Generic.Output}, v={line}")
142
+ yield match.start(), Generic.Output, line
143
+ insertions = []
144
+ curcode = ''
145
+
146
+ if insertions:
147
+ for i, t, v in do_insertions(insertions,
148
+ innerlexer.get_tokens_unprocessed(curcode)):
149
+ # print(f"\n4. yielding pos={pos+i}, t={t}, v={v}")
150
+ yield pos+i, t, v
@@ -0,0 +1,23 @@
1
+ """An example plugin style for Pygments."""
2
+
3
+ from pygments.style import Style
4
+ from pygments.token import Token, Punctuation, Whitespace, \
5
+ Text, Comment, Operator, Keyword, Name, String, Number, Generic
6
+ from pygments.styles.default import DefaultStyle
7
+
8
+ class ShellConsoleStyle(Style):
9
+ styles = DefaultStyle.styles.copy()
10
+ styles.update({
11
+ Generic.Prompt.UserHost: "#008000",
12
+ Generic.Prompt.Directory: "#19177C",
13
+ Generic.Prompt.GitBranch: "#767600",
14
+ Generic.Prompt.VirtualEnv: "#800000",
15
+
16
+ Token.Git.BranchLine: "#f00",
17
+ Token.Git.CommitHash: "#00f",
18
+ Token.Git.CommitDate: "#008000",
19
+ Token.Git.CommitMessage: "#FFFFFF",
20
+ Token.Git.CommitAuthor: "#aaaaaa",
21
+ Token.Git.Refs: "#00ffff",
22
+ })
23
+ del styles[Token.Generic.Prompt]
@@ -0,0 +1,27 @@
1
+ joapuiib@FP:~/git_tutorial (main) $ echo "Hello world!"
2
+ (venv) joapuiib@FP:~/git_tutorial (main) $ git diff
3
+ diff --git a/README.md b/README.md
4
+ index 6d747b3..ff524e4 100644
5
+ --- a/README.md
6
+ +++ b/README.md
7
+ @@ -1,2 +1,4 @@
8
+ # Tutorial de Git
9
+ Estem aprenent a utilitzar Git!
10
+ +
11
+ +Hem modificat un fitxer existent.
12
+ -Hem eliminat un fitxer.
13
+ joapuiib@FP:~/git_tutorial (main) $ git push
14
+ Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
15
+ To /home/joapuiib/gitflow_example/remot
16
+ 0fb88ef..9e34bb0 develop -> develop
17
+ joapuiib@FP:~/git_tutorial (main) $ git lga
18
+ * f853946 - (7 minutes ago) README: Afegits autors - Mar (origin/feature/author)
19
+ | * cc8c388 - (9 minutes ago) LICENSE: Afegida llicència - Pau (origin/feature/license)
20
+ |/
21
+ | * 9e34bb0 - (15 minutes ago) README: Afegida descripció del projecte - Anna (HEAD -> develop, origin/develop, feature/readme, origin/feature/readme)
22
+ |/
23
+ * 0fb88ef - (29 minutes ago) 1. Primer commit - Joan Puigcerver (origin/main, origin/HEAD, main)
24
+ [user@host ~ (main)] $ echo "Hello, world!"
25
+ (venv) [user@host ~] $ echo "Hello, world!"
26
+ (example) $ ls -l
27
+