Exemplo n.º 1
0
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
}
Exemplo n.º 2
0
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
}
Exemplo n.º 3
0
// 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
}