mirror of
https://github.com/asciimoo/wuzz
synced 2024-11-12 07:10:24 +00:00
[enh] add statusline
This commit is contained in:
parent
aab7f36262
commit
54d532497d
@ -40,6 +40,7 @@ type GeneralOptions struct {
|
||||
PreserveScrollPosition bool
|
||||
FollowRedirects bool
|
||||
DefaultURLScheme string
|
||||
StatusLine string
|
||||
TLSVersionMin uint16
|
||||
TLSVersionMax uint16
|
||||
}
|
||||
@ -98,6 +99,7 @@ var DefaultConfig = Config{
|
||||
Insecure: false,
|
||||
PreserveScrollPosition: true,
|
||||
FollowRedirects: true,
|
||||
StatusLine: "wuzz {{ .Version }}",
|
||||
DefaultURLScheme: "https",
|
||||
},
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ insecure = false
|
||||
preserveScrollPosition = true
|
||||
followRedirects = true
|
||||
defaultURLScheme = "https"
|
||||
statusLine = "wuzz {{.Version}}"
|
||||
|
||||
# KEYBINDINGS
|
||||
[keys.global]
|
||||
|
39
status-line.go
Normal file
39
status-line.go
Normal file
@ -0,0 +1,39 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"text/template"
|
||||
|
||||
"github.com/jroimartin/gocui"
|
||||
)
|
||||
|
||||
type StatusLine struct {
|
||||
tpl *template.Template
|
||||
}
|
||||
|
||||
type StatusLineFunctions struct {
|
||||
}
|
||||
|
||||
var STATUSLINE_FUNCTIONS = &StatusLineFunctions{}
|
||||
|
||||
func (_ *StatusLineFunctions) Version() string {
|
||||
return VERSION
|
||||
}
|
||||
|
||||
func (s *StatusLine) Update(v *gocui.View) {
|
||||
v.Clear()
|
||||
err := s.tpl.Execute(v, STATUSLINE_FUNCTIONS)
|
||||
if err != nil {
|
||||
fmt.Fprintf(v, "StatusLine update error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func NewStatusLine(format string) (*StatusLine, error) {
|
||||
tpl, err := template.New("status line").Parse(format)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &StatusLine{
|
||||
tpl: tpl,
|
||||
}, nil
|
||||
}
|
27
wuzz.go
27
wuzz.go
@ -42,6 +42,7 @@ const (
|
||||
REQUEST_METHOD_VIEW = "method"
|
||||
REQUEST_DATA_VIEW = "data"
|
||||
REQUEST_HEADERS_VIEW = "headers"
|
||||
STATUSLINE_VIEW = "status-line"
|
||||
SEARCH_VIEW = "search"
|
||||
RESPONSE_HEADERS_VIEW = "response-headers"
|
||||
RESPONSE_BODY_VIEW = "response-body"
|
||||
@ -112,6 +113,11 @@ var VIEW_POSITIONS = map[string]viewPosition{
|
||||
position{0.25, 2},
|
||||
position{1.0, -2},
|
||||
position{1.0, -3}},
|
||||
STATUSLINE_VIEW: {
|
||||
position{0.0, -1},
|
||||
position{1.0, -4},
|
||||
position{1.0, 0},
|
||||
position{1.0, -1}},
|
||||
SEARCH_VIEW: {
|
||||
position{0.0, 7},
|
||||
position{1.0, -3},
|
||||
@ -208,6 +214,14 @@ var VIEW_PROPERTIES = map[string]viewProperties{
|
||||
wrap: false,
|
||||
editor: &singleLineEditor{&SearchEditor{&defaultEditor}},
|
||||
},
|
||||
STATUSLINE_VIEW : {
|
||||
title: "",
|
||||
frame: false,
|
||||
editable: false,
|
||||
wrap: false,
|
||||
editor: nil,
|
||||
text: "",
|
||||
},
|
||||
SEARCH_PROMPT_VIEW: {
|
||||
title: "",
|
||||
frame: false,
|
||||
@ -295,6 +309,7 @@ type App struct {
|
||||
currentPopup string
|
||||
history []*Request
|
||||
config *config.Config
|
||||
statusLine *StatusLine
|
||||
}
|
||||
|
||||
type ViewEditor struct {
|
||||
@ -556,6 +571,7 @@ func (a *App) Layout(g *gocui.Gui) error {
|
||||
REQUEST_HEADERS_VIEW,
|
||||
RESPONSE_HEADERS_VIEW,
|
||||
RESPONSE_BODY_VIEW,
|
||||
STATUSLINE_VIEW,
|
||||
SEARCH_PROMPT_VIEW,
|
||||
SEARCH_VIEW,
|
||||
} {
|
||||
@ -566,6 +582,10 @@ func (a *App) Layout(g *gocui.Gui) error {
|
||||
setViewProperties(v, name)
|
||||
}
|
||||
}
|
||||
sv, _ := g.View(STATUSLINE_VIEW)
|
||||
sv.BgColor = gocui.ColorDefault | gocui.AttrReverse
|
||||
sv.FgColor = gocui.ColorDefault | gocui.AttrReverse
|
||||
a.statusLine.Update(sv)
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -1264,6 +1284,13 @@ func (a *App) LoadConfig(configPath string) error {
|
||||
}
|
||||
|
||||
a.config = conf
|
||||
sl, err := NewStatusLine(conf.General.StatusLine)
|
||||
if err != nil {
|
||||
a.config = &config.DefaultConfig
|
||||
a.config.Keys = config.DefaultKeys
|
||||
return err
|
||||
}
|
||||
a.statusLine = sl
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user