-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
79 lines (67 loc) · 2.95 KB
/
Copy pathmain.js
File metadata and controls
79 lines (67 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
define(function (require, exports, module) {
"use strict";
const AppInit = brackets.getModule("utils/AppInit"),
CommandManager = brackets.getModule("command/CommandManager"),
Menus = brackets.getModule("command/Menus"),
ExtensionUtils = brackets.getModule("utils/ExtensionUtils"),
PanelManager = brackets.getModule("view/PanelManager"),
NodeConnector = brackets.getModule("NodeConnector");
const NODE_CONNECTOR_ID = "ext_main_shell";
let nodeConnector = NodeConnector.createNodeConnector(NODE_CONNECTOR_ID, exports);
var toolbar = require("text!html/toolbar.html");
var panelHtml = require("text!html/panel.html");
var shellPanel = PanelManager.createBottomPanel("shell.panel", $(panelHtml), 100);
shellPanel.hide();
$("#close-shell").on("click", function () {
shellPanel.hide();
});
var COMMAND_ID = "shell.toggle";
CommandManager.register("Toggle Shell", COMMAND_ID, function () {
if (shellPanel.isVisible()) {
shellPanel.hide();
} else {
shellPanel.show();
}
});
var menu = Menus.getMenu(Menus.AppMenuBar.VIEW_MENU);
menu.addMenuItem(COMMAND_ID);
$("#main-toolbar .buttons").append(toolbar);
$("#main-toolbar").on("click", function () {
if (shellPanel.isVisible()) {
shellPanel.hide();
} else {
shellPanel.show();
}
});
AppInit.appReady(function () {
ExtensionUtils.loadStyleSheet(module, "styles/main.css");
let clearCmds = ["cls", "clean", "clear"];
$("#shell-input").on("keypress", async function (e) {
if (e.key === "Enter") {
e.preventDefault();
var input = await $(this).val().trim();
$(this).val("");
if (clearCmds.includes(input)) {
$("#shell-output").html("");
} else {
let dir = "";
nodeConnector
.execPeer("execute", { input })
.then((result) => {
let msg = JSON.parse(result).msg;
dir = JSON.parse(result).dir;
$("#shell-output").append(`<div>${dir}> ${input}</div>`);
$("#shell-output").append(`<div>${msg}</div>`);
$("#shell-output").append(`<div></div>`);
})
.catch((err) => {
console.log("err", err);
$("#shell-output").append(`<div>${dir}> ${input}</div>`);
$("#shell-output").append(`<div style="color: red;">${err.message}</div>`);
$("#shell-output").append(`<div></div>`);
});
}
}
});
});
});