-
Notifications
You must be signed in to change notification settings - Fork 0
/
request_model.go
51 lines (39 loc) · 1.09 KB
/
request_model.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"strings"
"github.com/charmbracelet/bubbles/textarea"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
type Request struct {
body textarea.Model
headers textarea.Model
border lipgloss.Style
}
func InitialRequestModel() *Request {
bodyTextArea := textarea.New()
bodyTextArea.Placeholder = `{"request": "body"}`
bodyTextArea.SetValue(`{"body": "Data ..."}`)
bodyTextArea.SetWidth(100)
headersTextArea := textarea.New()
headersTextArea.Placeholder = `{"request": "headers"}`
headersTextArea.SetValue(`{"Content-type": "application/json; charset=UTF-8"}`)
headersTextArea.SetWidth(100)
return &Request{
body: bodyTextArea,
headers: headersTextArea,
border: StyleRequestBorder,
}
}
func (rq Request) Init() tea.Cmd {
return nil
}
func (rq Request) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return rq, nil
}
func (rq Request) View() string {
var stringBuilder strings.Builder
stringBuilder.WriteString(rq.body.View() + "\n\n")
stringBuilder.WriteString(rq.headers.View())
return rq.border.Render(stringBuilder.String())
}