Skip to content

Commit 4f08428

Browse files
committed
add custom padding option #107
1 parent 98aba92 commit 4f08428

File tree

3 files changed

+69
-17
lines changed

3 files changed

+69
-17
lines changed

dist/main.js

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/AcodeX.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
FONT_WEIGHT,
1717
SCROLLBACK,
1818
SCROLL_SENSITIVITY,
19+
TERMINAL_PADDING,
1920
THEME_LIST,
2021
FONTS_LIST,
2122
showTerminalBtnSize,
@@ -202,6 +203,10 @@ export default class AcodeX {
202203
this._saveSetting();
203204
}
204205
}
206+
if (typeof this.settings?.terminalPadding === "undefined") {
207+
this.settings.terminalPadding = TERMINAL_PADDING;
208+
appSettings.update(false);
209+
}
205210
}
206211

207212
async init($page, cacheFile, cacheFileUrl) {
@@ -1141,6 +1146,9 @@ export default class AcodeX {
11411146
// webgl loading failed for some reason, attach with DOM renderer
11421147
this.$terminal.open(this.$terminalContent);
11431148
}
1149+
if (this.$terminal.element) {
1150+
this._setTerminalPadding(this.settings.terminalPadding);
1151+
}
11441152
if (this.settings.fontLigatures) {
11451153
this.$ligatureAddon = new LigaturesAddon();
11461154
this.$terminal.loadAddon(this.$ligatureAddon);
@@ -1697,6 +1705,7 @@ export default class AcodeX {
16971705
fontSize: FONT_SIZE,
16981706
fontFamily: FONT_FAMILY,
16991707
letterSpacing: 0,
1708+
terminalPadding: TERMINAL_PADDING,
17001709
fontWeight: FONT_WEIGHT[0],
17011710
customFontStyleSheet: "",
17021711
scrollBack: SCROLLBACK,
@@ -1743,6 +1752,23 @@ export default class AcodeX {
17431752
}
17441753
}
17451754

1755+
_setTerminalPadding(padding) {
1756+
if (!this.$terminal?.element) {
1757+
return;
1758+
}
1759+
const numericPadding = Number(padding);
1760+
const safePadding = Number.isNaN(numericPadding)
1761+
? 0
1762+
: Math.max(0, numericPadding);
1763+
const paddingValue = `${safePadding}px`;
1764+
const terminalElement = this.$terminal.element;
1765+
terminalElement.style.boxSizing = "border-box";
1766+
terminalElement.style.padding = paddingValue;
1767+
if (this.$fitAddon) {
1768+
this.fitTerminal();
1769+
}
1770+
}
1771+
17461772
_updateTerminalHeight() {
17471773
const terminalHeaderHeight = this.$terminalHeader.offsetHeight;
17481774
this.$terminalContent.style.height = `calc(100vh - ${
@@ -2302,6 +2328,20 @@ export default class AcodeX {
23022328
},
23032329
],
23042330
},
2331+
{
2332+
key: "terminalPadding",
2333+
text: "Terminal Padding",
2334+
value: this.settings.terminalPadding,
2335+
info: "Padding around the terminal content in pixels.",
2336+
prompt: "Terminal Padding",
2337+
promptType: "number",
2338+
promptOption: [
2339+
{
2340+
match: /^[0-9]+$/,
2341+
required: true,
2342+
},
2343+
],
2344+
},
23052345
{
23062346
key: "serverHost",
23072347
text: "Server Host Name",
@@ -2710,6 +2750,17 @@ export default class AcodeX {
27102750
this.settings[key] = value;
27112751
appSettings.update();
27122752
break;
2753+
case "terminalPadding": {
2754+
const parsedPadding = Number(value);
2755+
if (Number.isNaN(parsedPadding)) break;
2756+
const clampedPadding = Math.max(0, parsedPadding);
2757+
this.settings[key] = clampedPadding;
2758+
if (this.$terminal?.element) {
2759+
this._setTerminalPadding(clampedPadding);
2760+
}
2761+
appSettings.update();
2762+
break;
2763+
}
27132764
case "cursorBlink":
27142765
if (this.$terminal) {
27152766
this.$terminal.options.cursorBlink = value;

src/utils/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const FONT_WEIGHT = [
3434
];
3535
export const SCROLLBACK = 1000;
3636
export const SCROLL_SENSITIVITY = 1000;
37+
export const TERMINAL_PADDING = 0;
3738
export const showTerminalBtnSize = 35;
3839
export const showTerminalBtn = true; // to hide/unhide show terminal button
3940
export const DEFAULT_THEME = "catppuccin";

0 commit comments

Comments
 (0)