mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-22 16:48:23 +01:00
compgen hasmore
This commit is contained in:
parent
fbb523aed8
commit
d4528d1c42
@ -11,6 +11,7 @@ import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
@ -364,6 +365,19 @@ func (*ResponsePacketType) GetResponseDone() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (p *ResponsePacketType) Err() error {
|
||||
if p == nil {
|
||||
return fmt.Errorf("no response received")
|
||||
}
|
||||
if !p.Success {
|
||||
if p.Error != "" {
|
||||
return errors.New(p.Error)
|
||||
}
|
||||
return fmt.Errorf("rpc failed")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func MakeErrorResponsePacket(reqId string, err error) *ResponsePacketType {
|
||||
return &ResponsePacketType{Type: ResponsePacketStr, RespId: reqId, Error: err.Error()}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ func (m *MServer) runCompGen(compPk *packet.CompGenPacketType) {
|
||||
m.Sender.SendErrorResponse(reqId, fmt.Errorf("invalid compgen type '%s'", compPk.CompType))
|
||||
return
|
||||
}
|
||||
compGenCmdStr := fmt.Sprintf("cd %s; compgen -A %s -- %s | head -n %d", shellescape.Quote(compPk.Cwd), shellescape.Quote(compPk.CompType), shellescape.Quote(compPk.Prefix), packet.MaxCompGenValues)
|
||||
compGenCmdStr := fmt.Sprintf("cd %s; compgen -A %s -- %s | head -n %d", shellescape.Quote(compPk.Cwd), shellescape.Quote(compPk.CompType), shellescape.Quote(compPk.Prefix), packet.MaxCompGenValues+1)
|
||||
ecmd := exec.Command("bash", "-c", compGenCmdStr)
|
||||
outputBytes, err := ecmd.Output()
|
||||
if err != nil {
|
||||
@ -69,7 +69,12 @@ func (m *MServer) runCompGen(compPk *packet.CompGenPacketType) {
|
||||
if len(parts) > 0 && parts[len(parts)-1] == "" {
|
||||
parts = parts[0 : len(parts)-1]
|
||||
}
|
||||
m.Sender.SendResponse(reqId, map[string]interface{}{"comps": parts})
|
||||
hasMore := false
|
||||
if len(parts) > packet.MaxCompGenValues {
|
||||
hasMore = true
|
||||
parts = parts[0:packet.MaxCompGenValues]
|
||||
}
|
||||
m.Sender.SendResponse(reqId, map[string]interface{}{"comps": parts, "hasmore": hasMore})
|
||||
return
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user