Clean up API

This commit is contained in:
Roi Martin (@nibble_ds) 2014-01-11 20:29:16 +01:00
parent 21cbd1f235
commit cee092a9f8
3 changed files with 11 additions and 11 deletions

12
gui.go
View File

@ -19,7 +19,7 @@ type Gui struct {
views []*View views []*View
currentView *View currentView *View
layout func(*Gui) error layout func(*Gui) error
keybindings []*Keybinding keybindings []*keybinding
maxX, maxY int 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 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.bgColor, v.fgColor = g.BgColor, g.FgColor
v.selBgColor, v.selFgColor = g.SelBgColor, g.SelFgColor v.selBgColor, v.selFgColor = g.SelBgColor, g.SelFgColor
g.views = append(g.views, v) 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) { func (g *Gui) SetKeybinding(viewname string, key interface{}, mod Modifier, cb KeybindingCB) (err error) {
var kb *Keybinding var kb *keybinding
switch k := key.(type) { switch k := key.(type) {
case Key: case Key:
kb = NewKeybinding(viewname, k, 0, mod, cb) kb = newKeybinding(viewname, k, 0, mod, cb)
case rune: case rune:
kb = NewKeybinding(viewname, 0, k, mod, cb) kb = newKeybinding(viewname, 0, k, mod, cb)
default: default:
return errors.New("unknown type") return errors.New("unknown type")
} }
@ -203,7 +203,7 @@ func (g *Gui) draw() (err error) {
} }
for _, v := range g.views { for _, v := range g.views {
if err := v.Draw(); err != nil { if err := v.draw(); err != nil {
return err return err
} }
} }

View File

@ -86,7 +86,7 @@ const (
ModAlt Modifier = Modifier(termbox.ModAlt) ModAlt Modifier = Modifier(termbox.ModAlt)
) )
type Keybinding struct { type keybinding struct {
ViewName string ViewName string
Key Key Key Key
Ch rune Ch rune
@ -94,8 +94,8 @@ type Keybinding struct {
CB KeybindingCB CB KeybindingCB
} }
func NewKeybinding(viewname string, key Key, ch rune, mod Modifier, cb KeybindingCB) (kb *Keybinding) { func newKeybinding(viewname string, key Key, ch rune, mod Modifier, cb KeybindingCB) (kb *keybinding) {
kb = &Keybinding{ kb = &keybinding{
ViewName: viewname, ViewName: viewname,
Key: key, Key: key,
Ch: ch, Ch: ch,

View File

@ -19,7 +19,7 @@ type View struct {
selBgColor, selFgColor Attribute 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{ v = &View{
Name: name, Name: name,
X0: x0, X0: x0,
@ -79,7 +79,7 @@ func (v *View) Write(p []byte) (n int, err error) {
return len(pr), nil return len(pr), nil
} }
func (v *View) Draw() (err error) { func (v *View) draw() (err error) {
maxX, maxY := v.Size() maxX, maxY := v.Size()
buf := bytes.NewBufferString(string(v.buffer)) buf := bytes.NewBufferString(string(v.buffer))
br := bufio.NewReader(buf) br := bufio.NewReader(buf)