完善格式化输出

This commit is contained in:
fofolee 2022-04-27 00:29:13 +08:00
parent e950aa1d91
commit d755df87f2

View File

@ -61,8 +61,6 @@ const shortCodes = [
const ctlKey = utools.isMacOs() ? 'command' : 'control' const ctlKey = utools.isMacOs() ? 'command' : 'control'
const createBrowserWindow = utools.createBrowserWindow
let browserWindow
window.quickcommand = { window.quickcommand = {
// 模拟复制操作 // 模拟复制操作
simulateCopy: function() { simulateCopy: function() {
@ -418,35 +416,33 @@ window.convertFilePathToUtoolsPayload = files => files.map(file => {
let stringifyAll = item => { let stringifyAll = item => {
var cache = []; var cache = [];
var string = JSON.stringify(item, (key, value) => { var string = JSON.stringify(item, (key, value) => {
if (typeof value === 'function') return value.toString().replace(/\{[\s\S]*\}/, '{...}');
if (typeof value === 'object' && value !== null) { if (typeof value === 'object' && value !== null) {
if (cache.indexOf(value) !== -1) return if (cache.includes(value)) return value.toString()
cache.push(value); cache.push(value);
} }
return value; return value;
}, '\t') }, 2);
if (string != "{}") return string return string
else return item.toString()
} }
let parseItem = item => { let parseItem = item => {
if (typeof item == "object") { if (typeof item === "undefined") return "undefined"
if (Buffer.isBuffer(item)) { if (typeof item !== "object") return item.toString()
var bufferString = `[Buffer ${item.slice(0, 50).toString('hex').match(/\w{1,2}/g).join(" ")}` if (Object.keys(item).length == 0) return "{}"
if (item.length > 50) bufferString += `... ${(item.length / 1000).toFixed(2)}kb` if (Buffer.isBuffer(item)) {
return bufferString + ']' var bufferString = `[Buffer ${item.slice(0, 50).toString('hex').match(/\w{1,2}/g).join(" ")}`;
} else if (item instanceof ArrayBuffer) { if (item.length > 50) bufferString += `...${(item.length / 1000).toFixed(2)} kb `;
return `ArrayBuffer(${item.byteLength})` return bufferString + ']'
} else if (item instanceof Blob) { }
return `Blob {size: ${item.size}, type: "${item.type}"}` if (item instanceof ArrayBuffer) return `ArrayBuffer(${item.byteLength})`;
} else { if (item instanceof Blob) return `Blob { size: ${item.size}, type: "${item.type}" }`;
try { try {
return stringifyAll(item) return stringifyAll(item)
} catch (error) {} } catch (error) {
} console.log(error);
} else if (typeof item == "undefined") { return item.toString()
return "undefined"
} }
return item.toString()
} }
let parseStdout = stdout => stdout.map(x => parseItem(x)).join("\n") let parseStdout = stdout => stdout.map(x => parseItem(x)).join("\n")