예제 #1
0
func editValue(g *gocui.Gui, v *gocui.View) error {
	var l string
	var err error

	_, cy := v.Cursor()
	global.placeholder, _ = myViews.placeholders.Line(cy)
	if l, err = myViews.values.Line(cy); err != nil {
		l = ""
	}

	maxX, maxY := g.Size()
	if v, err := g.SetView("dialog", maxX/2-30, maxY/2, maxX/2+30, maxY/2+2); err != nil {
		if err != gocui.ErrUnknownView {
			return err
		}
		lx := len(l)
		fmt.Fprintln(v, l[:lx])
		if l == " " {
			lx = 0
		}
		v.SetCursor(lx, 0)
		if err := g.SetCurrentView("dialog"); err != nil {
			return err
		}
		v.Editable = true
		myViews.dialog = v
	}
	return nil
}
예제 #2
0
func moveCursor(v *gocui.View, direction int) error {
	if v != nil {
		ox, oy := v.Origin()
		cx, cy := v.Cursor()
		err := v.SetCursor(cx, cy+direction)
		if v.Name() == "placeholders" {
			myViews.values.SetCursor(cx, cy+direction)
		}
		if err != nil && (direction == 1 || (direction == -1 && oy > 0)) {
			if v.Name() == "placeholders" {
				myViews.values.SetOrigin(ox, oy+direction)
			}
			if err := v.SetOrigin(ox, oy+direction); err != nil {
				return err
			}
		}
	}
	return nil
}