当前位置: 首页>>代码示例>>Golang>>正文


Golang gocui.Gui类代码示例

本文整理汇总了Golang中github.com/grafov/gocui.Gui的典型用法代码示例。如果您正苦于以下问题:Golang Gui类的具体用法?Golang Gui怎么用?Golang Gui使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Gui类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: addSource

func addSource(g *gocui.Gui, p *gocui.View) error {
	v, _ := g.View("addSource")
	v.Editable = true
	if v.Visible() {
		v.Hide()
	} else {
		v.Unhide()
	}
	return nil
}
开发者ID:gophergala2016,项目名称:dbcom,代码行数:10,代码来源:actions.go

示例2: 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
}
开发者ID:gophergala2016,项目名称:dbcom,代码行数:17,代码来源:actions.go

示例3: 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
}
开发者ID:grafov,项目名称:dbcom,代码行数:46,代码来源:actions.go

示例4: switchPanels

func switchPanels(g *gocui.Gui, v *gocui.View) error {
	lp, _ := g.View("lpanel")
	rp, _ := g.View("rpanel")
	if twoPanelsVisible {
		lp.Hide()
		rp.Hide()
		g.SetCurrentView("sql")
		g.ShowCursor = true
		twoPanelsVisible = false
	} else {
		lp.Unhide()
		rp.Unhide()
		g.SetCurrentView("lpanel")
		g.ShowCursor = false
		twoPanelsVisible = true
	}
	return nil
}
开发者ID:gophergala2016,项目名称:dbcom,代码行数:18,代码来源:actions.go

示例5: initKeys

func initKeys(g *gocui.Gui) error {
	if err := g.SetKeybinding("", gocui.KeyCtrlQ, gocui.ModNone, quit); err != nil {
		return err
	}
	if err := g.SetKeybinding("", gocui.KeyF10, gocui.ModNone, quit); err != nil {
		return err
	}
	if err := g.SetKeybinding("", gocui.KeyCtrlR, gocui.ModNone, refresh); err != nil {
		return err
	}
	if err := g.SetKeybinding("", gocui.KeyCtrlO, gocui.ModNone, switchPanels); err != nil {
		return err
	}
	if err := g.SetKeybinding("", gocui.KeyF2, gocui.ModAlt, addSource); err != nil {
		return err
	}

	if err := g.SetKeybinding("lpanel", gocui.KeyArrowDown, gocui.ModNone, cursorDown); err != nil {
		return err
	}
	if err := g.SetKeybinding("rpanel", gocui.KeyArrowDown, gocui.ModNone, cursorDown); err != nil {
		return err
	}
	if err := g.SetKeybinding("lpanel", gocui.KeyArrowUp, gocui.ModNone, cursorUp); err != nil {
		return err
	}
	if err := g.SetKeybinding("rpanel", gocui.KeyArrowUp, gocui.ModNone, cursorUp); err != nil {
		return err
	}

	if err := g.SetKeybinding("sql", gocui.KeyArrowDown, gocui.ModNone, cursorDownInEditor); err != nil {
		return err
	}
	if err := g.SetKeybinding("sql", gocui.KeyEnter, gocui.ModAlt, execQuery); err != nil {
		return err
	}

	return nil
}
开发者ID:gophergala2016,项目名称:dbcom,代码行数:39,代码来源:keys.go

示例6: refresh

func refresh(g *gocui.Gui, v *gocui.View) error {
	return g.Flush()
}
开发者ID:gophergala2016,项目名称:dbcom,代码行数:3,代码来源:actions.go

示例7: 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
}
开发者ID:grafov,项目名称:dbcom,代码行数:80,代码来源:panels.go


注:本文中的github.com/grafov/gocui.Gui类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。