Skip to content

Commit 2025517

Browse files
committed
add config file
1 parent c647994 commit 2025517

4 files changed

Lines changed: 96 additions & 41 deletions

File tree

index.html

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
<div class="form-group">
1919
<label for="directory-input">代码文件夹</label>
2020
<div class="row">
21-
<div class="col col-9">
21+
<div class="col col-8">
2222
<input
2323
type="text"
2424
id="directory-input"
2525
class="form-control"
2626
/>
2727
</div>
28-
<div class="col col-3">
28+
<div class="col col-2">
2929
<button
3030
type="button"
3131
onclick="chooseDirectory()"
@@ -34,6 +34,15 @@
3434
选择文件夹
3535
</button>
3636
</div>
37+
<div class="col col-2">
38+
<button
39+
type="button"
40+
onclick="resetConfig()"
41+
class="btn btn-primary"
42+
>
43+
重置配置
44+
</button>
45+
</div>
3746
</div>
3847
</div>
3948
<div class="form-group">
@@ -43,9 +52,7 @@
4352
cols="30"
4453
rows="2"
4554
class="form-control"
46-
>
47-
(filename) => true</textarea
48-
>
55+
></textarea>
4956
</div>
5057
<div class="form-group">
5158
<button
@@ -70,7 +77,7 @@
7077
<select id="language-select" class="form-control">
7178
<option value="0">8086</option>
7279
<option value="1">C</option>
73-
<option value="2" selected>C++</option>
80+
<option value="2">C++</option>
7481
<option value="3">Java</option>
7582
<option value="4">lisp</option>
7683
<option value="5">m2</option>
@@ -85,53 +92,55 @@
8592
id="threshold"
8693
type="number"
8794
step="1"
88-
min="0"
95+
min="1"
8996
max="100"
9097
class="form-control"
91-
value="75"
9298
/>
9399
</div>
100+
<div class="form-group">
101+
<button
102+
type="button"
103+
class="btn btn-primary"
104+
onclick="processSIM()"
105+
>
106+
执行
107+
</button>
108+
</div>
109+
<label for="sim-stdout">sim-stdout</label>
110+
<pre
111+
id="sim-stdout"
112+
class="bg-light text-info"
113+
style="max-height: 300px"
114+
>
115+
Null</pre
116+
>
117+
<label for="sim-stderr">sim-stderr</label>
118+
<pre
119+
id="sim-stderr"
120+
class="bg-light text-info"
121+
style="max-height: 100px"
122+
>
123+
Null</pre
124+
>
94125
<div class="form-group">
95126
<label for="result-fliter">结果过滤器</label>
96127
<textarea
97128
id="result-fliter"
98129
cols="30"
99130
rows="5"
100131
class="form-control"
101-
>
102-
(fileAName, fileBName, percentage) => {
103-
const A = fileAName.split("-");
104-
const B = fileBName.split("-");
105-
return A[0] != B[0] && A[1] == B[1];
106-
};</textarea
107-
>
132+
></textarea>
108133
</div>
109134
<div class="form-group">
110135
<button
111136
type="button"
112137
class="btn btn-primary"
113-
onclick="processSIM()"
138+
onclick="processResultFilter()"
114139
>
115-
执行
140+
过滤
116141
</button>
117142
</div>
118143
</form>
119-
<label for="sim-stdout">sim-stdout</label>
120-
<pre
121-
id="sim-stdout"
122-
class="bg-light text-info"
123-
style="max-height: 300px"
124-
>
125-
Null</pre
126-
>
127-
<label for="sim-stderr">sim-stderr</label>
128-
<pre
129-
id="sim-stderr"
130-
class="bg-light text-info"
131-
style="max-height: 100px"
132-
>
133-
Null</pre
134-
>
135144
<!-- <div style="overflow-y: auto; max-height: 300px"> -->
136145
<table
137146
class="table table-striped table-hover"

js/index.js

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ const { dialog } = require("electron").remote;
22
const fs = require("fs");
33
const path = require("path");
44
const child_process = require("child_process");
5-
const stream = require("stream");
65
const os = require("os");
6+
const process = require("process");
7+
const configPath = path.join(process.cwd(), "config.json");
78

89
const valueToLanguage = [
910
"8086",
@@ -22,7 +23,7 @@ const valueToMonacoLanguage = [
2223
"cpp",
2324
"java",
2425
"plaintext",
25-
"plaintext",
26+
"m3",
2627
"plaintext",
2728
"pascal",
2829
"plaintext",
@@ -83,6 +84,10 @@ async function processSIM() {
8384
const err = ret.stderr.toString("utf-8");
8485
$("#sim-stdout").text(out);
8586
$("#sim-stderr").text(err);
87+
}
88+
89+
function processResultFilter() {
90+
const out = $("#sim-stdout").text();
8691
const resArr = out.split("\n");
8792
let startIndex = resArr.indexOf("\r") + 1;
8893
let tableData = [];
@@ -103,9 +108,7 @@ async function processSIM() {
103108
tableData.forEach((v) => {
104109
tableBody.append(
105110
$(
106-
`<tr onclick="diff()"><th>${v.fileAName}</th><th>${
107-
v.fileBName
108-
}</th><th>${v.similarPercentage.toString()}</th></tr>`
111+
`<tr onclick="diff()"><th>${v.fileAName}</th><th>${v.fileBName}</th><th>${v.similarPercentage}</th></tr>`
109112
)
110113
);
111114
});
@@ -132,6 +135,40 @@ function diff() {
132135
$("#diffModal").modal();
133136
}
134137

138+
function loadConfig() {
139+
const config = JSON.parse(fs.readFileSync(configPath));
140+
$("#directory-input").val(config.directory ?? "");
141+
$("#input-file-fliter").val(config.fileFilter ?? "");
142+
$("#language-select").val(config.language ?? "");
143+
$("#threshold").val(config.threshold ?? "");
144+
$("#result-fliter").val(config.resultFilter ?? "");
145+
}
146+
147+
function saveConfig(config) {
148+
fs.writeFileSync(
149+
configPath,
150+
JSON.stringify(
151+
config ?? {
152+
directory: $("#directory-input").val(),
153+
fileFilter: $("#input-file-fliter").val(),
154+
language: $("#language-select").val(),
155+
threshold: $("#threshold").val(),
156+
resultFilter: $("#result-fliter").val(),
157+
}
158+
)
159+
);
160+
}
161+
function resetConfig() {
162+
saveConfig({
163+
directory: os.homedir(),
164+
fileFilter: "(filename) => true",
165+
language: "2",
166+
threshold: 75,
167+
resultFilter: `(fileAName, fileBName, percentage) => {\n const A = fileAName.split("-");\n const B = fileBName.split("-");\n return A[0] != B[0] && A[1] == B[1];\n};`,
168+
});
169+
loadConfig();
170+
}
171+
135172
(function () {
136173
const amdLoader = require("./node_modules/monaco-editor/min/vs/loader.js");
137174
const amdRequire = amdLoader.require;
@@ -159,3 +196,12 @@ function diff() {
159196
);
160197
});
161198
})();
199+
200+
(function () {
201+
if (!fs.existsSync(configPath)) {
202+
resetConfig();
203+
} else {
204+
loadConfig();
205+
}
206+
window.onbeforeunload = () => saveConfig();
207+
})();

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "simgui",
3-
"version": "0.0.4",
3+
"version": "0.0.5",
44
"description": "SimGUI",
55
"main": "dist/main.js",
66
"scripts": {

0 commit comments

Comments
 (0)