Skip to content

Commit 9824787

Browse files
authored
Merge pull request #2 from hnrobert/develop
use ANSI Viewer, add dim mode selection, add glob matching, fix some known issues
2 parents c6848ef + a001d54 commit 9824787

File tree

10 files changed

+189
-122
lines changed

10 files changed

+189
-122
lines changed

.github/workflows/release.yml

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ jobs:
3232
- name: Generate Release Notes
3333
id: release_notes
3434
run: |
35-
CURRENT_TAG=${GITHUB_REF#refs/tags/}
35+
# Use the workflow input `version` as the current tag (ensure v-prefix)
36+
if [[ "${{ github.event.inputs.version }}" == v* ]]; then
37+
CURRENT_TAG=${{ github.event.inputs.version }}
38+
else
39+
CURRENT_TAG=v${{ github.event.inputs.version }}
40+
fi
3641
LAST_TAG=$(git tag --sort=-creatordate | grep -v 'beta' | head -n 1)
3742
3843
if [ -z "$LAST_TAG" ]; then
@@ -60,6 +65,8 @@ jobs:
6065
steps:
6166
- name: Checkout code
6267
uses: actions/checkout@v2
68+
with:
69+
fetch-depth: 0
6370

6471
- name: Set up Node.js
6572
uses: actions/setup-node@v2
@@ -70,7 +77,7 @@ jobs:
7077
run: |
7178
corepack enable
7279
corepack prepare pnpm@10.13.1 --activate
73-
pnpm install --frozen-lockfile
80+
pnpm install --frozen-lockfile --shamefully-hoist
7481
7582
- name: Build the extension
7683
run: pnpm run build
@@ -86,21 +93,62 @@ jobs:
8693
8794
- name: Extract tag name
8895
id: extract_tag
89-
run: echo "tag=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
96+
run: |
97+
if [[ "${{ github.event.inputs.version }}" == v* ]]; then
98+
echo "tag=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
99+
else
100+
echo "tag=v${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
101+
fi
102+
103+
- name: Bump package version and create tag with pnpm
104+
if: steps.extract_tag.outputs.tag != ''
105+
env:
106+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
107+
run: |
108+
INPUT_VERSION="${{ github.event.inputs.version }}"
109+
# Normalize semver without leading v for pnpm
110+
if [[ "$INPUT_VERSION" == v* ]]; then
111+
SEMVER=${INPUT_VERSION#v}
112+
else
113+
SEMVER=${INPUT_VERSION}
114+
fi
115+
116+
TAG=v${SEMVER}
117+
118+
# Configure git author
119+
git config user.name "github-actions[bot]"
120+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
121+
122+
# Skip if tag already exists
123+
if git rev-parse "$TAG" >/dev/null 2>&1; then
124+
echo "Tag $TAG already exists - skipping pnpm version"
125+
else
126+
pnpm version "$SEMVER"
127+
git push origin HEAD
128+
git push origin --tags
129+
fi
130+
131+
- name: Prune devDependencies (keep production deps)
132+
run: |
133+
rm -rf node_modules
134+
pnpm install --prod --frozen-lockfile --shamefully-hoist
135+
echo "Production dependencies present:" && ls -1 node_modules | head -n 50 || true
90136
91137
- name: Package the extension
92138
run: |
93139
if [[ ${{ steps.prerelease.outputs.prerelease }} == 'true' ]]; then
94-
pnpm exec vsce package --pre-release -o vscode-ansi-${{ steps.extract_tag.outputs.tag }}.vsix
140+
pnpm dlx @vscode/vsce package --no-dependencies --pre-release -o ansi-viewer-${{ steps.extract_tag.outputs.tag }}.vsix
95141
else
96-
pnpm exec vsce package -o vscode-ansi-${{ steps.extract_tag.outputs.tag }}.vsix
142+
pnpm dlx @vscode/vsce package --no-dependencies -o ansi-viewer-${{ steps.extract_tag.outputs.tag }}.vsix
97143
fi
98144
99145
- name: Create GitHub Release
100146
id: create_release
101147
uses: softprops/action-gh-release@v1
102148
with:
103-
files: vscode-ansi-${{ steps.extract_tag.outputs.tag }}.vsix
149+
tag_name: ${{ steps.extract_tag.outputs.tag }}
150+
name: ${{ steps.extract_tag.outputs.tag }}
151+
files: ansi-viewer-${{ steps.extract_tag.outputs.tag }}.vsix
104152
draft: false
105153
prerelease: ${{ steps.prerelease.outputs.prerelease }}
106154
generate_release_notes: false
@@ -111,9 +159,9 @@ jobs:
111159
- name: Publish to VSCode Marketplace
112160
run: |
113161
if [[ ${{ steps.prerelease.outputs.prerelease }} == 'true' ]]; then
114-
pnpm exec vsce publish --pre-release -p ${{ secrets.VSCE_PAT }}
162+
pnpm dlx @vscode/vsce publish --no-dependencies --pre-release -p ${{ secrets.VSCE_PAT }}
115163
else
116-
pnpm exec vsce publish -p ${{ secrets.VSCE_PAT }}
164+
pnpm dlx @vscode/vsce publish --no-dependencies -p ${{ secrets.VSCE_PAT }}
117165
fi
118166
env:
119167
NODE_AUTH_TOKEN: ${{ secrets.VSCE_PAT }}

.vscode/settings.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
1010
"typescript.tsc.autoDetect": "off",
1111
"cSpell.words": [
12-
"iliazeus"
13-
]
12+
"creatordate",
13+
"iliazeus",
14+
"softprops"
15+
],
16+
"i18n-ally.localesPaths": []
1417
}

.vscodeignore

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
1-
.vscode/**
2-
.vscode-test/**
3-
out/test/**
1+
# 忽略源码和构建配置
42
src/**
3+
tsconfig.json
4+
tsup.config.ts
5+
.eslintrc*
6+
.prettierrc*
7+
pnpm-lock.yaml
8+
pnpm-workspace.yaml
9+
10+
# 忽略 CI/CD 文件
11+
.github/**
12+
.vscode/**
513
.gitignore
6-
vsc-extension-quickstart.md
7-
**/tsconfig.json
8-
**/.eslintrc.json
9-
**/*.map
10-
**/*.ts
14+
*.yml
15+
16+
# 忽略测试文件
17+
**/test
18+
**/*.spec.*
19+
**/*.test.*
20+
**/.claude
21+
22+
# 其它你不想要的
23+
*.md

README.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
1-
# ANSI Previewer
1+
# ANSI Viewer
22

33
ANSI Color styling and previewer for your text editor.
44

5-
[![Visual Studio Marketplace](https://flat.badgen.net/vs-marketplace/i/HNRobert.vscode-ansi?icon=visualstudio)](https://marketplace.visualstudio.com/items?itemName=HNRobert.vscode-ansi)
6-
[![GitHub](https://flat.badgen.net/github/release/HNRobert/vscode-ansi?icon=github)](https://github.com/HNRobert/vscode-ansi)
5+
[![Visual Studio Marketplace](https://flat.badgen.net/vs-marketplace/i/HNRobert.ansi-viewer?icon=visualstudio)](https://marketplace.visualstudio.com/items?itemName=HNRobert.ansi-viewer)
6+
[![GitHub](https://flat.badgen.net/github/release/HNRobert/ansi-viewer?icon=github)](https://github.com/HNRobert/ansi-viewer)
77
[![MIT License](https://flat.badgen.net/badge/license/MIT/blue)](LICENSE)
8-
[![Open Issues](https://flat.badgen.net/github/open-issues/HNRobert/vscode-ansi?icon=github)](https://github.com/HNRobert/vscode-ansi/issues)
9-
[![Closed Issues](https://flat.badgen.net/github/closed-issues/HNRobert/vscode-ansi?icon=github)](https://github.com/HNRobert/vscode-ansi/issues?q=is%3Aissue+is%3Aclosed)
8+
[![Open Issues](https://flat.badgen.net/github/open-issues/HNRobert/ansi-viewer?icon=github)](https://github.com/HNRobert/ansi-viewer/issues)
9+
[![Closed Issues](https://flat.badgen.net/github/closed-issues/HNRobert/ansi-viewer?icon=github)](https://github.com/HNRobert/ansi-viewer/issues?q=is%3Aissue+is%3Aclosed)
1010

1111
> Forked from [iliazeus/vscode-ansi](https://github.com/iliazeus/vscode-ansi) and enhanced with more complete ANSI escape code and additional function support.
1212
13-
<https://github.com/user-attachments/assets/486f77fc-1d21-4315-a244-3df765640669>
13+
## Demo
14+
15+
### Enable / Disable
16+
17+
![demo1](https://github.com/user-attachments/assets/fa74dd85-6a7b-42eb-8353-67231240c557)
18+
19+
### Switch Normal / Dim / Hidden
20+
21+
![demo2](https://github.com/user-attachments/assets/4f833bf0-5304-4a4d-9135-b50b7a9a7c92)
22+
23+
### Apply matching file glob rules for workspace
24+
25+
![demo3](https://github.com/user-attachments/assets/af70205f-c33b-4197-b7d1-2c3403c6082a)
1426

1527
## Basic usage
1628

@@ -68,7 +80,7 @@ Basic colors and formatting:
6880

6981
```json
7082
{
71-
"ansiPreviewer.autoLanguageModeFiles": [
83+
"ansiViewer.autoLanguageModeFiles": [
7284
"**/*.ans",
7385
"**/*.ansi",
7486
"*.log", // All .log files in any directory
@@ -80,7 +92,6 @@ Basic colors and formatting:
8092
```
8193

8294
**Pattern support:**
83-
8495
- `*.log` - matches `.log` files in any directory (same as `**/*.log`)
8596
- `logs/*.txt` - matches `.txt` files only in `logs` folder
8697
- `build/**` - matches all files in `build` directory and subdirectories

package.json

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
{
2-
"name": "vscode-ansi",
2+
"name": "ansi-viewer",
33
"publisher": "HNRobert",
4-
"displayName": "ANSI Previewer",
4+
"displayName": "ANSI Viewer",
55
"description": "ANSI color styling and previewer for text documents",
6-
"version": "1.0.0",
6+
"version": "0.0.14",
77
"license": "MIT",
88
"repository": {
9-
"url": "https://github.com/HNRobert/vscode-ansi"
9+
"url": "https://github.com/HNRobert/ansi-viewer"
1010
},
1111
"bugs": {
12-
"url": "https://github.com/HNRobert/vscode-ansi/issues",
12+
"url": "https://github.com/HNRobert/ansi-viewer/issues",
1313
"email": "hnrobert@qq.com"
1414
},
1515
"packageManager": "pnpm@10.13.1",
1616
"icon": "images/icon.png",
1717
"engines": {
18-
"vscode": "^1.74.0"
18+
"vscode": "^1.104.0"
1919
},
2020
"categories": [
2121
"Themes",
@@ -34,42 +34,42 @@
3434
"contributes": {
3535
"commands": [
3636
{
37-
"command": "HNRobert.vscode-ansi.showPreview",
37+
"command": "HNRobert.ansi-viewer.showPreview",
3838
"title": "Open Preview",
3939
"category": "ANSI Text",
4040
"icon": "$(open-preview)"
4141
},
4242
{
43-
"command": "HNRobert.vscode-ansi.showPreviewToSide",
43+
"command": "HNRobert.ansi-viewer.showPreviewToSide",
4444
"title": "Open Preview to the Side",
4545
"category": "ANSI Text",
4646
"icon": "$(open-preview)"
4747
},
4848
{
49-
"command": "HNRobert.vscode-ansi.toggleEnable",
50-
"title": "Toggle ANSI Previewer",
49+
"command": "HNRobert.ansi-viewer.toggleEnable",
50+
"title": "Toggle ANSI Viewer",
5151
"category": "ANSI Text"
5252
}
5353
],
5454
"menus": {
5555
"editor/title": [
5656
{
57-
"command": "HNRobert.vscode-ansi.showPreviewToSide",
58-
"alt": "HNRobert.vscode-ansi.showPreview",
57+
"command": "HNRobert.ansi-viewer.showPreviewToSide",
58+
"alt": "HNRobert.ansi-viewer.showPreview",
5959
"when": "editorLangId == ansi",
6060
"group": "navigation"
6161
}
6262
]
6363
},
6464
"keybindings": [
6565
{
66-
"command": "HNRobert.vscode-ansi.showPreview",
66+
"command": "HNRobert.ansi-viewer.showPreview",
6767
"key": "shift+ctrl+v",
6868
"mac": "shift+cmd+v",
6969
"when": "editorLangId == ansi"
7070
},
7171
{
72-
"command": "HNRobert.vscode-ansi.showPreviewToSide",
72+
"command": "HNRobert.ansi-viewer.showPreviewToSide",
7373
"key": "ctrl+k v",
7474
"mac": "cmd+k v",
7575
"when": "editorLangId == ansi"
@@ -89,14 +89,14 @@
8989
}
9090
],
9191
"configuration": {
92-
"title": "ANSI Previewer",
92+
"title": "ANSI Viewer",
9393
"properties": {
94-
"ansiPreviewer.enable": {
94+
"ansiViewer.enable": {
9595
"type": "boolean",
9696
"default": true,
97-
"description": "Enable ANSI Previewer extension functionality"
97+
"description": "Enable ANSI Viewer extension functionality"
9898
},
99-
"ansiPreviewer.autoLanguageModeFiles": {
99+
"ansiViewer.autoLanguageModeFiles": {
100100
"type": "array",
101101
"items": {
102102
"type": "string"
@@ -107,7 +107,7 @@
107107
],
108108
"description": "File glob patterns for files that should automatically be set to ANSI language mode when opened. This enables ANSI escape sequence highlighting. Supports gitignore-style patterns: '*.log' matches log files in any directory, 'logs/*.txt' matches txt files in logs folder."
109109
},
110-
"ansiPreviewer.escapeSequenceDisplay": {
110+
"ansiViewer.escapeSequenceDisplay": {
111111
"type": "string",
112112
"enum": [
113113
"normal",

src/AnsiDecorationProvider.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ export class AnsiDecorationProvider implements TextEditorDecorationProvider {
6666

6767
private _provideDecorationsForAnsiLanguageType(document: TextDocument): ProviderResult<[string, Range[]][]> {
6868
const result = new Map<string, Range[]>();
69-
70-
const config = workspace.getConfiguration("ansiPreviewer");
69+
70+
const config = workspace.getConfiguration("ansiViewer");
7171
const escapeSequenceDisplay: string = config.get("escapeSequenceDisplay", "dimmed");
72-
72+
7373
for (const key of this._decorationTypes.keys()) {
7474
result.set(key, []);
7575
}
@@ -130,7 +130,7 @@ export class AnsiDecorationProvider implements TextEditorDecorationProvider {
130130
lineNumber,
131131
offset - totalEscapeLength,
132132
lineNumber,
133-
offset + length - totalEscapeLength
133+
offset + length - totalEscapeLength,
134134
);
135135

136136
const key = JSON.stringify(style);
@@ -157,12 +157,12 @@ export class AnsiDecorationProvider implements TextEditorDecorationProvider {
157157
}
158158

159159
private getEscapeSequenceDecorationType(): TextEditorDecorationType {
160-
const config = workspace.getConfiguration("ansiPreviewer");
160+
const config = workspace.getConfiguration("ansiViewer");
161161
const escapeSequenceDisplay: string = config.get("escapeSequenceDisplay", "dimmed");
162-
162+
163163
const cacheKey = `escape_${escapeSequenceDisplay}`;
164164
let decorationType = this._decorationTypes.get(cacheKey);
165-
165+
166166
if (!decorationType) {
167167
// 清理之前的转义序列装饰类型
168168
for (const [key, oldDecorationType] of this._decorationTypes.entries()) {
@@ -171,16 +171,16 @@ export class AnsiDecorationProvider implements TextEditorDecorationProvider {
171171
this._decorationTypes.delete(key);
172172
}
173173
}
174-
174+
175175
switch (escapeSequenceDisplay) {
176176
case "normal":
177177
decorationType = window.createTextEditorDecorationType({});
178178
break;
179179
case "hidden":
180-
decorationType = window.createTextEditorDecorationType({
180+
decorationType = window.createTextEditorDecorationType({
181181
opacity: "0%",
182182
// 或者使用 textDecoration 来完全隐藏
183-
textDecoration: "none; font-size: 0px;"
183+
textDecoration: "none; font-size: 0px;",
184184
});
185185
break;
186186
case "dimmed":
@@ -190,7 +190,7 @@ export class AnsiDecorationProvider implements TextEditorDecorationProvider {
190190
}
191191
this._decorationTypes.set(cacheKey, decorationType);
192192
}
193-
193+
194194
return decorationType;
195195
}
196196

@@ -199,7 +199,7 @@ export class AnsiDecorationProvider implements TextEditorDecorationProvider {
199199
if (key.startsWith("escape_")) {
200200
return this.getEscapeSequenceDecorationType();
201201
}
202-
202+
203203
let decorationType = this._decorationTypes.get(key);
204204

205205
if (decorationType) {

0 commit comments

Comments
 (0)