-
Notifications
You must be signed in to change notification settings - Fork 90
feat(windows): 为 Run 输出增加时间戳和 ANSI/级别着色 #283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+1,048
−17
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9753ec1
feat(windows): 为 Run 输出增加时间戳和 ANSI/级别着色
Rangsh 0f59876
fix(windows): 避免 ANSI 前缀导致 Run 输出重复打戳
Rangsh 682f645
fix(windows): 缓存跨 chunk 的 Run 输出前缀再打戳
Rangsh f582e47
Merge branch 'preview' into fix/275-windows-run-output-style
1lck 252634d
fix(windows): 避免数字前缀无限暂存并在 ANSI 边界裁剪输出
Rangsh a83094b
Merge branch 'preview' into fix/275-windows-run-output-style
1lck 5dad3d0
fix(windows): 让 Run ANSI 跟随主题并修好回车与短时钟分块
Rangsh aae9cbe
Merge branch 'preview' into fix/275-windows-run-output-style
1lck baf8533
Merge branch 'preview' into fix/275-windows-run-output-style
1lck 8900ea8
fix(windows): 按 range 着色并扫描完整 CSI/OSC 再裁剪
Rangsh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
windows/tauri/src/features/run/components/run-output-text.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import { useMemo, useRef, type KeyboardEvent } from "react"; | ||
| import { renderRunOutput } from "../utils/run-output-style"; | ||
|
|
||
| export function RunOutputText({ | ||
| source, | ||
| emptyLabel, | ||
| title, | ||
| }: { | ||
| source: string; | ||
| emptyLabel: string; | ||
| title: string; | ||
| }) { | ||
| const preRef = useRef<HTMLPreElement>(null); | ||
| const spans = useMemo(() => renderRunOutput(source), [source]); | ||
|
|
||
| const selectAll = () => { | ||
| const node = preRef.current; | ||
| const selection = window.getSelection(); | ||
| if (!node || !selection) return; | ||
| const range = document.createRange(); | ||
| range.selectNodeContents(node); | ||
| selection.removeAllRanges(); | ||
| selection.addRange(range); | ||
| }; | ||
|
|
||
| const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => { | ||
| if (!(event.ctrlKey || event.metaKey) || event.key.toLowerCase() !== "a") return; | ||
| event.preventDefault(); | ||
| event.stopPropagation(); | ||
| selectAll(); | ||
| }; | ||
|
|
||
| return ( | ||
| <div tabIndex={0} className="outline-none" onKeyDown={handleKeyDown}> | ||
| <div className="mb-1 font-medium text-subtle-foreground ui-text-sm">{title}</div> | ||
| {source ? ( | ||
| <pre | ||
| ref={preRef} | ||
| className="cursor-text whitespace-pre-wrap font-mono text-[12px] text-foreground select-text *:select-text" | ||
| > | ||
| {spans.map((span, index) => ( | ||
| <span key={index} className={span.className} style={span.style}> | ||
| {span.text} | ||
| </span> | ||
| ))} | ||
| </pre> | ||
| ) : ( | ||
| <pre className="cursor-text whitespace-pre-wrap font-mono text-[12px] text-foreground select-text"> | ||
| {emptyLabel} | ||
| </pre> | ||
| )} | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { describe, expect, mock, test } from "bun:test"; | ||
|
|
||
| mock.module("@/platform/tauri-core", () => ({ | ||
| invoke: mock(async () => undefined), | ||
| })); | ||
|
|
||
| const { createRunStore } = await import("./run.store"); | ||
| const { PRIMARY_SESSION_ID } = await import("../types/run.types"); | ||
|
|
||
| describe("run output session lifecycle", () => { | ||
| test("stop flushes a held prefix that never received a newline", async () => { | ||
| const store = createRunStore(); | ||
| store.getState().actions.appendOutput(PRIMARY_SESSION_ID, "\u001b[32m"); | ||
| expect(store.getState().primaryOutput).toBe(""); | ||
| await store.getState().actions.stop(PRIMARY_SESSION_ID); | ||
| expect(store.getState().primaryOutput).toBe("\u001b[32m"); | ||
| expect(store.getState().primaryRunning).toBe(false); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.