Merge pull request #2997 from beekeeper-studio/fix/mongo-ansi

fix ansi output from mongosh
This commit is contained in:
Mohammad Azmi
2025-04-11 11:07:16 +07:00
committed by GitHub
3 changed files with 35 additions and 18 deletions

View File

@@ -46,6 +46,7 @@
"@mongosh/service-provider-node-driver": "^3.6.0",
"@pdanpdan/vue-keyboard-trap": "^1.0.19",
"@types/ini": "^4.1.0",
"ansi-to-html": "^0.7.2",
"axios": "^1.8.2",
"axios-retry": "^3.2.4",
"base64-url": "^2.3.3",

View File

@@ -37,6 +37,9 @@ import { keymapTypes } from "@/lib/db/types";
import { mapGetters, mapState } from 'vuex';
import { plugins } from "@/lib/editor/utils";
import { AppEvent } from '@/common/AppEvent';
import AnsiToHtml from 'ansi-to-html';
const ansiToHtml = new AnsiToHtml();
interface InitializeOptions {
userKeymap?: typeof keymapTypes[number]['value']
@@ -104,7 +107,15 @@ export default {
const lastLineNum = this.shell.lastLine();
let output = value.output;
if (typeof output === 'object') {
if (typeof output === 'string' && /\x1b\[[0-9;]*m/.test(output)) {
const html = ansiToHtml.toHtml(output);
const el = document.createElement('pre');
el.className = 'ansi-output';
el.innerHTML = html;
this.shell.addLineWidget(lastLineNum, el, { above: false });
} else if (typeof output === 'object') {
try {
const formattedOutput = JSON.stringify(output, null, 2);
@@ -361,4 +372,12 @@ export default {
}
}
.ansi-output {
user-select: text !important;
white-space: pre-wrap;
color: white;
padding: 4px;
margin: 0;
}
</style>

View File

@@ -4901,6 +4901,13 @@ ansi-styles@^6.1.0:
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-6.2.1.tgz#0e62320cf99c21afff3b3012192546aacbfb05c5"
integrity sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==
ansi-to-html@^0.7.2:
version "0.7.2"
resolved "https://registry.yarnpkg.com/ansi-to-html/-/ansi-to-html-0.7.2.tgz#a92c149e4184b571eb29a0135ca001a8e2d710cb"
integrity sha512-v6MqmEpNlxF+POuyhKkidusCHWWkaLcGRURzivcU3I9tv7k4JVhFcnukrM5Rlk2rUywdZuzYAZ+kbZqWCnfN3g==
dependencies:
entities "^2.2.0"
any-promise@^1.0.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/any-promise/-/any-promise-1.3.0.tgz#abc6afeedcea52e809cdc0376aed3ce39635d17f"
@@ -5469,11 +5476,6 @@ buffer@^6.0.3:
base64-js "^1.3.1"
ieee754 "^1.2.1"
buildcheck@~0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/buildcheck/-/buildcheck-0.0.6.tgz#89aa6e417cfd1e2196e3f8fe915eb709d2fe4238"
integrity sha512-8f9ZJCUXyT1M35Jx7MkBgmBMo3oHTTBIPLiY9xyL0pl3T5RwcPEY8cUHr5LBNfu/fk6c2T4DJZuVM/8ZZT2D2A==
builder-util-runtime@9.2.10, builder-util-runtime@^9.1.1:
version "9.2.10"
resolved "https://registry.yarnpkg.com/builder-util-runtime/-/builder-util-runtime-9.2.10.tgz#a0f7d9e214158402e78b74a745c8d9f870c604bc"
@@ -6092,13 +6094,8 @@ core-util-is@~1.0.0:
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.3.tgz#a6042d3634c2b27e9328f837b965fac83808db85"
integrity sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==
cpu-features@~0.0.10:
version "0.0.10"
resolved "https://registry.yarnpkg.com/cpu-features/-/cpu-features-0.0.10.tgz#9aae536db2710c7254d7ed67cb3cbc7d29ad79c5"
integrity sha512-9IkYqtX3YHPCzoVg1Py+o9057a3i0fp7S530UWokCSaFVTc7CwXPRiOjRjBQQ18ZCNafx78YfnG+HALxtVmOGA==
dependencies:
buildcheck "~0.0.6"
nan "^2.19.0"
"cpu-features@file:./.yarn/packages/empty-package", cpu-features@~0.0.10:
version "1.0.0"
crc-32@^1.2.0:
version "1.2.2"
@@ -6758,6 +6755,11 @@ ent@^2.2.0:
punycode "^1.4.1"
safe-regex-test "^1.1.0"
entities@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/entities/-/entities-2.2.0.tgz#098dc90ebb83d8dffa089d55256b351d34c4da55"
integrity sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A==
entities@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/entities/-/entities-4.5.0.tgz#5d268ea5e7113ec74c4d033b79ea5a35a488fb48"
@@ -9968,11 +9970,6 @@ named-placeholders@^1.1.3:
dependencies:
lru-cache "^7.14.1"
nan@^2.19.0:
version "2.22.2"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.22.2.tgz#6b504fd029fb8f38c0990e52ad5c26772fdacfbb"
integrity sha512-DANghxFkS1plDdRsX0X9pm0Z6SJNN6gBdtXfanwoZ8hooC5gosGFSBGRYHUVPz1asKA/kMRqDRdHrluZ61SpBQ==
nan@^2.20.0:
version "2.22.0"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.22.0.tgz#31bc433fc33213c97bad36404bb68063de604de3"