コード例 #1
0
ファイル: util.go プロジェクト: mephux/komanda-cli
// 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
ファイル: stack.go プロジェクト: ketchupsalt/debugger
func (self *stack) draw(v *gocui.View, refresh bool) {
	if refresh {
		self.written = false
	}

	if self.written {
		return
	}

	v.Clear()

	self.sx, self.sy = v.Size()

	blob := self.contents[self.bump:]

	for off, b := range blob {
		cur := self.lastaddr + uint16(off) + uint16(self.bump)
		if off%2 == 0 {
			if cur == self.lastsp {
				fmt.Fprintf(v, "%0.4x:>>    ", cur)
			} else {
				fmt.Fprintf(v, "%0.4x:      ", cur)
			}

			fmt.Fprintf(v, "%0.2x", b)
		} else {
			fmt.Fprintf(v, "%0.2x\n", b)
		}
	}

	self.written = true
}
コード例 #3
0
ファイル: edit.go プロジェクト: YouROK/GoProjectManager
func getLine(g *gocui.Gui, v *gocui.View) error {
	var l string
	var err error

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

	maxX, maxY := g.Size()
	if v, err := g.SetView("msg", maxX/2-30, maxY/2, maxX/2+30, maxY/2+2); err != nil {
		if err != gocui.ErrorUnkView {
			return err
		}
		fmt.Fprintln(v, l)
		if err := g.SetCurrentView("msg"); err != nil {
			return err
		}
	}

	if v, err := g.View("main"); err != nil {
		if err != gocui.ErrorUnkView {
			return err
		}
		f := proj.GetFile(l)
		if f != nil {
			v.Clear()
			fmt.Fprintf(v, "%s", f.GetBody())
		}
		v.Editable = true
		v.Wrap = true
	}
	return nil
}
コード例 #4
0
ファイル: handler.go プロジェクト: hojgr/cook
func Handle(
	stdHandler *std.StdHandler,
	travianHandler *travian.TravianHandler,
	trav *travian.Game,
	ui *console.GUI,
	v *gocui.View) error {

	command := strings.Trim(v.Buffer(), "\n\r ")

	parsedCmd, _ := shellwords.Parse(command)

	if len(command) == 0 {
		return nil
	}

	if exists := stdHandler.Handle(parsedCmd, ui); exists {

	} else if exists := travianHandler.Handle(parsedCmd, trav, ui); exists {

	} else {
		ui.Println("Command not found")
	}

	v.Clear() // clears input view's input buffer

	return nil
}
コード例 #5
0
ファイル: tabbar.go プロジェクト: ketchupsalt/debugger
func (self *tabbar) renderBar(v *gocui.View) {
	v.Clear()

	for i, vs := range self.options {
		if i == self.selected {
			fmt.Fprintf(v, " [%s]", strings.ToUpper(vs))
		} else {
			fmt.Fprintf(v, " %s", vs)
		}
	}
}
コード例 #6
0
ファイル: dump.go プロジェクト: ketchupsalt/debugger
// draw a simple hex dump, filling available space
func (self *dump) draw(v *gocui.View, refresh bool) {
	if refresh {
		self.written = false
	}

	if self.written {
		return
	}

	v.Clear()

	self.sx, self.sy = v.Size()

	xpos := 0
	ypos := 0

	p, _ := fmt.Fprintf(v, "%0.4X:   ", self.addr)
	xpos += p
	bytesThisLine := 1

	for off, b := range self.contents {
		need := 3
		pad := " "
		if bytesThisLine != 1 && bytesThisLine%4 == 0 {
			need += 2
			pad = "   "
		}
		if xpos < (self.sx - need) {
			bytesThisLine++
			p, _ = fmt.Fprintf(v, "%.2x%s", b, pad)
			xpos += p
		} else {
			xpos = 0
			bytesThisLine = 2
			ypos += 1

			v.Write([]byte("\n"))

			if ypos == self.sy {
				break
			}

			p, _ = fmt.Fprintf(v, "%0.4X:   %0.2x ", self.addr+uint16(off), b)
			xpos += p
		}
	}

	v.Write([]byte("\n"))

	self.written = true
}
コード例 #7
0
ファイル: ui.go プロジェクト: garry415/goax
func send(g *gocui.Gui, v *gocui.View) error {
	v.SetOrigin(0, 0)
	message, err := v.Line(0)
	if err != nil {
		// We pressed enter and there's no text. Do nothing
		return nil
	}
	v.Clear()
	message = strings.Replace(message, string(0x00), "", -1) // Remove trailing 0x00
	if strings.TrimSpace(message) == "" {
		return nil
	}

	contacts := g.View("contacts")
	_, cy := contacts.Cursor()
	contact, err := contacts.Line(cy)
	if err != nil {
		return err
	}

	if message[0] == '/' {
		spl := strings.Split(message[1:], " ")
		if len(spl) == 0 {
			return nil
		}
		switch spl[0] {
		case "q":
			fallthrough
		case "quit":
			return gocui.ErrorQuit
		default:
			display(g, contact, fmt.Sprintf("! Unknown command: %#v", message))
		}
	} else {
		contacts := g.View("contacts")
		_, cy := contacts.Cursor()
		contact, err := contacts.Line(cy)
		if err != nil {
			return err
		}
		if contact != "Home" {
			displayTimestamped(g, contact, message)
			sendMessage(contact, message)
		}
	}

	return nil
}
コード例 #8
0
ファイル: gui.go プロジェクト: robert-butts/slackterm
// 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
}
コード例 #9
0
ファイル: gui.go プロジェクト: ak-67/vuvuzela
func (gc *GuiClient) readLine(_ *gocui.Gui, v *gocui.View) error {
	// HACK: pressing enter on startup causes panic
	if len(v.Buffer()) == 0 {
		return nil
	}
	_, cy := v.Cursor()
	line, err := v.Line(cy - 1)
	if err != nil {
		return err
	}
	if line == "" {
		return nil
	}
	v.Clear()

	return gc.handleLine(line)
}
コード例 #10
0
ファイル: util.go プロジェクト: mephux/komanda-cli
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
}
コード例 #11
0
ファイル: util.go プロジェクト: mephux/komanda-cli
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{}
	}
}