mirror of https://github.com/jroimartin/gocui.git
Clean up API
This commit is contained in:
parent
21cbd1f235
commit
cee092a9f8
12
gui.go
12
gui.go
|
@ -19,7 +19,7 @@ type Gui struct {
|
|||
views []*View
|
||||
currentView *View
|
||||
layout func(*Gui) error
|
||||
keybindings []*Keybinding
|
||||
keybindings []*keybinding
|
||||
maxX, maxY int
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ func (g *Gui) SetView(name string, x0, y0, x1, y1 int) (v *View, err error) {
|
|||
return v, nil
|
||||
}
|
||||
|
||||
v = NewView(name, x0, y0, x1, y1)
|
||||
v = newView(name, x0, y0, x1, y1)
|
||||
v.bgColor, v.fgColor = g.BgColor, g.FgColor
|
||||
v.selBgColor, v.selFgColor = g.SelBgColor, g.SelFgColor
|
||||
g.views = append(g.views, v)
|
||||
|
@ -112,13 +112,13 @@ func (g *Gui) SetCurrentView(name string) (err error) {
|
|||
}
|
||||
|
||||
func (g *Gui) SetKeybinding(viewname string, key interface{}, mod Modifier, cb KeybindingCB) (err error) {
|
||||
var kb *Keybinding
|
||||
var kb *keybinding
|
||||
|
||||
switch k := key.(type) {
|
||||
case Key:
|
||||
kb = NewKeybinding(viewname, k, 0, mod, cb)
|
||||
kb = newKeybinding(viewname, k, 0, mod, cb)
|
||||
case rune:
|
||||
kb = NewKeybinding(viewname, 0, k, mod, cb)
|
||||
kb = newKeybinding(viewname, 0, k, mod, cb)
|
||||
default:
|
||||
return errors.New("unknown type")
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ func (g *Gui) draw() (err error) {
|
|||
}
|
||||
|
||||
for _, v := range g.views {
|
||||
if err := v.Draw(); err != nil {
|
||||
if err := v.draw(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ const (
|
|||
ModAlt Modifier = Modifier(termbox.ModAlt)
|
||||
)
|
||||
|
||||
type Keybinding struct {
|
||||
type keybinding struct {
|
||||
ViewName string
|
||||
Key Key
|
||||
Ch rune
|
||||
|
@ -94,8 +94,8 @@ type Keybinding struct {
|
|||
CB KeybindingCB
|
||||
}
|
||||
|
||||
func NewKeybinding(viewname string, key Key, ch rune, mod Modifier, cb KeybindingCB) (kb *Keybinding) {
|
||||
kb = &Keybinding{
|
||||
func newKeybinding(viewname string, key Key, ch rune, mod Modifier, cb KeybindingCB) (kb *keybinding) {
|
||||
kb = &keybinding{
|
||||
ViewName: viewname,
|
||||
Key: key,
|
||||
Ch: ch,
|
||||
|
|
4
view.go
4
view.go
|
@ -19,7 +19,7 @@ type View struct {
|
|||
selBgColor, selFgColor Attribute
|
||||
}
|
||||
|
||||
func NewView(name string, x0, y0, x1, y1 int) (v *View) {
|
||||
func newView(name string, x0, y0, x1, y1 int) (v *View) {
|
||||
v = &View{
|
||||
Name: name,
|
||||
X0: x0,
|
||||
|
@ -79,7 +79,7 @@ func (v *View) Write(p []byte) (n int, err error) {
|
|||
return len(pr), nil
|
||||
}
|
||||
|
||||
func (v *View) Draw() (err error) {
|
||||
func (v *View) draw() (err error) {
|
||||
maxX, maxY := v.Size()
|
||||
buf := bytes.NewBufferString(string(v.buffer))
|
||||
br := bufio.NewReader(buf)
|
||||
|
|
Loading…
Reference in New Issue