Skip to content

Commit 6bf0719

Browse files
bajrangCoderclaude
andcommitted
feat: add header toggle for wrapping console lines
Long output lines scroll horizontally per line (unchanged default). A new header button wraps them instead; the choice is saved in localStorage. Also keep the >> marker from shrinking or breaking when lines wrap. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent ea807a7 commit 6bf0719

4 files changed

Lines changed: 56 additions & 0 deletions

File tree

‎changelog.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Packages such as `numpy`, `pandas` and `micropip` are now downloaded on demand when imported
77
- Errors written to stderr are now shown in red
88
- Console output can now be selected and copied
9+
- Header button to toggle line wrap in the console (remembered between sessions)
910
- Fixed Python failing to load (or staying on "loading...") on some devices
1011
- Clear error message when Python fails to load, with automatic retry on the next run
1112
- Smaller plugin size (removed stale Pyodide files)

‎plugin.zip‎

1.11 KB
Binary file not shown.

‎src/main.js‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import plugin from "../plugin.json";
22
import style from "./style.css";
33

4+
const WRAP_KEY = `${plugin.id}.wrap`;
5+
// Material "wrap_text" icon (Apache-2.0); Acode's icon font has no wrap glyph
6+
const WRAP_ICON =
7+
'<svg viewBox="0 0 24 24" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/></svg>';
8+
49
class Python {
510
#worker;
611
#onInitError;
@@ -13,6 +18,7 @@ class Python {
1318
$input = null;
1419
$page = null;
1520
$runBtn = null;
21+
$wrapBtn = null;
1622
$style = null;
1723
#codes = [];
1824
#niddle = 0;
@@ -60,6 +66,14 @@ class Python {
6066
attr: { action: "run" },
6167
onclick: this.run.bind(this),
6268
});
69+
this.$wrapBtn = tag("span", {
70+
className: "icon wrap_py",
71+
innerHTML: WRAP_ICON,
72+
attr: { action: "toggle-wrap", title: "Wrap lines", role: "button" },
73+
onclick: () => this.#setWrap(!this.$page.classList.contains("wrap")),
74+
});
75+
this.$page.header?.append(this.$wrapBtn);
76+
this.#setWrap(loadWrap());
6377
this.$style = tag("style", { textContent: style });
6478
this.$input = tag("div", {
6579
className: "print input",
@@ -159,6 +173,7 @@ class Python {
159173
this.$runBtn.remove();
160174
}
161175

176+
this.$wrapBtn?.remove();
162177
this.#worker?.terminate();
163178
editorManager.off("switch-file", this.checkRunnable.bind(this));
164179
editorManager.off("rename-file", this.checkRunnable.bind(this));
@@ -179,6 +194,14 @@ class Python {
179194
}
180195
}
181196

197+
/** Wraps long output lines instead of scrolling them horizontally */
198+
#setWrap(wrap) {
199+
this.$page.classList.toggle("wrap", wrap);
200+
this.$wrapBtn.classList.toggle("active", wrap);
201+
this.$wrapBtn.setAttribute("aria-pressed", String(wrap));
202+
saveWrap(wrap);
203+
}
204+
182205
print(res, type) {
183206
if (!this.$page.isConnected) return;
184207
const $output = tag("div", {
@@ -339,6 +362,22 @@ class Python {
339362
}
340363
}
341364

365+
function loadWrap() {
366+
try {
367+
return localStorage.getItem(WRAP_KEY) === "true";
368+
} catch {
369+
return false;
370+
}
371+
}
372+
373+
function saveWrap(wrap) {
374+
try {
375+
localStorage.setItem(WRAP_KEY, String(wrap));
376+
} catch {
377+
// the preference is a convenience, ignore storage failures
378+
}
379+
}
380+
342381
if (window.acode) {
343382
const python = new Python();
344383
acode.setPluginInit(

‎src/style.css‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
&:not(:empty) {
2424
&::before {
2525
content: ">>";
26+
flex-shrink: 0;
27+
white-space: pre;
28+
overflow-wrap: normal;
2629
padding: 0 10px 0 0;
2730
background: var(--secondary-color);
2831
position: sticky;
@@ -42,6 +45,19 @@
4245
}
4346
}
4447
}
48+
49+
&.wrap .print {
50+
white-space: pre-wrap;
51+
overflow-wrap: anywhere;
52+
}
53+
54+
.wrap_py {
55+
opacity: 0.5;
56+
57+
&.active {
58+
opacity: 1;
59+
}
60+
}
4561
}
4662

4763
@font-face {

0 commit comments

Comments
 (0)