Exemplo n.º 1
0
// Retrieve a line from the history.
func GetHistory(i int) string {
	e := C.history_get(C.int(i + 1))
	if e == nil {
		return ""
	}
	return C.GoString(e.line)
}
Exemplo n.º 2
0
// GetHistory returns the history entry at position index, starting from 0.
// If there is no entry there, or if index is greater than the history length, return an error.
// (See history_get http://cnswww.cns.cwru.edu/php/chet/readline/history.html#IDX17)
func GetHistory(index int32) (string, error) {
	length := HistoryLength()
	if index < 0 {
		index += length
	}
	if index < 0 || index >= length {
		return "", fmt.Errorf("invalid index %d", index)
	}
	index += HistoryBase() // TODO
	entry := C.history_get(C.int(index))
	if entry == nil {
		return "", fmt.Errorf("invalid index %d", index)
	}
	return C.GoString(entry.line), nil
}