Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

💡 Expose display-width helpers (stringWidth / charWidth)

未关闭
#72 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
68/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
冷清
技术栈
c, typescript, wasm

调研方向

从 mod.ts 和 test/string-width.test.ts 开始,然后检查 src/wcwidth.h 中现有的表以及 Makefile:12 处的 wasm 导出设置。使用链接的 string-width 测试和 diff 来理解预期行为,包括 ANSI 序列和 codepoint;当 width helpers 被公开提供且测试通过时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

enhancement high priority

Is your feature request related to a problem?

The C layer already measures the display width of a character and of a whole string—it's how text gets laid out—but that isn't surfaced to consumers. There are real use cases for measuring text JS-side (truncating to a column budget, padding or aligning labels) with no way to do it today short of a throwaway render.

Describe the solution you'd like

Expose two pure helpers (exact names TBD), backed by the internal wcwidth table:

charWidth(0x4f60); // 2  (CJK)
stringWidth("你好"); // 4

charWidth returns 0/1/2; stringWidth sums codepoints with proper handling for ANSI escape sequences.

Describe alternatives you've considered

Add a JS-side width dependency (duplicates the table we already ship and can drift to a different Unicode version than layout uses), or render into a fit element and read back info.get(id).bounds.width (slow, and gets VS16 emoji clusters wrong).

Additional context

Failing test case on nm/repro/string-width (test · diff). The table is already in C (src/wcwidth.h:8) and exported from the wasm (Makefile:12, --export-all); this is mostly surfacing it from mod.ts.

主要语言
TypeScript
星标
42
派生
2
平均合并
21 小时 40 分钟
30 天内合并 PR
9

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

bombshell-dev/tty 的其他 Issue

查看 bombshell-dev/tty 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。