__terminal__ output reappears after clearing the element

Aperta Adatta ai principianti
#913 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
84/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript, python
Ambito
frontend, web-dev

Direzione di ricerca

Inizia in transcrypt/modules/org/transcrypt/runtime.py, nell’implementazione di Terminal e nei binding print/input a livello di modulo collegati nell’issue. Controlla come init imposta l’elemento e come output lo riscrive da self.buffer. Il lavoro è completato quando un metodo clear() reimposta sia buffer sia il contenuto visualizzato, in modo che l’output successivo non ripristini testo obsoleto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
2.9k
Fork
218
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di TranscryptOrg/Transcrypt

Tutte le issue di TranscryptOrg/Transcrypt

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.