mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
view/edit, fix wsh editor (this is the one for EDITOR var)
This commit is contained in:
parent
9d344b899d
commit
0084f8eb97
@ -16,33 +16,21 @@ import (
|
||||
|
||||
var editMagnified bool
|
||||
|
||||
var editCmd = &cobra.Command{
|
||||
Use: "edit",
|
||||
Short: "edit a file",
|
||||
var editorCmd = &cobra.Command{
|
||||
Use: "editor",
|
||||
Short: "edit a file (blocks until editor is closed)",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: editRun,
|
||||
Run: editorRun,
|
||||
PreRunE: preRunSetupRpcClient,
|
||||
}
|
||||
|
||||
func init() {
|
||||
editCmd.Flags().BoolVarP(&editMagnified, "magnified", "m", false, "open view in magnified mode")
|
||||
rootCmd.AddCommand(editCmd)
|
||||
rootCmd.AddCommand(editorCmd)
|
||||
}
|
||||
|
||||
func editRun(cmd *cobra.Command, args []string) {
|
||||
func editorRun(cmd *cobra.Command, args []string) {
|
||||
fileArg := args[0]
|
||||
wshCmd := wshrpc.CommandCreateBlockData{
|
||||
BlockDef: &waveobj.BlockDef{
|
||||
Meta: map[string]any{
|
||||
waveobj.MetaKey_View: "preview",
|
||||
waveobj.MetaKey_File: fileArg,
|
||||
},
|
||||
},
|
||||
Magnified: editMagnified,
|
||||
}
|
||||
if RpcContext.Conn != "" {
|
||||
wshCmd.BlockDef.Meta[waveobj.MetaKey_Connection] = RpcContext.Conn
|
||||
}
|
||||
absFile, err := filepath.Abs(fileArg)
|
||||
if err != nil {
|
||||
WriteStderr("[error] getting absolute path: %v\n", err)
|
||||
@ -57,6 +45,19 @@ func editRun(cmd *cobra.Command, args []string) {
|
||||
WriteStderr("[error] getting file info: %v\n", err)
|
||||
return
|
||||
}
|
||||
wshCmd := wshrpc.CommandCreateBlockData{
|
||||
BlockDef: &waveobj.BlockDef{
|
||||
Meta: map[string]any{
|
||||
waveobj.MetaKey_View: "preview",
|
||||
waveobj.MetaKey_File: absFile,
|
||||
waveobj.MetaKey_Edit: true,
|
||||
},
|
||||
},
|
||||
Magnified: editMagnified,
|
||||
}
|
||||
if RpcContext.Conn != "" {
|
||||
wshCmd.BlockDef.Meta[waveobj.MetaKey_Connection] = RpcContext.Conn
|
||||
}
|
||||
blockRef, err := wshclient.CreateBlockCommand(RpcClient, wshCmd, &wshrpc.RpcOpts{Timeout: 2000})
|
||||
if err != nil {
|
||||
WriteStderr("[error] running view command: %v\r\n", err)
|
@ -18,7 +18,15 @@ var viewMagnified bool
|
||||
|
||||
var viewCmd = &cobra.Command{
|
||||
Use: "view",
|
||||
Short: "preview a file or directory",
|
||||
Short: "preview/edit a file or directory",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: viewRun,
|
||||
PreRunE: preRunSetupRpcClient,
|
||||
}
|
||||
|
||||
var editCmd = &cobra.Command{
|
||||
Use: "edit",
|
||||
Short: "preview/edit a file or directory",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: viewRun,
|
||||
PreRunE: preRunSetupRpcClient,
|
||||
@ -27,6 +35,7 @@ var viewCmd = &cobra.Command{
|
||||
func init() {
|
||||
viewCmd.Flags().BoolVarP(&viewMagnified, "magnified", "m", false, "open view in magnified mode")
|
||||
rootCmd.AddCommand(viewCmd)
|
||||
rootCmd.AddCommand(editCmd)
|
||||
}
|
||||
|
||||
func viewRun(cmd *cobra.Command, args []string) {
|
||||
@ -67,6 +76,9 @@ func viewRun(cmd *cobra.Command, args []string) {
|
||||
},
|
||||
Magnified: viewMagnified,
|
||||
}
|
||||
if cmd.Use == "edit" {
|
||||
wshCmd.BlockDef.Meta[waveobj.MetaKey_Edit] = true
|
||||
}
|
||||
if conn != "" {
|
||||
wshCmd.BlockDef.Meta[waveobj.MetaKey_Connection] = conn
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user