Skip to content

Commit 9b83d77

Browse files
committed
impl a simple and buggy teminal
1 parent 62f5aeb commit 9b83d77

File tree

10 files changed

+122
-117
lines changed

10 files changed

+122
-117
lines changed

masm-tasm/src/dosbox-api/jsdos/Jsdos.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as Jszip from "jszip";
77
import { runInWebview } from "./runInWebview";
88
import { logger } from "../logger";
99
import { isNode } from "browser-or-node";
10+
import { createTerminal } from "./utils/terminal";
1011

1112
const fs = vscode.workspace.fs;
1213

@@ -19,10 +20,11 @@ export class Jsdos implements api.Jsdos {
1920
public jszip: Jszip = new Jszip();
2021

2122
constructor(private context: vscode.ExtensionContext) {
22-
const dist = vscode.Uri.joinPath(context.extensionUri, "node_modules/emulators/build/wasm");
23+
const dist = vscode.Uri.joinPath(context.extensionUri, "node_modules/emulators/build/wasm/");
2324
this.pathPrefix = isNode ? dist.fsPath : dist.toString();
2425
this.emulators=adapted.getEmulators(this.pathPrefix)
2526
}
27+
createTerminal=createTerminal;
2628

2729
async setBundle(
2830
bundle: vscode.Uri | Uint8Array,

masm-tasm/src/dosbox-api/jsdos/main.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import * as vscode from "vscode";
2-
import { createBundle } from "../jsdos-bundle/bundle";
2+
import { createBundle } from "./utils/bundle";
3+
export{ createBundle } from "./utils/bundle";
4+
export { createTerminal } from "./utils/terminal";
35
import { Jsdos } from "../jsdos/Jsdos";
46

57
const input = "Input your url";
@@ -74,5 +76,5 @@ export function activateJSdos(context: vscode.ExtensionContext) {
7476

7577
context.subscriptions.push(disposable, disposable2);
7678

77-
return { jsdos, createBundle };
79+
return jsdos;
7880
}

masm-tasm/src/dosbox-api/jsdos/runInHost.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.
File renamed without changes.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { CommandInterface, utils } from "emulators";
2+
import * as vscode from "vscode";
3+
4+
export function createTerminal(ci: CommandInterface) {
5+
const writeEmitter = new vscode.EventEmitter<string>();
6+
const pty: vscode.Pseudoterminal = {
7+
onDidWrite: writeEmitter.event,
8+
open: () => {
9+
writeEmitter.fire(
10+
"Jsdos Terminal all changes after launch \x1b[31mwill not\x1b[0m be applied to this shell\r\n"
11+
);
12+
ci.events().onStdout((val) => {
13+
writeEmitter.fire(val);
14+
});
15+
},
16+
close: () => { },
17+
handleInput: (datas) => {
18+
console.log(datas)
19+
for (const data of datas.split("")) {
20+
if (data.charCodeAt(0) === 127) {
21+
writeEmitter.fire("<backspace>");
22+
} else {
23+
// writeEmitter.fire(data);
24+
}
25+
if (data.charCodeAt(0) === 13) {
26+
const key = utils.Keys.KBD_enter;
27+
console.log(key)
28+
ci.simulateKeyPress(257)
29+
}
30+
else {
31+
const keys = utils.string2jsdosKey(data);
32+
keys.forEach(k => ci.simulateKeyPress(...k));
33+
}
34+
}
35+
36+
},
37+
};
38+
39+
return vscode.window.createTerminal({ name: "Jsdos Terminal", pty });
40+
}

masm-tasm/src/dosbox-api/vscode-dosbox-api.impl.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { CommandInterface, Emulators,getEmulators } from "emulators";
22
import { ExtensionContext, Terminal, Uri, Webview } from "vscode";
33
import { API, Dosbox, Jsdos } from "./vscode-dosbox-api";
44
import * as Jszip from 'jszip';
5-
import {activateJSdos} from "./jsdos/main"
6-
import { CreateBundleOptions } from "./jsdos-bundle/bundle";
5+
import {activateJSdos,createBundle,createTerminal} from "./jsdos/main"
6+
import { CreateBundleOptions } from "./jsdos/utils/bundle";
77

88
export class vscodeDosboxAPI implements API {
99
emulators: Emulators;
@@ -12,14 +12,16 @@ export class vscodeDosboxAPI implements API {
1212
dosboxX: Dosbox;
1313
msdosPath: string="";
1414
commandPath: string="";
15-
createBundle:({ sample, boxConf, mount, }: CreateBundleOptions) => Promise<Jszip>
15+
createBundle=createBundle;
16+
createTerminal=createTerminal;
17+
1618

1719
constructor(context:ExtensionContext) {
18-
const { jsdos, createBundle }=activateJSdos(context);
20+
const jsdos=activateJSdos(context);
21+
this.jsdos=jsdos;
1922
this.emulators = jsdos.emulators;
2023

2124
// prefer real emulator instances when available, otherwise keep lightweight placeholders
22-
this.jsdos = jsdos;
2325
this.createBundle=createBundle;
2426
this.dosbox = (this.emulators as any).dosbox || ({} as Dosbox);
2527
this.dosboxX = (this.emulators as any).dosboxX || ({} as Dosbox);

masm-tasm/src/dosbox-api/vscode-dosbox-api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ export interface Jsdos {
7070
* @returns the vscode webview running JSDos
7171
*/
7272
runInWebview(): Promise<vscode.Webview>,
73+
74+
createTerminal(ci: CommandInterface): vscode.Terminal
7375
}
7476

7577
export interface API {
Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,64 @@
1-
//TODO
1+
import { ExtensionContext, workspace } from "vscode";
2+
import { DosEmulatorType } from "../utils/configuration";
3+
import { ActionContext, AsmResult, ExecAction, API } from "../ASM/manager";
4+
import { getFiles, uriUtils } from "../utils/util";
5+
6+
import * as conf from "../utils/configuration";
7+
import * as path from "path";
8+
import { messageCollector } from "../diagnose/messageCollector";
9+
10+
export class JsdosHost implements ExecAction {
11+
name: DosEmulatorType | DosEmulatorType[] = DosEmulatorType.jsdos;
12+
async run(context: ExtensionContext, ctx: ActionContext, api: API): Promise<AsmResult> {
13+
await api.jsdos.jszip.loadAsync(ctx.bundleData);
14+
15+
let fileInJsdos = "";
16+
if (ctx.mountMode === conf.MountMode.workspace) {
17+
for await (const f of getFiles(ctx.workspaceFolderUri)) {
18+
const rel = path.relative(ctx.workspaceFolderUri.fsPath, f.fsPath);
19+
const dst = path.posix.join('code/', rel);
20+
const _data = await workspace.fs.readFile(f);
21+
api.jsdos.jszip.file(dst, _data);
22+
}
23+
const rel = path.relative(
24+
ctx.workspaceFolderUri.fsPath,
25+
ctx.fileUri.fsPath,
26+
);
27+
fileInJsdos = "D:\\"+ rel.replace(/\//g,"\\");
28+
} else if (ctx.mountMode === conf.MountMode.single) {
29+
api.jsdos.jszip.file('code/test' + uriUtils.extname(ctx.fileUri), ctx.doc.getText());
30+
fileInJsdos = "D:\\test" + uriUtils.extname(ctx.fileUri);
31+
}
32+
33+
const fileinfo = path.parse(fileInJsdos);
34+
const autoexec = [
35+
`mount c .`,
36+
`mount d ./code`,
37+
'd:'
38+
];
39+
const before = conf.extConf.action.before;
40+
if (before) {
41+
autoexec.push(...before);
42+
}
43+
function cb(val: string) {
44+
const r = val
45+
.replace("${file}", fileInJsdos)
46+
.replace("${filename}", fileInJsdos.replace(fileinfo.ext, ""));
47+
if (val.startsWith('>')) {
48+
return r.replace(">", "");
49+
}
50+
return r;
51+
}
52+
if (ctx.actionType === conf.ActionType.run) {
53+
autoexec.push(...conf.extConf.action.run.map(cb));
54+
}
55+
if (ctx.actionType === conf.ActionType.debug) {
56+
autoexec.push(...conf.extConf.action.debug.map(cb));
57+
}
58+
api.jsdos.updateAutoexec(autoexec);
59+
const ci = await api.jsdos.runInHost();
60+
const terminal=api.jsdos.createTerminal(ci);
61+
terminal.show()
62+
throw new Error("can't get message from" + this.name);
63+
}
64+
}

masm-tasm/src/emulators/jsdosWeb.ts

Lines changed: 0 additions & 74 deletions
This file was deleted.

masm-tasm/src/emulators/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { JsdosWeb } from "./jsdosWeb";
1+
import { JsdosHost } from "./jsdosHost";
22

33
export const emulist = [
4-
new JsdosWeb(),
4+
new JsdosHost(),
55
];

0 commit comments

Comments
 (0)