Patchwork [U-Boot,09/16] drivers/video/cfb_console.c: Add functions for moving with cursor

login
register
mail settings
Submitter Pali Rohár
Date Dec. 17, 2011, 5:03 p.m.
Message ID <1324141398-14859-9-git-send-email-pali.rohar@gmail.com>
Download mbox | patch
Permalink /patch/132010/
State Changes Requested
Headers show

Comments

Pali Rohár - Dec. 17, 2011, 5:03 p.m.
* console_cursor_fix - check and fix cursor position (if it is not out of screen)
 * console_cursor_up, console_cursor_down, console_cursor_left, console_cursor_right and console_cursor_set_position for changing 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>
---
 drivers/video/cfb_console.c |   64 +++++++++++++++++++++++++++++++++++++++----
 1 files changed, 58 insertions(+), 6 deletions(-)
Mike Frysinger - Dec. 18, 2011, 7 p.m.
On Saturday 17 December 2011 12:03:11 Pali Rohár wrote:
>  * console_cursor_fix - check and fix cursor position (if it is not out of
> screen) * console_cursor_up, console_cursor_down, console_cursor_left,
> console_cursor_right and console_cursor_set_position for changing cursor
> position * console_newline - added param to specify count of creating new
> lines * console_previewsline - opposite of console_newline

you need to line wrap your changelogs
-mike

Patch

diff --git a/drivers/video/cfb_console.c b/drivers/video/cfb_console.c
index 7a4f0f3..9e0f665 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;
 		}
 	}