當前位置: 首頁>>代碼示例>>Golang>>正文


Golang C.add_history函數代碼示例

本文整理匯總了Golang中C.add_history函數的典型用法代碼示例。如果您正苦於以下問題:Golang add_history函數的具體用法?Golang add_history怎麽用?Golang add_history使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了add_history函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Readline

func Readline(prompt string) (string, error) {
	c_prompt := C.CString(prompt)
	defer C.free(unsafe.Pointer(c_prompt))

	c_line := C.readline(c_prompt)
	defer C.free(unsafe.Pointer(c_line))
	line := C.GoString(c_line)

	if c_line == nil {
		return "", errors.New("C.readline call failed")
	}
	C.add_history(c_line)

	// append to file
	f, e := os.OpenFile(history_path, os.O_APPEND|os.O_WRONLY, 0600)
	if e == nil {
		defer f.Close()

		_, e = f.WriteString(line + "\n")
		if e != nil {
			fmt.Printf("error writing to history")
		}
	}

	return line, nil
}
開發者ID:wcgh,項目名稱:plum,代碼行數:26,代碼來源:readline.go

示例2: Run

func (c *console) Run() {
	defer c.Stopped()

	re := regexp.MustCompile(`[\w\:\.]+`)
	prompt := C.CString("god> ")
	defer C.free(unsafe.Pointer(prompt))

	var line string

	for !c.StopRequested() {
		cline := C.readline(prompt)
		defer C.free(unsafe.Pointer(cline))
		if cline == nil {
			fmt.Printf("\n")
			break
		}

		C.add_history(cline)
		line = C.GoString(cline)
		args := re.FindAllString(line, -1)
		if len(args) > 0 {
			f := c.funcs[args[0]]
			if f != nil {
				var ret interface{}
				ext.PCall(
					func() {
						ret = f(args[1:])
					})
				ext.LogInfo("RUN_COMMAND\t%s\t%s\t%v\n", args[0], args[1:], ret)
			}
		}
	}
}
開發者ID:hycxa,項目名稱:gommo,代碼行數:33,代碼來源:console.go

示例3: receiveLine

//export receiveLine
func receiveLine(c *C.char) {
	if c == nil {
		activeTerm.quit()
	} else {
		activeTerm.Exec(C.GoString(c))
		C.add_history(c)
	}
}
開發者ID:alexcrichton,項目名稱:fargo,代碼行數:9,代碼來源:cli.go

示例4: AddHistory

// AddHistory places string at the end of the history list.
// Blank lines are discarded.
// (See add_history http://cnswww.cns.cwru.edu/php/chet/readline/history.html#IDX5)
func AddHistory(line string) {
	if len(line) == 0 || len(strings.TrimSpace(line)) == 0 {
		return
	}
	if unicode.IsSpace(rune(line[0])) { // ignorespace
		return
	}
	if prev, err := GetHistory(-1); err == nil && prev == line { // ignore consecutive dups
		return
	}
	cline := C.CString(line)
	C.add_history(cline)
	C.free(unsafe.Pointer(cline))
}
開發者ID:gwenn,項目名稱:goreadline,代碼行數:17,代碼來源:history.go

示例5: Rlwrap

// Rlwrap prompts the user with the given prompt string and calls the
// underlying readline function. If the input stream closes, Rlwrap returns an
// EOF error.
func Rlwrap(prompt string, record bool) (string, error) {
	p := C.CString(prompt)
	defer C.free(unsafe.Pointer(p))

	ret := C.readline(p)
	if ret == nil {
		return "", errors.New("EOF")
	}
	defer C.free(unsafe.Pointer(ret))

	if record {
		C.add_history(ret)
	}

	return C.GoString(ret), nil
}
開發者ID:jenareljam,項目名稱:minimega,代碼行數:19,代碼來源:goreadline.go

示例6: loadHistory

func loadHistory(filename string) error {
	content, err := ioutil.ReadFile(history_path)
	if err != nil {
		return err
	}

	for _, add_line := range strings.Split(string(content), "\n") {
		if add_line == "" {
			continue
		}
		c_add_line := C.CString(add_line)
		C.add_history(c_add_line)
		C.free(unsafe.Pointer(c_add_line))
	}

	return nil
}
開發者ID:wcgh,項目名稱:plum,代碼行數:17,代碼來源:readline.go

示例7: AddHistory

func AddHistory(s string) {
	p := C.CString(s)
	C.add_history(p)
	C.free(unsafe.Pointer(p))
}
開發者ID:jbuchbinder,項目名稱:go-readline,代碼行數:5,代碼來源:readline.go

示例8: AddHistory

// Add an item to the history.
func AddHistory(s string) {
	n := HistorySize()
	if n == 0 || s != GetHistory(n-1) {
		C.add_history(C.CString(s))
	}
}
開發者ID:ZhuHangpeng,項目名稱:mig,代碼行數:7,代碼來源:readline.go

示例9: AddHistory

func AddHistory(line string) {
	cLine := C.CString(line)
	C.add_history(cLine)
	C.free(unsafe.Pointer(cLine))
}
開發者ID:jsmorph,項目名稱:golisp,代碼行數:5,代碼來源:goreadline.go


注:本文中的C.add_history函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。