* flickering effect with some slow terminal, but the lesser sequences
* the more compatible.
*
- * CHA (Cursor Horizontal Absolute)
- * Sequence: ESC [ n G
- * Effect: moves cursor to column n (1 based)
- *
* EL (Erase Line)
* Sequence: ESC [ n K
* Effect: if n is 0 or missing, clear from cursor to end of line
* Sequence: ESC [ n C
* Effect: moves cursor forward of n chars
*
+ * CR (Carriage Return)
+ * Sequence: \r
+ * Effect: moves cursor to column 1
+ *
* The following are used to clear the screen: ESC [ H ESC [ 2 J
* This is actually composed of two sequences:
*
free(history[j]);
free(history);
history = NULL;
+ history_len = 0;
}
}
linenoiseHistoryFree();
}
-/* gcc/glibc insists that we care about the return code of write! */
+/* gcc/glibc insists that we care about the return code of write!
+ * Clarification: This means that a void-cast like "(void) (EXPR)"
+ * does not work.
+ */
#define IGNORE_RC(EXPR) if (EXPR) {}
/* This is fdprintf() on some systems, but use a different
static void cursorToLeft(struct current *current)
{
- fd_printf(current->fd, "\x1b[1G");
+ fd_printf(current->fd, "\r");
}
static int outputChars(struct current *current, const char *buf, int len)
static void outputControlChar(struct current *current, char ch)
{
- fd_printf(current->fd, "\033[7m^%c\033[0m", ch);
+ fd_printf(current->fd, "\x1b[7m^%c\x1b[0m", ch);
}
static void eraseEol(struct current *current)
static void setCursorPos(struct current *current, int x)
{
- fd_printf(current->fd, "\x1b[1G\x1b[%dC", x);
+ fd_printf(current->fd, "\r\x1b[%dC", x);
}
/**
if (current->cols == 0) {
current->cols = 80;
- /* Move cursor far right and report cursor position */
- fd_printf(current->fd, "\x1b[999G" "\x1b[6n");
+ /* Move cursor far right and report cursor position, then back to the left */
+ fd_printf(current->fd, "\x1b[999C" "\x1b[6n");
/* Parse the response: ESC [ rows ; cols R */
if (fd_read_char(current->fd, 100) == 0x1b && fd_read_char(current->fd, 100) == '[') {
{
COORD pos = { (SHORT)current->x, (SHORT)current->y };
DWORD n;
-
+
WriteConsoleOutputCharacter(current->outh, buf, len, pos, &n);
current->x += len;
return 0;
/* Only autocomplete when the callback is set. It returns < 0 when
* there was an error reading from fd. Otherwise it will return the
* character that should be handled next. */
- if (c == 9 && completionCallback != NULL) {
+ if (c == '\t' && current->pos == current->chars && completionCallback != NULL) {
c = completeLine(current);
/* Return on errors */
if (c < 0) return current->len;
char buf[LINENOISE_MAX_LINE];
if (enableRawMode(¤t) == -1) {
- printf("%s", prompt);
+ printf("%s", prompt);
fflush(stdout);
if (fgets(buf, sizeof(buf), stdin) == NULL) {
- return NULL;
+ return NULL;
}
count = strlen(buf);
if (count && buf[count-1] == '\n') {
return 1;
}
+int linenoiseHistoryGetMaxLen(void) {
+ return history_max_len;
+}
+
int linenoiseHistorySetMaxLen(int len) {
char **newHistory;