From fee58ea68cdd08e7fb298960e12b2c921254a75b Mon Sep 17 00:00:00 2001
From: Ron Yorston <rmy@pobox.com>
Date: Mon, 7 Apr 2014 13:30:28 +0100
Subject: Implement ANSI escape sequences for cursor up/forward

These escape sequences are required for proper handling of line
editing when the input exceeds the console width.
---
 win32/winansi.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/win32/winansi.c b/win32/winansi.c
index d929bcc66..415105fcd 100644
--- a/win32/winansi.c
+++ b/win32/winansi.c
@@ -123,6 +123,30 @@ static void erase_till_end_of_screen(void)
 					    pos, &dummy);
 }
 
+static void move_cursor_up(int n)
+{
+	CONSOLE_SCREEN_BUFFER_INFO sbi;
+
+	if (!console)
+		return;
+
+	GetConsoleScreenBufferInfo(console, &sbi);
+	sbi.dwCursorPosition.Y -= n;
+	SetConsoleCursorPosition(console, sbi.dwCursorPosition);
+}
+
+static void move_cursor_forward(int n)
+{
+	CONSOLE_SCREEN_BUFFER_INFO sbi;
+
+	if (!console)
+		return;
+
+	GetConsoleScreenBufferInfo(console, &sbi);
+	sbi.dwCursorPosition.X += n;
+	SetConsoleCursorPosition(console, sbi.dwCursorPosition);
+}
+
 static void move_cursor_back(int n)
 {
 	CONSOLE_SCREEN_BUFFER_INFO sbi;
@@ -285,6 +309,12 @@ static const char *set_attr(const char *str)
 
 		set_console_attr();
 		break;
+	case 'A':
+		move_cursor_up(strtol(str, (char **)&str, 10));
+		break;
+	case 'C':
+		move_cursor_forward(strtol(str, (char **)&str, 10));
+		break;
 	case 'D':
 		move_cursor_back(strtol(str, (char **)&str, 10));
 		break;
-- 
cgit v1.2.3-55-g6feb