本文整理匯總了Golang中github.com/grafov/gocui.Gui.Size方法的典型用法代碼示例。如果您正苦於以下問題:Golang Gui.Size方法的具體用法?Golang Gui.Size怎麽用?Golang Gui.Size使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/grafov/gocui.Gui
的用法示例。
在下文中一共展示了Gui.Size方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: execQuery
func execQuery(g *gocui.Gui, v *gocui.View) error {
dbc := db.Use("test")
query := strings.TrimSpace(v.Buffer())
v.Reset()
fmt.Fprint(v, query)
widtgh, height := v.Size()
if height > v.LinesCount() {
v.SetSize(widtgh, v.LinesCount())
_, maxY := g.Size()
splitY = maxY - v.LinesCount() - 3
}
v.SetCursor(0, 0)
if len(query) == 0 {
return nil
}
log, _ := g.View("log")
rows, err := dbc.Queryx(query)
if err != nil {
fmt.Fprintln(log, err)
return nil
}
fmt.Fprintln(log, "\n", query)
logWidth, _ := log.Size()
log.Write(bytes.Repeat([]byte("─"), logWidth))
for rows.Next() {
log.Write([]byte("\n"))
cols, err := rows.SliceScan()
if err != nil {
fmt.Fprintln(log, err)
err = nil
break
}
for _, col := range cols {
if col != nil {
log.Write(col.([]byte))
log.Write([]byte("\t"))
}
}
}
log.Write([]byte("\n"))
log.Write(bytes.Repeat([]byte("─"), logWidth))
return err
}
示例2: baseLayout
// sql panel is for exploring queries and log output
func baseLayout(g *gocui.Gui) error {
maxX, maxY := g.Size()
// Panels of sql explorer
if splitY == 0 {
splitY = maxY - 4
}
l, err := g.SetView("log", 0, 0, maxX-1, splitY)
if err != nil {
if err != gocui.ErrUnknownView {
return err
}
l.Frame = false
l.Autoscroll = true
l.BgColor = gocui.ColorBlack
l.FgColor = gocui.ColorWhite
fmt.Fprintf(l, strings.Repeat("\n", splitY))
}
s, err := g.SetView("sql", 0, splitY, maxX-1, maxY-2)
if err != nil {
if err != gocui.ErrUnknownView {
return err
}
s.Editable = true
s.Wrap = true
s.Frame = false
s.BgColor = gocui.ColorBlack
s.FgColor = gocui.ColorWhite
fmt.Fprint(s, "")
}
// Two panels over sql explorer
lp, err := g.SetView("lpanel", 0, 0, maxX/2-1, maxY-2)
if err != nil {
if err != gocui.ErrUnknownView {
return err
}
// lp.Autoscroll = true
lp.Highlight = true
lp.BgColor = gocui.ColorBlue
lp.SelBgColor = gocui.ColorYellow
lp.SelFgColor = gocui.ColorBlack
for i := 1; i < 255; i++ {
fmt.Fprintf(lp, " menu item %3d │ \n", i)
}
}
rp, err := g.SetView("rpanel", maxX/2, 0, maxX-1, maxY-2)
if err != nil {
if err != gocui.ErrUnknownView {
return err
}
// rp.Autoscroll = true
rp.Highlight = true
rp.BgColor = gocui.ColorBlue
lp.SelBgColor = gocui.ColorYellow
lp.SelFgColor = gocui.ColorBlack
}
mp, err := g.SetView("menu", 0, maxY-2, maxX-1, maxY)
if err != nil {
if err != gocui.ErrUnknownView {
return err
}
mp.Frame = false
mp.BgColor = gocui.ColorBlack
mp.FgColor = gocui.ColorYellow | gocui.AttrBold
fmt.Fprint(mp, "F1 new F2 edit F5 copy F8 delete F10 exit")
}
as, _ := g.SetView("addSource", maxX/2-10, maxY/2-2, maxX/2+10, maxY/2+2)
as.Hide()
if twoPanelsVisible {
g.SetCurrentView("lpanel")
} else {
g.SetCurrentView("sql")
}
return nil
}