Repository navigation
feat(terminal): outputStyle.decode 把带 ANSI 转义的控制台输出解码成纯文本行和着色区间 - #44
Merged
Merged
Conversation
宿主按块发送控制台输出并回传上一次返回的状态,Core 返回去掉转义的行和 UTF-16 着色区间。支持 SGR 颜色与属性(含 256 色与真彩色)、回车改写、清行,丢弃其他控制序列与 OSC/DCS 字符串;块、行长和区间数都有上限。夹具 rust/fixtures/terminal/output-style-v1.json 供各宿主复用。
xiaoyumuxi
marked this pull request as ready for review
November 14, 2026 15:46
This was referenced Nov 14, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
关联
桌面端的 Run 窗口要像 IntelliJ IDEA 一样把构建、运行和测试输出里的 ANSI 颜色画出来(例如构建工具强制彩色输出时的
[INFO]、BUILD SUCCESS)。解析 ANSI 转义是与界面无关的通用逻辑,按“通用逻辑进 Rust Core”放在 Core;桌面端只负责按主题配色绘制。桌面端改动在配套 PR 1lck/Lithe-IDEA#1932,它先固定在本 PR 的 commitcdc0258,本 PR 合入后改为 main 上的 commit。改动
outputStyle.decode:请求是一块控制台输出text(不超过 1 MiB)和上一次返回的state(同一个控制台的第一块不传);返回本块结束的行lines(每行是去掉转义和换行符的text,加上按 UTF-16 偏移给出、升序且不重叠的着色区间spans:start、length、style)和新的state。state.line是还没结束的那一行,宿主显示在lines之后;state其余部分(当前样式、未完成的转义序列、待定的回车)对宿主不透明,下一块原样传回,传回的不是 Core 给出的state时返回invalid_request。style:可选的foreground、background({index: 0-255}或{rgb: "#rrggbb"};0–15 由宿主按主题取色,16–255 是 xterm 色立方和灰阶),以及bold、dim、italic、underline、inverse、hidden、strikethrough,未设置的字段省略。ESC [ … m)跨块、跨行保持样式:0 重置;1、2、3、4(4:0关闭)、7、8、9、21 设置属性,22–29 清除;30–37、90–97、40–47、100–107 选调色板 0–15,39、49 恢复默认;38、48 支持5;n、2;r;g;b及冒号写法38:5:n、38:2:r:g:b、38:2::r:g:b;58 读掉并忽略;无效颜色保留当前颜色。\n结束一行;\r让下一个字符改写当前行,所以\r\n是普通换行、进度条改写只留最后状态;ESC [ 2 K和紧跟回车的ESC [ K清行,ESC [ G(第 1 列)等同\r。<=>?)和带中间字节的序列、其他控制序列、OSC/DCS/SOS/PM/APC 字符串(到 BEL 或ESC \为止,OSC 8 超链接标记之间的文字保留)、其他转义,以及除 Tab 外的控制字符。rust/crates/terminal/src/style.rs,由lithe-terminal导出;Cargo.toml同步依赖与描述。protocol/command.rs(枚举和命令名)、runtime/dispatcher.rs(分发,坏请求返回invalid_request),tests/protocol.rs覆盖命令名和分发。rust/contracts/rust-core-api.md:命令表新增一行,新增 “outputStyle.decode” 一节,写明请求、状态传递、样式字段、各类序列的处理、上限和错误。rust/fixtures/terminal/output-style-v1.json:覆盖颜色与属性、256 色和真彩色、重置、跨块的转义、回车改写、清行、丢弃的序列、上限和无效请求。桌面端测试读同一份样例。验证
cargo test -p lithe-terminal -p lithe-core:全部通过(lithe-core 793 个,其余 38 个)。cargo fmt --all -- --check、cargo clippy -p lithe-terminal -p lithe-core --all-targets -- -D warnings:通过。LITHE_CORE_RUST_DIR指向本分支跑scripts/desktop/desktop-go.sh test ./...:全部通过;-race跑 workbench、core、i18n、termview 四个包:通过。不涉及插件契约、能力版本或插件函数协议,所以不需要更新协议记录。