Skip to content

Commit 633e669

Browse files
committed
pref: display (nil) for null output in cli (#509)
1 parent 0fdb26f commit 633e669

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

backend/services/cli_service.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import (
44
"context"
55
"errors"
66
"fmt"
7-
"github.com/redis/go-redis/v9"
8-
"github.com/wailsapp/wails/v2/pkg/runtime"
97
"strings"
108
"sync"
119
"tinyrdm/backend/types"
1210
sliceutil "tinyrdm/backend/utils/slice"
1311
strutil "tinyrdm/backend/utils/string"
12+
13+
"github.com/redis/go-redis/v9"
14+
"github.com/wailsapp/wails/v2/pkg/runtime"
1415
)
1516

1617
type cliService struct {
@@ -22,8 +23,9 @@ type cliService struct {
2223
}
2324

2425
type cliOutput struct {
25-
Content []string `json:"content"` // output content
26-
Prompt string `json:"prompt,omitempty"` // new line prompt, empty if not ready to input
26+
Null bool `json:"null,omitempty"` // output content is null
27+
Content []string `json:"content,omitempty"` // output content
28+
Prompt string `json:"prompt,omitempty"` // new line prompt, empty if not ready to input
2729
}
2830

2931
var cli *cliService
@@ -55,7 +57,7 @@ func (c *cliService) runCommand(server, data string) {
5557
}
5658
}
5759

58-
c.echo(server, strutil.AnyToString(result, "", 0), true)
60+
c.echo(server, result, true)
5961
} else {
6062
c.echoError(server, err.Error())
6163
}
@@ -66,9 +68,11 @@ func (c *cliService) runCommand(server, data string) {
6668
c.echoReady(server)
6769
}
6870

69-
func (c *cliService) echo(server, data string, newLineReady bool) {
70-
output := cliOutput{
71-
Content: strings.Split(data, "\n"),
71+
func (c *cliService) echo(server string, data any, newLineReady bool) {
72+
var output cliOutput
73+
if data != nil {
74+
str := strutil.AnyToString(data, "", 0)
75+
output.Content = strings.Split(str, "\n")
7276
}
7377
if newLineReady {
7478
output.Prompt = fmt.Sprintf("%s:db%d> ", server, c.selectedDB[server])

frontend/src/components/content_value/ContentCli.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,11 +598,13 @@ const receiveTermOutput = (data) => {
598598
return
599599
}
600600
601-
const { content = [], prompt } = data || {}
602-
if (!isEmpty(content)) {
601+
const { content, prompt } = data || {}
602+
if (content instanceof Array) {
603603
for (const line of content) {
604604
termInst.write('\r\n' + line)
605605
}
606+
} else {
607+
termInst.write('\r\n\x1b[38;5;244m(nil)\x1b[0m')
606608
}
607609
if (!isEmpty(prompt)) {
608610
promptPrefix.value = prompt

0 commit comments

Comments
 (0)