当前位置: 首页>>代码示例>>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;未经允许,请勿转载。