__terminal__ output reappears after clearing the element

未关闭 适合新手
#913 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
84/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
javascript, python
领域
frontend, web-dev

调研方向

从 transcrypt/modules/org/transcrypt/runtime.py 中的 Terminal 实现以及 issue 中链接的模块级 print/input 绑定开始。检查 init 如何设置元素,以及 output 如何从 self.buffer 重新写入该元素。完成的标准是:clear() 方法会同时重置 buffer 和显示内容,使后续输出不会恢复过时的文本。

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

描述

Problem

Output written to __terminal__ cannot be cleared. Clearing the target element from application code removes the rendered text only. The next print puts everything back.

Cause

__Terminal__ keeps the output history in self.buffer and rewrites the whole element from that buffer on every call:

https://github.com/TranscryptOrg/Transcrypt/blob/32b216bcd3cb08c81645528c1a108a78be0b2325/transcrypt/modules/org/transcrypt/__runtime__.py#L284-L288

The class offers no method to reset self.buffer. Replacing the module-level instance does not help either, because print and input are bound to the original instance when the runtime module is loaded:

https://github.com/TranscryptOrg/Transcrypt/blob/32b216bcd3cb08c81645528c1a108a78be0b2325/transcrypt/modules/org/transcrypt/__runtime__.py#L301-L304

Proposed fix

Add a clear() method that resets buffer and element together, so the buffer cannot restore stale output:

    def clear (self):
        self.buffer = ''

        if self.element:
            self.element.innerHTML = '_'

'_' is the initial content written by __init__, so clear() returns the terminal to its start state.

Workaround

Reset both parts by hand:

__terminal__.buffer = ''
__terminal__.element.innerHTML = ''

Version

Transcrypt 3.9.5

Contribution

I am happy to write the pull request for this change if the proposed approach is acceptable.

主要语言
Python
星标
2.9k
派生
218
PR 合并指标
30 天内没有已合并 PR

贡献指南

这个仓库没有索引到贡献指南

从这里开始

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

TranscryptOrg/Transcrypt 的其他 Issue

查看 TranscryptOrg/Transcrypt 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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