@@ -22,6 +22,7 @@ type ReplayView struct {
22
22
request * tview.TextView // http request box
23
23
response * tview.TextView // http response box
24
24
responseMeta * tview.Table // metadata for size recieved and time taken
25
+ goButton * tview.Button // send button
25
26
26
27
host * tview.InputField // host field input
27
28
port * tview.InputField // port input
@@ -97,7 +98,7 @@ func (view *ReplayView) Init(app *tview.Application) {
97
98
view .request .SetWrap (false ).SetBorder (true ).SetTitle ("Request" )
98
99
99
100
// go and cancel buttons
100
- goButton : = tview .NewButton ("Go" )
101
+ view . goButton = tview .NewButton ("Go" )
101
102
102
103
// Host, Port, TLS and Auto-content-length fields
103
104
view .host = tview .NewInputField ()
@@ -134,42 +135,8 @@ func (view *ReplayView) Init(app *tview.Application) {
134
135
view .response = tview .NewTextView ().SetWrap (false )
135
136
view .response .SetBorder (true ).SetTitle ("Response" )
136
137
137
- goButton .SetSelectedFunc (func () {
138
- if req , ok := view .entries [id ]; ok {
139
- view .response .Clear ()
140
- c := false
141
-
142
- go func () {
143
- size , err := req .SendRequest ()
144
- if req == view .entries [id ] {
145
- if size > 0 {
146
- view .refreshReplay (req )
147
- } else {
148
- view .responseMeta .SetCell (0 , 1 , tview .NewTableCell ("ERROR" ))
149
- view .responseMeta .SetCell (0 , 3 , tview .NewTableCell ("ERROR" ))
150
- view .response .Clear ()
151
- fmt .Fprint (view .response , err )
152
- }
153
- app .Draw ()
154
- }
155
- c = true
156
- }()
157
-
158
- spindex := 0
159
- spinner := []string {"|" , "/" , "-" , "\\ " }
160
- go func () {
161
- for ! c {
162
- goButton .SetLabel ("Go " + spinner [spindex ])
163
- app .Draw ()
164
- spindex ++
165
- if spindex == 3 {
166
- spindex = 0
167
- }
168
- time .Sleep (100 * time .Millisecond )
169
- }
170
- goButton .SetLabel ("Go" )
171
- }()
172
- }
138
+ view .goButton .SetSelectedFunc (func () {
139
+ view .sendRequest (app , id )
173
140
})
174
141
175
142
view .Table = tview .NewTable ()
@@ -294,7 +261,7 @@ func (view *ReplayView) Init(app *tview.Application) {
294
261
requestFlexView .SetDirection (tview .FlexRow )
295
262
requestFlexView .AddItem (connectionForm , 2 , 1 , false )
296
263
requestFlexView .AddItem (view .request , 0 , 8 , false )
297
- requestFlexView .AddItem (goButton , 1 , 1 , false )
264
+ requestFlexView .AddItem (view . goButton , 1 , 1 , false )
298
265
299
266
responseFlexView := tview .NewFlex ()
300
267
responseFlexView .SetDirection (tview .FlexRow )
@@ -305,7 +272,7 @@ func (view *ReplayView) Init(app *tview.Application) {
305
272
replayFlexView .AddItem (requestFlexView , 0 , 4 , false )
306
273
replayFlexView .AddItem (responseFlexView , 0 , 4 , false )
307
274
308
- items := []tview.Primitive {view .Table , view .host , view .port , view .tls , view .updateContentLength , view .request , goButton , view .response }
275
+ items := []tview.Primitive {view .Table , view .host , view .port , view .tls , view .updateContentLength , view .request , view . goButton , view .response }
309
276
mainLayout .AddItem (replayFlexView , 0 , 1 , true )
310
277
311
278
view .Layout .AddPage ("mainLayout" , mainLayout , true , true )
@@ -357,6 +324,8 @@ func (view *ReplayView) Init(app *tview.Application) {
357
324
replayData .ID = "new"
358
325
view .AddItem (replayData )
359
326
327
+ case tcell .KeyCtrlG :
328
+ view .sendRequest (app , id )
360
329
}
361
330
return event
362
331
})
@@ -386,3 +355,43 @@ func (view *ReplayView) refreshReplay(r *replay.Request) {
386
355
view .responseMeta .SetCell (0 , 1 , tview .NewTableCell (strconv .Itoa (len (r .RawResponse ))))
387
356
view .responseMeta .SetCell (0 , 3 , tview .NewTableCell (r .ResponseTime ))
388
357
}
358
+
359
+ // Send the request
360
+
361
+ func (view * ReplayView ) sendRequest (app * tview.Application , id string ) {
362
+ if req , ok := view .entries [id ]; ok {
363
+ view .response .Clear ()
364
+ c := false
365
+
366
+ go func () {
367
+ size , err := req .SendRequest ()
368
+ if req == view .entries [id ] {
369
+ if size > 0 {
370
+ view .refreshReplay (req )
371
+ } else {
372
+ view .responseMeta .SetCell (0 , 1 , tview .NewTableCell ("ERROR" ))
373
+ view .responseMeta .SetCell (0 , 3 , tview .NewTableCell ("ERROR" ))
374
+ view .response .Clear ()
375
+ fmt .Fprint (view .response , err )
376
+ }
377
+ app .Draw ()
378
+ }
379
+ c = true
380
+ }()
381
+
382
+ spindex := 0
383
+ spinner := []string {"|" , "/" , "-" , "\\ " }
384
+ go func () {
385
+ for ! c {
386
+ view .goButton .SetLabel ("Go " + spinner [spindex ])
387
+ app .Draw ()
388
+ spindex ++
389
+ if spindex == 3 {
390
+ spindex = 0
391
+ }
392
+ time .Sleep (100 * time .Millisecond )
393
+ }
394
+ view .goButton .SetLabel ("Go" )
395
+ }()
396
+ }
397
+ }
0 commit comments