bump to 0.1.7, add line:set

This commit is contained in:
sawka 2023-03-17 14:47:30 -07:00
parent 5bc6f1fd6c
commit 5b74117bca
3 changed files with 52 additions and 2 deletions

View File

@ -162,6 +162,7 @@ func init() {
registerCmdFn("line:purge", LinePurgeCommand) registerCmdFn("line:purge", LinePurgeCommand)
registerCmdFn("line:setheight", LineSetHeightCommand) registerCmdFn("line:setheight", LineSetHeightCommand)
registerCmdFn("line:view", LineViewCommand) registerCmdFn("line:view", LineViewCommand)
registerCmdFn("line:set", LineSetCommand)
registerCmdFn("client", ClientCommand) registerCmdFn("client", ClientCommand)
registerCmdFn("client:show", ClientShowCommand) registerCmdFn("client:show", ClientShowCommand)
@ -2041,7 +2042,7 @@ func ScreenResizeCommand(ctx context.Context, pk *scpacket.FeCommandPacketType)
} }
func LineCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.UpdatePacket, error) { func LineCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.UpdatePacket, error) {
return nil, fmt.Errorf("/line requires a subcommand: %s", formatStrs([]string{"show", "star", "hide", "purge", "setheight"}, "or", false)) return nil, fmt.Errorf("/line requires a subcommand: %s", formatStrs([]string{"show", "star", "hide", "purge", "setheight", "set"}, "or", false))
} }
func LineSetHeightCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.UpdatePacket, error) { func LineSetHeightCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.UpdatePacket, error) {
@ -2072,6 +2073,47 @@ func LineSetHeightCommand(ctx context.Context, pk *scpacket.FeCommandPacketType)
return nil, nil return nil, nil
} }
func LineSetCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.UpdatePacket, error) {
ids, err := resolveUiIds(ctx, pk, R_Session|R_Screen)
if err != nil {
return nil, err
}
if len(pk.Args) != 1 {
return nil, fmt.Errorf("/line:set requires 1 argument (linearg)")
}
lineArg := pk.Args[0]
lineId, err := sstore.FindLineIdByArg(ctx, ids.SessionId, ids.ScreenId, lineArg)
if err != nil {
return nil, fmt.Errorf("error looking up lineid: %v", err)
}
var varsUpdated []string
if renderer, found := pk.Kwargs["renderer"]; found {
if err = validateRenderer(renderer); err != nil {
return nil, fmt.Errorf("invalid renderer value: %w", err)
}
err = sstore.UpdateLineRenderer(ctx, lineId, renderer)
if err != nil {
return nil, fmt.Errorf("error changing line renderer: %v", err)
}
varsUpdated = append(varsUpdated, "renderer")
}
if len(varsUpdated) == 0 {
return nil, fmt.Errorf("/line:set requires a value to set: %s", formatStrs([]string{"renderer"}, "or", false))
}
updatedLine, err := sstore.GetLineById(ctx, ids.SessionId, ids.ScreenId, lineId)
if err != nil {
return nil, fmt.Errorf("/line:set cannot retrieve updated line: %v", err)
}
update := sstore.ModelUpdate{
Line: updatedLine,
Info: &sstore.InfoMsgType{
InfoMsg: fmt.Sprintf("line updated %s", formatStrs(varsUpdated, "and", false)),
TimeoutMs: 2000,
},
}
return update, nil
}
func LineViewCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.UpdatePacket, error) { func LineViewCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.UpdatePacket, error) {
if len(pk.Args) != 3 { if len(pk.Args) != 3 {
return nil, fmt.Errorf("usage /line:view [session] [screen] [line]") return nil, fmt.Errorf("usage /line:view [session] [screen] [line]")

View File

@ -31,7 +31,7 @@ const PromptLockFile = "prompt.lock"
const PromptDirName = "prompt" const PromptDirName = "prompt"
const PromptDevDirName = "prompt-dev" const PromptDevDirName = "prompt-dev"
const PromptAppPathVarName = "PROMPT_APP_PATH" const PromptAppPathVarName = "PROMPT_APP_PATH"
const PromptVersion = "v0.1.6" const PromptVersion = "v0.1.7"
const PromptAuthKeyFileName = "prompt.authkey" const PromptAuthKeyFileName = "prompt.authkey"
const MShellVersion = "v0.2.0" const MShellVersion = "v0.2.0"

View File

@ -1840,6 +1840,14 @@ func UpdateLineHeight(ctx context.Context, lineId string, heightVal int) error {
return nil return nil
} }
func UpdateLineRenderer(ctx context.Context, lineId string, renderer string) error {
return WithTx(ctx, func(tx *TxWrap) error {
query := `UPDATE line SET renderer = ? WHERE lineid = ?`
tx.Exec(query, renderer, lineId)
return nil
})
}
// can return nil, nil if line is not found // can return nil, nil if line is not found
func GetLineById(ctx context.Context, sessionId string, screenId string, lineId string) (*LineType, error) { func GetLineById(ctx context.Context, sessionId string, screenId string, lineId string) (*LineType, error) {
var rtn *LineType var rtn *LineType