示例#1
0
// ReadHistory loads a readline history file.
// The default filename is ~/.history.
func ReadHistoryFile(s string) error {
	p := C.CString(s)
	defer C.free(unsafe.Pointer(p))
	if errno := C.read_history(p); errno != 0 {
		return syscall.Errno(errno)
	}
	return nil
}
示例#2
0
// Load the history from a file.
func LoadHistory(path string) error {
	p := C.CString(path)
	e := C.read_history(p)
	C.free(unsafe.Pointer(p))

	if e == 0 {
		return nil
	}
	return syscall.Errno(e)
}
示例#3
0
// ReadHistory adds the content of filename to the history list, a line at a time.
// If filename is "", then read from '~/.history'.
// (See read_history http://cnswww.cns.cwru.edu/php/chet/readline/history.html#IDX27)
func ReadHistory(filename string) (bool, error) {
	var cfilename *C.char
	if len(filename) != 0 {
		cfilename = C.CString(filename)
	}
	err := C.read_history(cfilename)
	if cfilename != nil {
		C.free(unsafe.Pointer(cfilename))
	}
	if err != 0 {
		e := syscall.Errno(err)
		if e == syscall.ENOENT { // ignored when the file doesn't exist.
			return false, nil
		}
		return false, e
	}
	return true, nil
}
示例#4
0
func LoadHistoryFromFile(fileName string) {
	cFileName := C.CString(fileName)
	C.read_history(cFileName)
	C.free(unsafe.Pointer(cFileName))
}