本文整理匯總了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
}
示例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)
}
}
}
}
示例3: receiveLine
//export receiveLine
func receiveLine(c *C.char) {
if c == nil {
activeTerm.quit()
} else {
activeTerm.Exec(C.GoString(c))
C.add_history(c)
}
}
示例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))
}
示例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
}
示例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
}
示例7: AddHistory
func AddHistory(s string) {
p := C.CString(s)
C.add_history(p)
C.free(unsafe.Pointer(p))
}
示例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))
}
}
示例9: AddHistory
func AddHistory(line string) {
cLine := C.CString(line)
C.add_history(cLine)
C.free(unsafe.Pointer(cLine))
}