hexy imported, much faster but with some integration issue
This commit is contained in:
parent
d85921a15e
commit
a0360f731b
|
@ -88,6 +88,7 @@
|
|||
"electron-localshortcut": "^3.2.1",
|
||||
"electron-squirrel-startup": "^1.0.0",
|
||||
"electron-store": "^5.1.0",
|
||||
"hexy": "^0.3.0",
|
||||
"material-design-icons": "^3.0.1",
|
||||
"materialize-css": "^1.0.0-rc.2",
|
||||
"monaco-editor": "^0.20.0",
|
||||
|
|
|
@ -4,6 +4,7 @@ const fs = require("fs");
|
|||
const path = require("path");
|
||||
const amdLoader = require("../node_modules/monaco-editor/min/vs/loader.js");
|
||||
const { dialog } = require("electron").remote;
|
||||
const hexy = require("hexy");
|
||||
|
||||
const amdRequire = amdLoader.require;
|
||||
|
||||
|
@ -13,7 +14,7 @@ const hmUnitSpanLength = 1;
|
|||
const hmUnitLength = hmUnitBytes + hmUnitSpanLength; // 3
|
||||
const hmHexPartLength = hmUnitCount * hmUnitLength;
|
||||
const hmHexPartOffset = 0 + 1;
|
||||
const hmSpanPartLength = 8;
|
||||
const hmSpanPartLength = 3;
|
||||
const hmSpanPartOffset = hmHexPartLength + 1;
|
||||
const hmStrPartLength = hmUnitCount;
|
||||
const hmStrPartOffset = hmHexPartLength + hmSpanPartLength + 1;
|
||||
|
@ -194,44 +195,6 @@ function openFile() {
|
|||
});
|
||||
}
|
||||
|
||||
function hexDump(buffer) {
|
||||
let lines = parseInt(buffer.length / hmUnitCount);
|
||||
if (buffer.length % hmUnitCount !== 0) lines++;
|
||||
let hexBuffer = buffer2Hex(buffer);
|
||||
const model = editor.getModel();
|
||||
|
||||
for (let i = 0, lineNumber = model.getLineCount(); i < lines; i++, lineNumber++) {
|
||||
let line = "";
|
||||
|
||||
let originalHex = hexBuffer.slice(
|
||||
hmHexPartLength * i,
|
||||
hmHexPartLength * (i + 1)
|
||||
);
|
||||
line = line.concat(originalHex);
|
||||
|
||||
let span = " ".repeat(
|
||||
hmSpanPartLength + hmHexPartLength - originalHex.length
|
||||
);
|
||||
line = line.concat(span);
|
||||
|
||||
let originalStr = buffer.slice(
|
||||
hmStrPartLength * i,
|
||||
hmStrPartLength * (i + 1)
|
||||
);
|
||||
line = line.concat(originalStr.toString().replace(/[^\x20-\x7E]/g, "."));
|
||||
|
||||
line = line.concat("\n");
|
||||
|
||||
// append to last line
|
||||
model.applyEdits([
|
||||
{
|
||||
range: new monaco.Range(),
|
||||
text: line,
|
||||
},
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
function openBinFile() {
|
||||
dialog
|
||||
.showOpenDialog({
|
||||
|
@ -246,7 +209,7 @@ function openBinFile() {
|
|||
let t1 = new Date();
|
||||
rs.on("data", (data) => {
|
||||
console.log("rs data");
|
||||
showHex(data);
|
||||
showHex(data, false);
|
||||
});
|
||||
rs.on("end", (data) => {
|
||||
let t2 = new Date();
|
||||
|
@ -311,40 +274,25 @@ function editorAppend(text) {
|
|||
editor.revealLine(editor.getModel().getLineCount());
|
||||
}
|
||||
|
||||
function buffer2Hex(buffer) {
|
||||
return Array.prototype.map
|
||||
.call(new Uint8Array(buffer), (x) => ("00" + x.toString(16)).slice(-2))
|
||||
.join(" ");
|
||||
}
|
||||
// function buffer2Hex(buffer) {
|
||||
// return Array.prototype.map
|
||||
// .call(new Uint8Array(buffer), (x) => ("00" + x.toString(16)).slice(-2))
|
||||
// .join(" ");
|
||||
// }
|
||||
function showHex(buffer, revealLine) {
|
||||
const text = hexy.hexy(buffer, { format: "twos", numbering: "none"});
|
||||
const model = editor.getModel();
|
||||
const lineCount = model.getLineCount();
|
||||
|
||||
function showHex(buffer) {
|
||||
let lines = parseInt(buffer.length / hmUnitCount);
|
||||
if (buffer.length % hmUnitCount !== 0) lines++;
|
||||
let hexBuffer = buffer2Hex(buffer);
|
||||
model.applyEdits([
|
||||
{
|
||||
forceMoveMarkers: true,
|
||||
range: new monaco.Range(lineCount, 1, lineCount, 1),
|
||||
text: text,
|
||||
},
|
||||
]);
|
||||
|
||||
for (let i = 0; i < lines; i++) {
|
||||
let line = "";
|
||||
|
||||
let originalHex = hexBuffer.slice(
|
||||
hmHexPartLength * i,
|
||||
hmHexPartLength * (i + 1)
|
||||
);
|
||||
line = line.concat(originalHex);
|
||||
|
||||
let span = " ".repeat(
|
||||
hmSpanPartLength + hmHexPartLength - originalHex.length
|
||||
);
|
||||
line = line.concat(span);
|
||||
|
||||
let originalStr = buffer.slice(
|
||||
hmStrPartLength * i,
|
||||
hmStrPartLength * (i + 1)
|
||||
);
|
||||
line = line.concat(originalStr.toString().replace(/[^\x20-\x7E]/g, "."));
|
||||
|
||||
line = line.concat("\n");
|
||||
editorAppend(line);
|
||||
}
|
||||
if (true === revealLine) editor.revealLine(model.getLineCount());
|
||||
}
|
||||
|
||||
function breakpointProcess(line) {
|
||||
|
@ -421,7 +369,7 @@ function showString(buffer) {
|
|||
|
||||
function processSerialData(buffer) {
|
||||
if (config.general.hexmode === true) {
|
||||
showHex(buffer);
|
||||
showHex(buffer, true);
|
||||
} else {
|
||||
showString(buffer);
|
||||
}
|
||||
|
|
|
@ -2025,6 +2025,11 @@ has-unicode@^2.0.0:
|
|||
resolved "https://registry.npm.taobao.org/has-unicode/download/has-unicode-2.0.1.tgz#e0e6fe6a28cf51138855e086d1691e771de2a8b9"
|
||||
integrity sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=
|
||||
|
||||
hexy@^0.3.0:
|
||||
version "0.3.0"
|
||||
resolved "https://registry.npm.taobao.org/hexy/download/hexy-0.3.0.tgz#53c00a95a0baf1d813040d59490eaeab45bad091"
|
||||
integrity sha1-U8AKlaC68dgTBA1ZSQ6uq0W60JE=
|
||||
|
||||
homedir-polyfill@^1.0.1:
|
||||
version "1.0.3"
|
||||
resolved "https://registry.npm.taobao.org/homedir-polyfill/download/homedir-polyfill-1.0.3.tgz#743298cef4e5af3e194161fbadcc2151d3a058e8"
|
||||
|
|
Loading…
Reference in New Issue