diff --git a/backend/services/cli_service.go b/backend/services/cli_service.go index bb8c462..783ba91 100644 --- a/backend/services/cli_service.go +++ b/backend/services/cli_service.go @@ -4,13 +4,14 @@ import ( "context" "errors" "fmt" - "github.com/redis/go-redis/v9" - "github.com/wailsapp/wails/v2/pkg/runtime" "strings" "sync" "tinyrdm/backend/types" sliceutil "tinyrdm/backend/utils/slice" strutil "tinyrdm/backend/utils/string" + + "github.com/redis/go-redis/v9" + "github.com/wailsapp/wails/v2/pkg/runtime" ) type cliService struct { @@ -22,8 +23,9 @@ 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 + Null bool `json:"null,omitempty"` // output content is null + Content []string `json:"content,omitempty"` // output content + Prompt string `json:"prompt,omitempty"` // new line prompt, empty if not ready to input } var cli *cliService @@ -55,7 +57,7 @@ func (c *cliService) runCommand(server, data string) { } } - c.echo(server, strutil.AnyToString(result, "", 0), true) + c.echo(server, result, true) } else { c.echoError(server, err.Error()) } @@ -66,9 +68,11 @@ func (c *cliService) runCommand(server, data string) { c.echoReady(server) } -func (c *cliService) echo(server, data string, newLineReady bool) { - output := cliOutput{ - Content: strings.Split(data, "\n"), +func (c *cliService) echo(server string, data any, newLineReady bool) { + var output cliOutput + if data != nil { + str := strutil.AnyToString(data, "", 0) + output.Content = strings.Split(str, "\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 abeee92..7f4d9b8 100644 --- a/frontend/src/components/content_value/ContentCli.vue +++ b/frontend/src/components/content_value/ContentCli.vue @@ -598,11 +598,13 @@ const receiveTermOutput = (data) => { return } - const { content = [], prompt } = data || {} - if (!isEmpty(content)) { + const { content, prompt } = data || {} + if (content instanceof Array) { for (const line of content) { termInst.write('\r\n' + line) } + } else { + termInst.write('\r\n\x1b[38;5;244m(nil)\x1b[0m') } if (!isEmpty(prompt)) { promptPrefix.value = prompt