func Scan(prompt string) (line string, end bool) { pt := C.CString(prompt) defer C.free(unsafe.Pointer(pt)) l := C.linenoise(pt) defer C.free(unsafe.Pointer(l)) if l == nil { end = true } else { end = false } return C.GoString(l), end }
func line(prompt string) (string, error) { promptCString := C.CString(prompt) resultCString := C.linenoise(promptCString) C.free(unsafe.Pointer(promptCString)) defer C.free(unsafe.Pointer(resultCString)) if resultCString == nil { return "", errors.New("quited by a signal") } result := C.GoString(resultCString) return result, nil }
// Line displays given string and returns line from user input. func Line(prompt string) (string, error) { // char *linenoise(const char *prompt); promptCString := C.CString(prompt) resultCString := C.linenoise(promptCString) C.free(unsafe.Pointer(promptCString)) defer C.free(unsafe.Pointer(resultCString)) if resultCString == nil { return "", KillSignalError } result := C.GoString(resultCString) return result, nil }