From 7b18ed0b2641c81e7313455c45fd91a2a628c2c9 Mon Sep 17 00:00:00 2001 From: Lykin <137850705+tiny-craft@users.noreply.github.com> Date: Tue, 21 Nov 2023 17:23:31 +0800 Subject: [PATCH] fix: the console output content lacks line breaks effect #80 --- backend/services/cli_service.go | 6 +++--- frontend/src/components/content_value/ContentCli.vue | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/backend/services/cli_service.go b/backend/services/cli_service.go index e419f39..779ca87 100644 --- a/backend/services/cli_service.go +++ b/backend/services/cli_service.go @@ -21,8 +21,8 @@ type cliService struct { } type cliOutput struct { - Content string `json:"content"` // output content - Prompt string `json:"prompt,omitempty"` // new line prompt, empty if not ready to input + Content []string `json:"content"` // output content + Prompt string `json:"prompt,omitempty"` // new line prompt, empty if not ready to input } var cli *cliService @@ -67,7 +67,7 @@ func (c *cliService) runCommand(server, data string) { func (c *cliService) echo(server, data string, newLineReady bool) { output := cliOutput{ - Content: data, + Content: strings.Split(data, "\n"), } if newLineReady { output.Prompt = fmt.Sprintf("%s:db%d> ", server, c.selectedDB[server]) diff --git a/frontend/src/components/content_value/ContentCli.vue b/frontend/src/components/content_value/ContentCli.vue index e6f928d..c32d7cb 100644 --- a/frontend/src/components/content_value/ContentCli.vue +++ b/frontend/src/components/content_value/ContentCli.vue @@ -351,16 +351,18 @@ const replaceTermInput = (content = '') => { /** * process receive output content - * @param {{content, prompt}} data + * @param {{content: string[], prompt: string}} data */ const receiveTermOutput = (data) => { if (termInst == null) { return } - const { content, prompt } = data || {} + const { content = [], prompt } = data || {} if (!isEmpty(content)) { - termInst.write('\r\n' + content) + for (const line of content) { + termInst.write('\r\n' + line) + } } if (!isEmpty(prompt)) { promptPrefix.value = prompt