Пример #1
0
// TODO: fix \x00 issues
func tabUpdateInput(input *gocui.View) (string, bool) {

	// logger.Logger.Println(spew.Sdump(input.Buffer()))

	search := strings.TrimSpace(input.ViewBuffer())
	searchSplit := strings.Split(search, " ")
	search = searchSplit[len(searchSplit)-1]

	if inCacheTab {
		cacheTabIndex++

		if cacheTabIndex > len(cacheTabResults)-1 {
			cacheTabIndex = 0
		}

		searchSplit[len(searchSplit)-1] = cacheTabResults[cacheTabIndex]

		newInputData := strings.Join(searchSplit, " ")

		input.Clear()

		if !strings.HasPrefix(newInputData, "/") && !strings.HasPrefix(newInputData, "#") {
			newInputData = newInputData + ":"
		}

		fmt.Fprint(input, newInputData+" ")
		input.SetCursor(len(input.Buffer())-1, 0)

		// logger.Logger.Println(spew.Sdump(newInputData + ""))
		// logger.Logger.Printf("WORD %s -- %s -- %s\n", search, cacheTabSearch, cacheTabResults[cacheTabIndex])
		return "", true
	}

	return search, false
}
Пример #2
0
func saveVisualMain(g *gocui.Gui, v *gocui.View) error {
	f, err := ioutil.TempFile("", "gocui_demo_")
	if err != nil {
		return err
	}
	defer f.Close()

	vb := v.ViewBuffer()
	if _, err := io.Copy(f, strings.NewReader(vb)); err != nil {
		return err
	}
	return nil
}
Пример #3
0
func runCmd(g *gocui.Gui, v *gocui.View) error {
	if !cmdMode {
		return nil
	}

	v, err := g.View("menu")
	if err != nil {
		return err
	}

	vb := v.ViewBuffer()
	cmdString := strings.TrimSpace(strings.TrimPrefix(vb, fmt.Sprintf(cmdPrefix, cTubes.Selected)))

	if cmdString == "" {
		return nil
	}

	debugLog("Received cmd: ", cmdString)

	tv, err := g.View("tubes")
	if err != nil {
		return err
	}

	PrintString(tv, cmdString+": ")

	cmd, err := ParseCmd(cmdString)
	if err != nil {
		PrintLine(tv, err.Error())
	} else {
		if err := cmd.Run(tv); err != nil {
			PrintLine(tv, err.Error())
		}
	}

	PrintLine(tv, "------------")

	return reloadMenu(g)
}
Пример #4
0
func quit(g *gocui.Gui, v *gocui.View) error {
	vbuf = v.ViewBuffer()
	buf = v.Buffer()
	return gocui.ErrQuit
}
Пример #5
0
func simpleEditor(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) {
	var tab = false
	var inHistroy = false

	switch {
	case key == gocui.KeyTab:
		tab = true
	case ch != 0 && mod == 0:
		v.EditWrite(ch)
	case key == gocui.KeySpace:
		v.EditWrite(' ')
	case key == gocui.KeyBackspace || key == gocui.KeyBackspace2:
		v.EditDelete(true)
	case key == gocui.KeyDelete:
		v.EditDelete(false)
	case key == gocui.KeyInsert:
		v.Overwrite = !v.Overwrite
	case key == gocui.KeyEnter:

		if line := v.ViewBuffer(); len(line) > 0 {
			GetLine(Server.Gui, v)
		}
		// v.EditNewLine()
		// v.Rewind()

	case key == gocui.KeyArrowDown:
		inHistroy = true

		if line := InputHistory.Next(); len(line) > 0 {
			v.Clear()
			fmt.Fprint(v, line)
			v.SetCursor(len(v.Buffer()), 0)
		}
	case key == gocui.KeyArrowUp:
		inHistroy = true

		if line := InputHistory.Prev(); len(line) > 0 {
			v.Clear()
			fmt.Fprint(v, line)
			v.SetCursor(len(v.Buffer()), 0)
		}
	case key == gocui.KeyArrowLeft:
		v.MoveCursor(-1, 0, false)
	case key == gocui.KeyArrowRight:

		cx, _ := v.Cursor()
		line := v.ViewBuffer()

		logger.Logger.Println(len(line), cx)
		logger.Logger.Println(spew.Sdump(line))

		// if cx == 0 {
		// v.MoveCursor(-1, 0, false)
		if cx < len(line)-1 {
			v.MoveCursor(1, 0, false)
		}

	case key == gocui.KeyCtrlA:
		v.SetCursor(0, 0)
	case key == gocui.KeyCtrlK:
		v.Clear()
		v.SetCursor(0, 0)
	case key == gocui.KeyCtrlE:
		v.SetCursor(len(v.Buffer())-1, 0)
	case key == gocui.KeyCtrlLsqBracket:
		// logger.Logger.Println("word...")
	}

	if !inHistroy {
		// InputHistory.Current()
	}

	if !tab {
		// logger.Logger.Print("CALL\n")

		inCacheTab = false
		cacheTabSearch = ""
		cacheTabResults = []string{}
	}
}