-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrog.go
More file actions
242 lines (214 loc) · 6.58 KB
/
frog.go
File metadata and controls
242 lines (214 loc) · 6.58 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
package frog
import (
"context"
"io"
"github.com/pondworks-lib/frog/core"
"github.com/pondworks-lib/frog/core/validate"
)
type (
App = core.Session
Option = core.Option
// Core types.
Model = core.Model
Msg = core.Msg
KeyMsg = core.KeyMsg
KeyType = core.KeyType
TickMsg = core.TickMsg
QuitMsg = core.QuitMsg
Cmd = core.Cmd
ResizeMsg = core.ResizeMsg
// Mouse and paste messages.
MouseMsg = core.MouseMsg
MouseButton = core.MouseButton
MouseAction = core.MouseAction
PasteMsg = core.PasteMsg
// Styling.
Style = core.Style
Color = core.Color
ColorProfile = core.ColorProfile
// Renderer options.
RendererOption = core.RendererOption
// Layout.
AlignH = core.AlignH
AlignV = core.AlignV
// Logger.
Logger = core.Logger
// Structured runtime and validation errors.
Error = core.Error
ErrorCode = core.ErrorCode
ValidationCode = validate.Code
ValidationSeverity = validate.Severity
ValidationIssue = validate.Issue
ValidationReport = validate.Report
)
// Key constants
const (
KeyUnknown = core.KeyUnknown
KeyRune = core.KeyRune
KeyEnter = core.KeyEnter
KeyBackspace = core.KeyBackspace
KeyEsc = core.KeyEsc
KeyCtrlC = core.KeyCtrlC
KeyUp = core.KeyUp
KeyDown = core.KeyDown
KeyLeft = core.KeyLeft
KeyRight = core.KeyRight
KeyTab = core.KeyTab
KeySpace = core.KeySpace
KeyDelete = core.KeyDelete
KeyHome = core.KeyHome
KeyEnd = core.KeyEnd
KeyPgUp = core.KeyPgUp
KeyPgDn = core.KeyPgDn
KeyQ = core.KeyQ
)
// Mouse constants
const (
MouseUnknown = core.MouseUnknown
MouseLeft = core.MouseLeft
MouseMiddle = core.MouseMiddle
MouseRight = core.MouseRight
MouseWheelUp = core.MouseWheelUp
MouseWheelDown = core.MouseWheelDown
)
// Runtime error codes
const (
ErrNilModel = core.ErrNilModel
ErrNilRenderer = core.ErrNilRenderer
ErrRawMode = core.ErrRawMode
ErrInitFailed = core.ErrInitFailed
ErrViewFailed = core.ErrViewFailed
ErrUpdateFailed = core.ErrUpdateFailed
ErrCommandFailed = core.ErrCommandFailed
ErrNilUpdateModel = core.ErrNilUpdateModel
)
// Validation issue codes
const (
ValidationNilModel = validate.CodeNilModel
ValidationMissingView = validate.CodeMissingView
ValidationEmptyView = validate.CodeEmptyView
ValidationViewNotString = validate.CodeViewNotString
ValidationViewHasBadRunes = validate.CodeViewHasBadRunes
ValidationViewPanic = validate.CodeViewPanic
ValidationMissingUpdate = validate.CodeMissingUpdate
ValidationBadUpdateSignature = validate.CodeBadUpdateSignature
ValidationMissingInit = validate.CodeMissingInit
ValidationBadInitSignature = validate.CodeBadInitSignature
ValidationUpdateNilModel = validate.CodeUpdateNilModel
ValidationViewVeryLarge = validate.CodeViewVeryLarge
ValidationViewSuspicious = validate.CodeViewSuspicious
ValidationNonExportedType = validate.CodeNonExportedType
ValidationSlowView = validate.CodeSlowView
ValidationSlowInit = validate.CodeSlowInit
ValidationHasNoMethods = validate.CodeHasNoMethods
ValidationUpdateNotMethod = validate.CodeUpdateNotMethod
ValidationViewNotMethod = validate.CodeViewNotMethod
ValidationReceiverMismatch = validate.CodeReceiverMismatch
ValidationViewControlCodes = validate.CodeViewControlCodes
)
const (
MousePress = core.MousePress
MouseRelease = core.MouseRelease
MouseDrag = core.MouseDrag
MouseWheel = core.MouseWheel
)
// Color profile constants
const (
ColorAuto = core.ColorAuto
ColorNone = core.ColorNone
ColorANSI16 = core.ColorANSI16
ColorANSI256 = core.ColorANSI256
ColorTrueColor = core.ColorTrueColor
)
// Named colors (16-color)
var (
ColorBlack = core.ColorBlack
ColorRed = core.ColorRed
ColorGreen = core.ColorGreen
ColorYellow = core.ColorYellow
ColorBlue = core.ColorBlue
ColorMagenta = core.ColorMagenta
ColorCyan = core.ColorCyan
ColorWhite = core.ColorWhite
ColorBrightBlack = core.ColorBrightBlack
ColorBrightRed = core.ColorBrightRed
ColorBrightGreen = core.ColorBrightGreen
ColorBrightYellow = core.ColorBrightYellow
ColorBrightBlue = core.ColorBrightBlue
ColorBrightMagenta = core.ColorBrightMagenta
ColorBrightCyan = core.ColorBrightCyan
ColorBrightWhite = core.ColorBrightWhite
)
// Style functions.
var (
NewStyle = core.NewStyle
ANSI256 = core.ANSI256
RGB = core.RGB
Colorize = core.Colorize
StripANSI = core.StripANSI
InspectModel = validate.InspectModel
ValidateModel = validate.ValidateModel
)
// App functions.
func NewApp(m Model, opts ...Option) *App { return core.NewSession(m, opts...) }
func Run(m Model, opts ...Option) error {
if err := validate.ValidateModel(m); err != nil {
return err
}
return core.NewSession(m, opts...).Run()
}
// Context-aware entrypoints.
func NewAppWithContext(ctx context.Context, m Model, opts ...Option) *App {
return core.NewSessionWithContext(ctx, m, opts...)
}
func RunContext(ctx context.Context, m Model, opts ...Option) error {
if err := validate.ValidateModel(m); err != nil {
return err
}
return core.NewSessionWithContext(ctx, m, opts...).Run()
}
// Session options
var (
Tick = core.Tick
Quit = core.Quit
Nil = core.Nil
WithRenderer = core.WithRenderer
WithAltScreen = core.WithAltScreen
WithMsgBuffer = core.WithMsgBuffer
WithOut = core.WithOut
WithIn = core.WithIn
WithResizeInterval = core.WithResizeInterval
WithNonInteractive = core.WithNonInteractive
WithLogger = core.WithLogger
WithMouse = core.WithMouse
WithBracketedPaste = core.WithBracketedPaste
)
// Renderer helpers.
func NewRenderer(out io.Writer, opts ...RendererOption) core.Renderer {
return core.NewRenderer(out, opts...)
}
// Help overlay.
func RenderKeyHelp(km *core.KeyMap, width, height int) string {
return core.RenderHelpOverlay(km, width, height)
}
// FPS-throttled renderer.
func NewThrottledRenderer(out io.Writer, fps int, opts ...core.RendererOption) core.Renderer {
return core.NewThrottledRenderer(out, fps, opts...)
}
var (
WithDiff = core.WithDiff
WithColorProfile = core.WithColorProfile
)
// Layout helpers.
const (
AlignLeft = core.AlignLeft
AlignCenter = core.AlignCenter
AlignRight = core.AlignRight
AlignTop = core.AlignTop
AlignMiddle = core.AlignMiddle
AlignBottom = core.AlignBottom
)
var (
Center = core.Center
PlaceBlock = core.PlaceBlock
)