本文整理汇总了Golang中github.com/grafov/gocui.View类的典型用法代码示例。如果您正苦于以下问题:Golang View类的具体用法?Golang View怎么用?Golang View使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了View类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: cursorDownInEditor
// cursorDownEditor enlarge sql view when a new line added
func cursorDownInEditor(g *gocui.Gui, v *gocui.View) error {
x, y := v.Cursor()
_, sizeY := v.Size()
if y >= sizeY-1 {
if splitY == minSplit {
return nil
}
splitY--
l, _ := g.View("log")
l.Resize(0, -1)
v.Resize(0, 1)
v.SetOrigin(0, 0)
v.SetCursor(x, y+1)
}
return nil
}
示例2: 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 {
log.Write(col.([]byte))
log.Write([]byte("\t"))
}
}
log.Write([]byte("\n"))
log.Write(bytes.Repeat([]byte("─"), logWidth))
return err
}
示例3: cursorUp
func cursorUp(g *gocui.Gui, v *gocui.View) error {
v.MoveCursor(0, -1, true)
return nil
}