Esempio n. 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
}
Esempio n. 2
0
File: tui.go Progetto: Rompei/vuls
func cursorPageDown(g *gocui.Gui, v *gocui.View) error {
	jump := pageUpDownJumpCount(v)

	if v != nil {
		cx, cy := v.Cursor()
		ox, oy := v.Origin()
		ok, yLimit := movable(v, oy+cy+jump)
		_, maxY := v.Size()

		if !ok {
			if yLimit < maxY {
				v.SetCursor(cx, yLimit)
			} else {
				v.SetCursor(cx, maxY-1)
				v.SetOrigin(ox, yLimit-maxY+1)
			}
		} else if yLimit < oy+jump+maxY {
			if yLimit < maxY {
				v.SetCursor(cx, yLimit)
			} else {
				v.SetOrigin(ox, yLimit-maxY+1)
				v.SetCursor(cx, maxY-1)
			}
		} else {
			v.SetCursor(cx, cy)
			v.SetOrigin(ox, oy+jump)
		}
		onMovingCursorRedrawView(g, v)
	}
	return nil
}
Esempio n. 3
0
File: tui.go Progetto: Rompei/vuls
func cursorMoveTop(g *gocui.Gui, v *gocui.View) error {
	if v != nil {
		cx, _ := v.Cursor()
		v.SetCursor(cx, 0)
	}
	onMovingCursorRedrawView(g, v)
	return nil
}
Esempio n. 4
0
File: tui.go Progetto: Rompei/vuls
func cursorMoveMiddle(g *gocui.Gui, v *gocui.View) error {
	if v != nil {
		_, maxY := v.Size()
		cx, _ := v.Cursor()
		v.SetCursor(cx, maxY/2)
	}
	onMovingCursorRedrawView(g, v)
	return nil
}
Esempio n. 5
0
func cursorHome(g *gocui.Gui, v *gocui.View) error {
	ox, _ := v.Origin()
	cx, _ := v.Cursor()
	v.SetCursor(cx, 0)
	v.SetOrigin(ox, 0)

	updateTracksView(g, v)
	return nil
}
Esempio n. 6
0
func prev(g *ui.Gui, v *ui.View) error {
	cx, cy := v.Cursor()
	if cy-1 < 0 {
		return nil
	}
	err := v.SetCursor(cx, cy-1)
	printNodes()
	printNode(g)
	return err
}
Esempio n. 7
0
func next(g *ui.Gui, v *ui.View) error {
	cx, cy := v.Cursor()
	if cy+1 >= len(cli.Nodes) {
		return nil
	}
	err := v.SetCursor(cx, cy+1)
	printNodes()
	printNode(g)
	return err
}
Esempio n. 8
0
func FocusInputView(g *gocui.Gui, v *gocui.View) error {

	v.SetCursor(len(v.Buffer()+"")-1, 0)

	if _, err := g.SetCurrentView("input"); err != nil {
		return err
	}

	return nil
}
Esempio n. 9
0
func moveRight(g *gocui.Gui, v *gocui.View) error {
	if v != nil {
		cx, cy := v.Cursor()
		if err := v.SetCursor(cx+1, cy); err != nil {
			ox, oy := v.Origin()
			if err := v.SetOrigin(ox+1, oy); err != nil {
				return err
			}
		}
	}
	return nil
}
Esempio n. 10
0
File: demo2.go Progetto: balu-/gocui
func cursorLeft(g *gocui.Gui, v *gocui.View) error {
	if v != nil {
		ox, oy := v.Origin()
		cx, cy := v.Cursor()
		if err := v.SetCursor(cx-1, cy); err != nil && ox > 0 {
			if err := v.SetOrigin(ox-1, oy); err != nil {
				return err
			}
		}
	}
	return nil
}
Esempio n. 11
0
func cursorDown(g *gocui.Gui, v *gocui.View) error {
	if v != nil {
		cx, cy := v.Cursor()
		if err := v.SetCursor(cx, cy+1); err != nil {
			ox, oy := v.Origin()
			if err := v.SetOrigin(ox, oy+1); err != nil {
				return err
			}
		}
	}
	return nil
}
Esempio n. 12
0
func cursorUp(g *gocui.Gui, v *gocui.View) error {
	if v != nil {
		ox, oy := v.Origin()
		cx, cy := v.Cursor()
		if err := v.SetCursor(cx, cy-1); err != nil && oy > 0 {
			if err := v.SetOrigin(ox, oy-1); err != nil {
				return err
			}
		}
	}
	return nil
}
Esempio n. 13
0
File: tui.go Progetto: ymomoi/vuls
func cursorUp(g *gocui.Gui, v *gocui.View) error {
	if v != nil {
		ox, oy := v.Origin()
		cx, cy := v.Cursor()
		if err := v.SetCursor(cx, cy-1); err != nil && 0 < oy {
			if err := v.SetOrigin(ox, oy-1); err != nil {
				return err
			}
		}
	}
	onMovingCursorRedrawView(g, v)
	return nil
}
Esempio n. 14
0
func (runner *appRunner) cursorUp(g *gocui.Gui, v *gocui.View) error {
	if v != nil {
		ox, oy := v.Origin()
		cx, cy := v.Cursor()
		if err := v.SetCursor(cx, cy-1); err != nil && oy > 0 {
			if err := v.SetOrigin(ox, oy-1); err != nil {
				return err
			}
		}
		runner.layout(g)
	}
	return nil
}
Esempio n. 15
0
func moveDown(g *gocui.Gui, v *gocui.View) error {
	fmt.Println("yo")
	if v != nil {
		fmt.Println("hey")
		cx, cy := v.Cursor()
		if err := v.SetCursor(cx, cy+1); err != nil {
			ox, oy := v.Origin()
			if err := v.SetOrigin(ox, oy+1); err != nil {
				return err
			}
		}
	}
	return nil
}
Esempio n. 16
0
File: tui.go Progetto: Rompei/vuls
func cursorPageUp(g *gocui.Gui, v *gocui.View) error {
	jump := pageUpDownJumpCount(v)
	if v != nil {
		cx, _ := v.Cursor()
		ox, oy := v.Origin()
		if err := v.SetOrigin(ox, oy-jump); err != nil {
			v.SetOrigin(ox, 0)
			v.SetCursor(cx, 0)

		}
		onMovingCursorRedrawView(g, v)
	}
	return nil
}
Esempio n. 17
0
func cursorUp(g *gocui.Gui, v *gocui.View) error {
	offset := getOffsetFromTypedNumbers()
	ox, oy := v.Origin()
	cx, cy := v.Cursor()
	if err := v.SetCursor(cx, cy-offset); err != nil && oy > 0 {
		if err := v.SetOrigin(ox, oy-offset); err != nil {
			return err
		}
	}
	if v == gui.playlistsView {
		gui.updateTracksView()
	}
	return nil
}
Esempio n. 18
0
func cursorDown(g *gocui.Gui, v *gocui.View) error {
	offset := getOffsetFromTypedNumbers()
	if cx, cy := v.Cursor(); canGoToNewPosition(cy + offset) {
		if err := v.SetCursor(cx, cy+offset); err != nil {
			ox, oy := v.Origin()
			if err := v.SetOrigin(ox, oy+offset); err != nil {
				return err
			}
		}
		if v == gui.playlistsView {
			gui.updateTracksView()
		}
	}
	return nil
}
Esempio n. 19
0
func cursorPgup(g *gocui.Gui, v *gocui.View) error {
	ox, oy := v.Origin()
	cx, cy := v.Cursor()
	_, pageSizeY := v.Size()
	pageSizeY--

	if newOriginY := oy - pageSizeY; newOriginY > 0 {
		v.SetOrigin(ox, newOriginY)
		v.SetCursor(cx, cy)
	} else {
		v.SetOrigin(ox, 0)
		v.SetCursor(cx, cy)
	}
	updateTracksView(g, v)
	return nil
}
Esempio n. 20
0
File: demo2.go Progetto: vzex/gocui
func cursorLeft(g *gocui.Gui, v *gocui.View) error {
	if v != nil {
		cx, cy := v.Cursor()
		if err := v.SetCursor(cx-1, cy); err != nil {
			/*ox, oy := v.Origin()
			log.Println("deg", ox, oy)
			if ox > 0 {
				if err := v.SetOrigin(ox-1, oy); err != nil {
					log.Println(err)
					return nil
				}
			}*/
		}
	}
	return nil
}
Esempio n. 21
0
// TODO(strip newlines only at cursor position)
func inputEnter(g *gocui.Gui, v *gocui.View, getChannelIdChan chan<- ChannelIdRequest, sendMsgChan chan<- PutRtmMsg) error {
	text := strings.Replace(strings.TrimRight(v.Buffer(), " \n\t"), "\n", "", -1)
	log.Println("Entered Text: X" + text + "X")

	channelName, err := getSelectedChannelName(g)
	if err != nil {
		return err
	}
	channelId := GetChannelId(channelName, getChannelIdChan)

	sendMsgChan <- PutRtmMsg{channelId, text}

	v.Clear()
	v.SetCursor(0, 0)
	v.SetOrigin(0, 0)
	return nil
}
Esempio n. 22
0
func cursorEnd(g *gocui.Gui, v *gocui.View) error {
	if newIndex := getCurrentViewSize(v); newIndex > -1 {
		ox, _ := v.Origin()
		cx, _ := v.Cursor()
		_, sizeY := v.Size()
		sizeY--

		if newIndex > sizeY {
			v.SetOrigin(ox, newIndex-sizeY)
			v.SetCursor(cx, sizeY)
		} else {
			v.SetCursor(cx, newIndex)
		}

		updateTracksView(g, v)
	}
	return nil
}
Esempio n. 23
0
func goTo(g *gocui.Gui, v *gocui.View, position int) error {
	if canGoToAbsolutNewPosition(v, position) {
		position--
		ox, _ := v.Origin()
		cx, _ := v.Cursor()
		v.SetCursor(cx, 0)
		v.SetOrigin(ox, 0)
		if err := v.SetCursor(cx, position); err != nil {
			if err := v.SetOrigin(ox, position); err != nil {
				return err
			}
		}
		if v == gui.playlistsView && gui.tracksView != nil {
			gui.updateTracksView()
		}
	}
	return nil
}
Esempio n. 24
0
func cursorDown(g *gocui.Gui, v *gocui.View) error {
	var err error
	if v != nil {
		cx, cy := v.Cursor()
		if current_name, err = v.Line(cy + 1); err != nil {
			current_name = ""
		}
		if l, err := v.Line(cy + 2); err != nil && l == "" {
		} else {
			if err := v.SetCursor(cx, cy+1); err != nil {
				ox, oy := v.Origin()
				if err := v.SetOrigin(ox, oy+1); err != nil {
					return err
				}
			}
			updateProjInfo(g, v)
		}
	}
	return nil
}
Esempio n. 25
0
File: tui.go Progetto: Rompei/vuls
func cursorDown(g *gocui.Gui, v *gocui.View) error {
	if v != nil {
		cx, cy := v.Cursor()
		ox, oy := v.Origin()
		//  ok,  := movable(v, oy+cy+1)
		//  _, maxY := v.Size()
		ok, _ := movable(v, oy+cy+1)
		//  log.Info(cy, oy, maxY, yLimit)
		if !ok {
			return nil
		}
		if err := v.SetCursor(cx, cy+1); err != nil {
			if err := v.SetOrigin(ox, oy+1); err != nil {
				return err
			}
		}
		onMovingCursorRedrawView(g, v)
	}
	return nil
}
Esempio n. 26
0
func cursorPgdn(g *gocui.Gui, v *gocui.View) error {
	if maxSize := getCurrentViewSize(v); maxSize > -1 {
		ox, oy := v.Origin()
		cx, cy := v.Cursor()
		_, pageSizeY := v.Size()
		pageSizeY--

		newOriginY := oy + pageSizeY

		if hasMorePages(newOriginY, cy, maxSize) {
			v.SetOrigin(ox, newOriginY)
			v.SetCursor(cx, cy)
		} else if isNotInLastPage(oy, pageSizeY, maxSize) {
			v.SetOrigin(ox, maxSize-pageSizeY)
			v.SetCursor(cx, pageSizeY)
		}
		updateTracksView(g, v)
	}
	return nil
}
Esempio n. 27
0
func cursorDown(g *gocui.Gui, v *gocui.View) error {
	if v == nil {
		return nil
	}
	cx, cy := v.Cursor()

	nextLine, err := v.Line(cy + 1)
	if err != nil {
		return err
	}
	if nextLine == "" {
		return nil
	}

	if err := v.SetCursor(cx, cy+1); err != nil {
		ox, oy := v.Origin()
		if err := v.SetOrigin(ox, oy+1); err != nil {
			return err
		}
	}
	return nil
}
Esempio n. 28
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{}
	}
}
Esempio n. 29
0
func GetLine(g *gocui.Gui, v *gocui.View) error {
	// _, cy := v.Cursor()
	// if line, err = v.Line(0); err != nil {
	// line = ""
	// }

	line := v.Buffer()

	// logger.Logger.Printf("LINE %s\n", line)

	if len(line) <= 0 {
		// return errors.New("input line empty")
		v.Clear()
		v.SetCursor(0, 0)
		return nil
	}

	line = strings.Replace(line, "\x00", "", -1)
	line = strings.Replace(line, "\n", "", -1)

	InputHistory.Add(line)

	if strings.HasPrefix(line, "//") || !strings.HasPrefix(line, "/") {
		if len(Server.CurrentChannel) > 0 {

			Server.Exec(Server.CurrentChannel, func(g *gocui.Gui, v *gocui.View, s *client.Server) error {
				if Server.Client.Connected() {
					// logger.Logger.Println("SEND:::", spew.Sdump(line))

					go Server.Client.Privmsg(Server.CurrentChannel, line)
				}
				return nil
			})

			if mainView, err := g.View(Server.CurrentChannel); err != nil {
				return err
			} else {
				if mainView.Name() != client.StatusChannel {

					c := Server.FindChannel(Server.CurrentChannel)

					timestamp := time.Now().Format("03:04")
					fmt.Fprintf(mainView, "[%s] -> %s: %s\n",
						ui.ColorString(ui.TimestampColor, timestamp),
						myNickColor(c.FindUser(Server.Client.Me().Nick).String(false)),
						myTextColor(line))
				}
			}
		}
		// send text
	} else {
		split := strings.Split(strings.Replace(line[1:], "\x00", "", -1), " ")

		// logger.Logger.Println("IN COMMAND!!!", line, spew.Sdump(split))

		// mainView, _ := g.View(client.StatusChannel)
		// fmt.Fprintln(mainView, "$ COMMAND = ", split[0], len(split))

		// TODO: what was this?
		if len(split) <= 1 {
			if split[0] == "p" || split[0] == "part" {
				command.Run(split[0], []string{"", Server.CurrentChannel})
				v.Clear()
				v.SetCursor(0, 0)
				return nil
			}
		}

		if err := command.Run(split[0], split); err != nil {
			client.StatusMessage(v, err.Error())
		}
	}

	// idleInputText := fmt.Sprintf("[%s] ", client.StatusChannel)

	// if len(command.CurrentChannel) > 0 {
	// idleInputText = fmt.Sprintf("[%s] ", command.CurrentChannel)
	// }

	// fmt.Fprint(v, idleInputText)
	// v.SetCursor(len(idleInputText), 0)

	v.Clear()
	v.SetCursor(0, 0)

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

	FocusAndResetAll(g, v)

	return nil
}