1
1
package gui
2
2
3
3
import (
4
+ "encoding/json"
4
5
"fmt"
5
6
"log"
7
+ "strings"
6
8
7
9
"fyne.io/fyne/v2"
8
10
"fyne.io/fyne/v2/container"
9
11
"fyne.io/fyne/v2/data/binding"
10
12
"fyne.io/fyne/v2/widget"
11
13
dialogWizard "github.com/KiraCore/kensho/gui/dialogs"
14
+ "github.com/KiraCore/kensho/helper/httph"
15
+ "github.com/KiraCore/kensho/types"
12
16
)
13
17
14
18
func showSekaiExecuteDialog (g * Gui ) {
15
19
var wizard * dialogWizard.Wizard
16
20
17
- cmdEntry := widget .NewEntry ()
21
+ sekaidCmdName := "/sekaid"
22
+ cmdData := binding .NewString ()
23
+ cmdEntry := widget .NewEntryWithData (cmdData )
18
24
cmdEntry .MultiLine = true
19
25
cmdEntry .Wrapping = fyne .TextWrapWord
20
26
21
27
doneAction := binding .NewDataListener (func () {
22
28
g .WaitDialog .ShowWaitDialog ()
23
29
log .Printf ("Trying to execute: %v" , cmdEntry .Text )
30
+ cmd , _ := cmdData .Get ()
31
+ cmd = strings .ReplaceAll (cmd , "\n " , " " )
32
+ cmd = fmt .Sprintf ("%v %v" , sekaidCmdName , cmd )
24
33
25
- // execute submit
34
+ cmdArgs := strings .Split (cmd , " " )
35
+ cmdArgs = RemoveEmptyAndWhitespaceStrings (cmdArgs )
36
+
37
+ cmdStruct := types.ExecSekaiCommands {Command : "sekaid" , ExecArgs : types.ExecArgs {Exec : cmdArgs }}
38
+
39
+ payload , err := json .Marshal (cmdStruct )
40
+ if err != nil {
41
+ log .Printf ("error when marshaling cmdStruct: %v" , err .Error ())
42
+ g .WaitDialog .HideWaitDialog ()
43
+ g .showErrorDialog (err , binding .NewDataListener (func () {}))
44
+ return
45
+ }
46
+
47
+ o , err := httph .ExecHttpRequestBySSHTunnel (g .sshClient , types .SEKIN_EXECUTE_ENDPOINT , "POST" , payload )
48
+ if err != nil {
49
+ log .Printf ("error when executing cmdStruct: %v" , err .Error ())
50
+ g .WaitDialog .HideWaitDialog ()
51
+ g .showErrorDialog (err , binding .NewDataListener (func () {}))
52
+ return
53
+ }
54
+
55
+ log .Printf ("output of <%v>:\n %v" , cmd , string (o ))
26
56
g .WaitDialog .HideWaitDialog ()
27
- wizard .Hide ()
57
+
58
+ showInfoDialog (g , "Out" , string (o ))
28
59
})
29
60
30
61
submitButton := widget .NewButton ("Submit" , func () {
@@ -37,14 +68,36 @@ func showSekaiExecuteDialog(g *Gui) {
37
68
wizard .Hide ()
38
69
})
39
70
submitButton .Importance = widget .HighImportance
71
+
72
+ hintCmd := "'tx bank send <from_key_or_address> <to_address> 1000ukex --chain-id=chaosnet2 --home=/sekai --fees=100ukex \n --keyring-backend=test --yes --broadcast-mode=block --log_format=json --output=json' "
73
+ hintText := & widget.TextSegment {Text : hintCmd , Style : widget .RichTextStyleBlockquote }
74
+ welcomeText := & widget.TextSegment {Text : "Example:" , Style : widget.RichTextStyle {TextStyle : fyne.TextStyle {Bold : true }}}
75
+
76
+ hintTextWidget := widget .NewRichText (welcomeText , hintText )
77
+ // hintTextWidget.Wrapping = fyne.TextWrapWord // dont use word wrapping, richtext glitches with this one
78
+
79
+ entryItem := widget .NewFormItem (sekaidCmdName [1 :]+ ":" , container .NewVBox (cmdEntry ))
80
+
40
81
content := container .NewBorder (
41
- widget . NewLabel ( "Enter sekai command below" ) ,
82
+ nil ,
42
83
container .NewVBox (submitButton , closeButton ),
43
- nil , nil ,
44
- cmdEntry ,
84
+ nil ,
85
+ nil ,
86
+ container .NewVBox (widget .NewForm (entryItem ), hintTextWidget ),
45
87
)
46
-
47
- wizard = dialogWizard .NewWizard ("Sekai cmd executor" , content )
88
+ wizard = dialogWizard .NewWizard ("Sekai executor" , content )
48
89
wizard .Show (g .Window )
49
- wizard .Resize (fyne .NewSize (900 , 200 ))
90
+ wizard .Resize (fyne .NewSize (800 , 200 ))
91
+
92
+ }
93
+
94
+ func RemoveEmptyAndWhitespaceStrings (input []string ) []string {
95
+ var result []string
96
+ for _ , str := range input {
97
+ trimmedStr := strings .TrimSpace (str )
98
+ if trimmedStr != "" {
99
+ result = append (result , trimmedStr )
100
+ }
101
+ }
102
+ return result
50
103
}
0 commit comments