5 changed files with 126 additions and 9 deletions
@ -1,4 +1,106 @@
|
||||
package main |
||||
|
||||
import ( |
||||
"log" |
||||
|
||||
"git.yetaga.in/alazyreader/library/config" |
||||
"github.com/gdamore/tcell" |
||||
"github.com/kelseyhightower/envconfig" |
||||
) |
||||
|
||||
func main() { |
||||
var c config.Config |
||||
err := envconfig.Process("library", &c) |
||||
if err != nil { |
||||
log.Fatalln(err) |
||||
} |
||||
|
||||
screen, err := tcell.NewScreen() |
||||
if err != nil { |
||||
log.Fatalln(err) |
||||
} |
||||
err = screen.Init() |
||||
if err != nil { |
||||
log.Fatalln(err) |
||||
} |
||||
screen.Clear() |
||||
inc := 0 |
||||
for { |
||||
e := screen.PollEvent() |
||||
screen.Clear() |
||||
w, h := screen.Size() |
||||
b := &box{h: h, w: w, x: 0, y: 0, title: "library", menuItems: []string{"(e)dit", "(q)uit"}} |
||||
switch v := e.(type) { |
||||
case *tcell.EventError: |
||||
screen.Beep() |
||||
b.draw(screen) |
||||
screen.SetContent(1, 1, 'E', nil, tcell.StyleDefault) |
||||
case *tcell.EventInterrupt: |
||||
b.draw(screen) |
||||
screen.Sync() |
||||
case *tcell.EventKey: |
||||
inc += 1 |
||||
b.draw(screen) |
||||
screen.SetContent(1, 1, v.Rune(), nil, tcell.StyleDefault) |
||||
screen.SetContent(2, 2, rune(inc+48), nil, tcell.StyleDefault) |
||||
if v.Rune() == 'q' { |
||||
screen.Fini() |
||||
return |
||||
} |
||||
screen.Sync() |
||||
case *tcell.EventMouse: |
||||
continue |
||||
case *tcell.EventResize: |
||||
b.draw(screen) |
||||
screen.Sync() |
||||
case *tcell.EventTime: |
||||
continue |
||||
} |
||||
} |
||||
} |
||||
|
||||
type box struct { |
||||
x, y int |
||||
h, w int |
||||
title string |
||||
menuItems []string |
||||
} |
||||
|
||||
func (b *box) draw(s tcell.Screen) { |
||||
for m := 1; m < b.w-1; m++ { |
||||
s.SetContent(m, b.y, tcell.RuneHLine, nil, tcell.StyleDefault) |
||||
s.SetContent(m, b.h-1, tcell.RuneHLine, nil, tcell.StyleDefault) |
||||
} |
||||
for m := 1; m < b.h-1; m++ { |
||||
s.SetContent(b.x, m, tcell.RuneVLine, nil, tcell.StyleDefault) |
||||
s.SetContent(b.w-1, m, tcell.RuneVLine, nil, tcell.StyleDefault) |
||||
} |
||||
s.SetContent(b.x, b.y, tcell.RuneULCorner, nil, tcell.StyleDefault) |
||||
s.SetContent(b.w-1, b.y, tcell.RuneURCorner, nil, tcell.StyleDefault) |
||||
s.SetContent(b.x, b.h-1, tcell.RuneLLCorner, nil, tcell.StyleDefault) |
||||
s.SetContent(b.w-1, b.h-1, tcell.RuneLRCorner, nil, tcell.StyleDefault) |
||||
|
||||
if b.title != "" { |
||||
t := b.x + 2 |
||||
s.SetContent(t, b.y, ' ', nil, tcell.StyleDefault) |
||||
t++ |
||||
for _, r := range b.title { |
||||
s.SetContent(t, b.y, r, nil, tcell.StyleDefault) |
||||
t++ |
||||
} |
||||
s.SetContent(t, b.y, ' ', nil, tcell.StyleDefault) |
||||
} |
||||
if len(b.menuItems) != 0 { |
||||
t := b.x + 2 |
||||
s.SetContent(t, b.h-1, ' ', nil, tcell.StyleDefault) |
||||
t++ |
||||
for i := range b.menuItems { |
||||
for _, r := range b.menuItems[i] { |
||||
s.SetContent(t, b.h-1, r, nil, tcell.StyleDefault) |
||||
t++ |
||||
} |
||||
s.SetContent(t, b.h-1, ' ', nil, tcell.StyleDefault) |
||||
t++ |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,9 @@
|
||||
package config |
||||
|
||||
type Config struct { |
||||
DBUser string |
||||
DBPass string |
||||
DBHost string |
||||
DBPort string |
||||
DBName string |
||||
} |
@ -1,4 +1,16 @@
|
||||
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko= |
||||
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg= |
||||
github.com/gdamore/tcell v1.4.0 h1:vUnHwJRvcPQa3tzi+0QI4U9JINXYJlOz9yiaiPQ2wMU= |
||||
github.com/gdamore/tcell v1.4.0/go.mod h1:vxEiSDZdW3L+Uhjii9c3375IlDmR05bzxY404ZVSMo0= |
||||
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= |
||||
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= |
||||
github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8= |
||||
github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg= |
||||
github.com/lucasb-eyer/go-colorful v1.0.3 h1:QIbQXiugsb+q10B+MI+7DI1oQLdmnep86tWFlaaUAac= |
||||
github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= |
||||
github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54= |
||||
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= |
||||
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756 h1:9nuHUbU8dRnRRfj9KjWUVrJeoexdbeMjttk6Oh1rD10= |
||||
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= |
||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= |
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= |
||||
|
Loading…
Reference in new issue