Skip to content

Commit d6ef70e

Browse files
author
bleeptrack
committed
Add font selection feature
1 parent 493e563 commit d6ef70e

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

examples/simple/script.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const shell = new LinuxBrowserShell(
77
vga_bios: "./v86/vgabios.bin",
88
cdrom: "./v86/image.iso",
99
initial_state: "./v86/initial-state.bin.zst",
10+
font: "monospace"
1011
},
1112
document.getElementById("screen"),
1213
)

src/index.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ export class Terminal {
1212
constructor(
1313
private id: number,
1414
private emulator: any,
15+
private options: { font?: string }
1516
) {}
1617

1718
attach(div: HTMLElement) {
1819
let term = new XTerm({
19-
fontFamily: "Iosevka Nerd Font",
20+
fontFamily: this.options.font || "monospace",
2021
})
2122
term.open(div)
2223
term.onKey((key) => {
@@ -162,22 +163,23 @@ export class LinuxBrowserShell {
162163
}
163164

164165
constructor(
165-
paths: {
166+
settings: {
166167
wasm: string
167168
bios: string
168169
vga_bios: string
169170
cdrom: string
170171
initial_state?: string
172+
font?: string
171173
},
172174
screen?: HTMLDivElement,
173175
) {
174-
this.config["wasm_path"] = paths.wasm
175-
this.config["bios"] = {url: paths.bios}
176-
this.config["vga_bios"] = {url: paths.vga_bios}
177-
this.config["cdrom"] = {url: paths.cdrom}
176+
this.config["wasm_path"] = settings.wasm
177+
this.config["bios"] = {url: settings.bios}
178+
this.config["vga_bios"] = {url: settings.vga_bios}
179+
this.config["cdrom"] = {url: settings.cdrom}
178180

179-
if (typeof paths.initial_state !== "undefined") {
180-
this.config["initial_state"] = {url: paths.initial_state}
181+
if (typeof settings.initial_state !== "undefined") {
182+
this.config["initial_state"] = {url: settings.initial_state}
181183
}
182184

183185
if (screen) {
@@ -202,10 +204,10 @@ export class LinuxBrowserShell {
202204
this.emulator = new V86Starter(this.config)
203205

204206
this.terminals = [
205-
new Terminal(0, this.emulator),
206-
new Terminal(1, this.emulator),
207-
new Terminal(2, this.emulator),
208-
new Terminal(3, this.emulator),
207+
new Terminal(0, this.emulator, { font: settings.font}),
208+
new Terminal(1, this.emulator, { font: settings.font}),
209+
new Terminal(2, this.emulator, { font: settings.font}),
210+
new Terminal(3, this.emulator, { font: settings.font}),
209211
]
210212
}
211213

0 commit comments

Comments
 (0)