The high level function that is the main API of the linenoise library. * This function checks if the terminal has basic capabilities, just checking * for a blacklist of stupid terminals, and later either calls the line * editing function or uses dummy fgets() so that you will be able to type * something even in the most desperate of the conditions. */
| 3873 | * editing function or uses dummy fgets() so that you will be able to type |
| 3874 | * something even in the most desperate of the conditions. */ |
| 3875 | char* linenoise(const char* prompt, const char* continuePrompt, |
| 3876 | const char* selectedContinuePrompt) { |
| 3877 | char buf[LINENOISE_MAX_LINE]; |
| 3878 | int count; |
| 3879 | |
| 3880 | if (!isatty(STDIN_FILENO)) { |
| 3881 | /* Not a tty: read from file / pipe. In this mode we don't want any |
| 3882 | * limit to the line size, so we call a function to handle that. */ |
| 3883 | return linenoiseNoTTY(); |
| 3884 | } else if (isUnsupportedTerm()) { |
| 3885 | size_t len; |
| 3886 | |
| 3887 | printf("%s", prompt); |
| 3888 | fflush(stdout); |
| 3889 | if (fgets(buf, LINENOISE_MAX_LINE, stdin) == NULL) |
| 3890 | return NULL; |
| 3891 | len = strlen(buf); |
| 3892 | while (len && (buf[len - 1] == '\n' || buf[len - 1] == '\r')) { |
| 3893 | len--; |
| 3894 | buf[len] = '\0'; |
| 3895 | } |
| 3896 | return strdup(buf); |
| 3897 | } else { |
| 3898 | count = |
| 3899 | linenoiseRaw(buf, LINENOISE_MAX_LINE, prompt, continuePrompt, selectedContinuePrompt); |
| 3900 | if (count == -1) |
| 3901 | return NULL; |
| 3902 | return strdup(buf); |
| 3903 | } |
| 3904 | } |
| 3905 | |
| 3906 | /* This is just a wrapper the user may want to call in order to make sure |
| 3907 | * the linenoise returned buffer is freed with the same allocator it was |
no test coverage detected