Patchwork [U-Boot,07/14] cfb_console: Add functions for moving with cursor

login
register
mail settings
Submitter Pali Rohár
Date Jan. 24, 2012, 2:28 p.m.
Message ID <1327415291-13260-8-git-send-email-pali.rohar@gmail.com>
Download mbox | patch
Permalink /patch/137572/
State Superseded
Delegated to: Anatolij Gustschin
Headers show

Comments

Pali Rohár - Jan. 24, 2012, 2:28 p.m.
* console_cursor_fix - fix cursor position (check for out of screen)
 * console_cursor_up, console_cursor_down, console_cursor_left,
   console_cursor_right, console_cursor_set_position for change cursor position
 * console_newline - added param to specify count of creating new lines
 * console_previewsline - opposite of console_newline

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
---
Changes since original version:
   - Fixed commit message

 drivers/video/cfb_console.c |   64 +++++++++++++++++++++++++++++++++++++++----
 1 files changed, 58 insertions(+), 6 deletions(-)

Patch

diff --git a/drivers/video/cfb_console.c b/drivers/video/cfb_console.c
index b74d6d0..3823eae 100644
--- a/drivers/video/cfb_console.c
+++ b/drivers/video/cfb_console.c
@@ -773,9 +773,54 @@  static void console_back(void)
 	CURSOR_SET;
 }
 
-static void console_newline(void)
+static void console_cursor_fix(void)
 {
-	console_row++;
+	if (console_row < 0)
+		console_row = 0;
+	if (console_row >= CONSOLE_ROWS)
+		console_row = CONSOLE_ROWS-1;
+	if (console_col < 0)
+		console_col = 0;
+	if (console_col >= CONSOLE_COLS)
+		console_col = CONSOLE_COLS-1;
+}
+
+static void console_cursor_up(int n)
+{
+	console_row -= n;
+	console_cursor_fix();
+}
+
+static void console_cursor_down(int n)
+{
+	console_row += n;
+	console_cursor_fix();
+}
+
+static void console_cursor_left(int n)
+{
+	console_col -= n;
+	console_cursor_fix();
+}
+
+static void console_cursor_right(int n)
+{
+	console_col += n;
+	console_cursor_fix();
+}
+
+static void console_cursor_set_position(int row, int col)
+{
+	if (console_row != -1)
+		console_row = row;
+	if (console_col != -1)
+		console_col = col;
+	console_cursor_fix();
+}
+
+static void console_newline(int n)
+{
+	console_row += n;
 	console_col = 0;
 
 	/* Check if we need to scroll the terminal */
@@ -784,10 +829,17 @@  static void console_newline(void)
 		console_scrollup();
 
 		/* Decrement row number */
-		console_row--;
+		console_row = CONSOLE_ROWS-1;
 	}
 }
 
+static void console_previewsline(int n)
+{
+	/* FIXME: also scroll terminal ? */
+	console_row -= n;
+	console_cursor_fix();
+}
+
 static void console_cr(void)
 {
 	console_col = 0;
@@ -806,7 +858,7 @@  void video_putc(const char c)
 
 	case '\n':		/* next line */
 		if (console_col || (!console_col && nl))
-			console_newline();
+			console_newline(1);
 		nl = 1;
 		break;
 
@@ -815,7 +867,7 @@  void video_putc(const char c)
 		console_col &= ~0x0007;
 
 		if (console_col >= CONSOLE_COLS)
-			console_newline();
+			console_newline(1);
 		break;
 
 	case 8:		/* backspace */
@@ -829,7 +881,7 @@  void video_putc(const char c)
 
 		/* check for newline */
 		if (console_col >= CONSOLE_COLS) {
-			console_newline();
+			console_newline(1);
 			nl = 0;
 		}
 	}