Index: uspace/app/edit/edit.c
===================================================================
--- uspace/app/edit/edit.c	(revision caad59aaedb0d9190a12111b1fd41fed41df0d07)
+++ uspace/app/edit/edit.c	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
@@ -40,5 +40,5 @@
 #include <vfs/vfs.h>
 #include <io/console.h>
-#include <io/color.h>
+#include <io/style.h>
 #include <io/keycode.h>
 #include <errno.h>
@@ -100,5 +100,6 @@
 static bool cursor_visible;
 
-static int scr_rows, scr_columns;
+static ipcarg_t scr_rows;
+static ipcarg_t scr_columns;
 
 #define ROW_BUF_SIZE 4096
@@ -505,8 +506,8 @@
 	asprintf(&str, "%s: %s", prompt, init_value);
 	status_display(str);
-	console_goto(con, 1 + str_length(str), scr_rows - 1);
+	console_set_pos(con, 1 + str_length(str), scr_rows - 1);
 	free(str);
 
-	console_set_color(con, COLOR_WHITE, COLOR_BLACK, 0);
+	console_set_style(con, STYLE_INVERTED);
 
 	max_len = min(INFNAME_MAX_LEN, scr_columns - 4 - str_length(prompt));
@@ -552,5 +553,5 @@
 	str = wstr_to_astr(buffer);
 
-	console_set_color(con, COLOR_BLACK, COLOR_WHITE, 0);
+	console_set_style(con, STYLE_NORMAL);
 
 	return str;
@@ -671,5 +672,4 @@
 {
 	int sh_rows, rows;
-	int i, j;
 
 	sheet_get_num_rows(&doc.sh, &sh_rows);
@@ -678,11 +678,13 @@
 	/* Draw rows from the sheet. */
 
-	console_goto(con, 0, 0);
+	console_set_pos(con, 0, 0);
 	pane_row_range_display(0, rows);
 
 	/* Clear the remaining rows if file is short. */
-
+	
+	int i;
+	ipcarg_t j;
 	for (i = rows; i < pane.rows; ++i) {
-		console_goto(con, 0, i);
+		console_set_pos(con, 0, i);
 		for (j = 0; j < scr_columns; ++j)
 			putchar(' ');
@@ -736,5 +738,5 @@
 	/* Draw rows from the sheet. */
 
-	console_goto(con, 0, 0);
+	console_set_pos(con, 0, 0);
 	for (i = r0; i < r1; ++i) {
 		/* Starting point for row display */
@@ -756,9 +758,9 @@
 		    coord_cmp(&rbc, &csel_end) < 0) {
 			fflush(stdout);
-			console_set_color(con, COLOR_BLACK, COLOR_RED, 0);
+			console_set_style(con, STYLE_SELECTED);
 			fflush(stdout);
 		}
 
-		console_goto(con, 0, i);
+		console_set_pos(con, 0, i);
 		size = str_size(row_buf);
 		pos = 0;
@@ -767,5 +769,5 @@
 			if ((csel_start.row == rbc.row) && (csel_start.column == s_column)) {
 				fflush(stdout);
-				console_set_color(con, COLOR_BLACK, COLOR_RED, 0);
+				console_set_style(con, STYLE_SELECTED);
 				fflush(stdout);
 			}
@@ -773,5 +775,5 @@
 			if ((csel_end.row == rbc.row) && (csel_end.column == s_column)) {
 				fflush(stdout);
-				console_set_color(con, COLOR_BLACK, COLOR_WHITE, 0);
+				console_set_style(con, STYLE_NORMAL);
 				fflush(stdout);
 			}
@@ -793,5 +795,5 @@
 		if ((csel_end.row == rbc.row) && (csel_end.column == s_column)) {
 			fflush(stdout);
-			console_set_color(con, COLOR_BLACK, COLOR_WHITE, 0);
+			console_set_style(con, STYLE_NORMAL);
 			fflush(stdout);
 		}
@@ -807,5 +809,5 @@
 			putchar(' ');
 		fflush(stdout);
-		console_set_color(con, COLOR_BLACK, COLOR_WHITE, 0);
+		console_set_style(con, STYLE_NORMAL);
 	}
 
@@ -824,11 +826,11 @@
 	const char *fname = (doc.file_name != NULL) ? doc.file_name : "<unnamed>";
 
-	console_goto(con, 0, scr_rows - 1);
-	console_set_color(con, COLOR_WHITE, COLOR_BLACK, 0);
+	console_set_pos(con, 0, scr_rows - 1);
+	console_set_style(con, STYLE_INVERTED);
 	int n = printf(" %d, %d: File '%s'. Ctrl-Q Quit  Ctrl-S Save  "
 	    "Ctrl-E Save As", coord.row, coord.column, fname);
 	printf("%*s", scr_columns - 1 - n, "");
 	fflush(stdout);
-	console_set_color(con, COLOR_BLACK, COLOR_WHITE, 0);
+	console_set_style(con, STYLE_NORMAL);
 
 	pane.rflags |= REDRAW_CARET;
@@ -844,5 +846,5 @@
 
 	spt_get_coord(&caret_pt, &coord);
-	console_goto(con, coord.column - pane.sh_column,
+	console_set_pos(con, coord.column - pane.sh_column,
 	    coord.row - pane.sh_row);
 }
@@ -1149,9 +1151,9 @@
 static void status_display(char const *str)
 {
-	console_goto(con, 0, scr_rows - 1);
-	console_set_color(con, COLOR_WHITE, COLOR_BLACK, 0);
+	console_set_pos(con, 0, scr_rows - 1);
+	console_set_style(con, STYLE_INVERTED);
 	printf(" %*s ", -(scr_columns - 3), str);
 	fflush(stdout);
-	console_set_color(con, COLOR_BLACK, COLOR_WHITE, 0);
+	console_set_style(con, STYLE_NORMAL);
 
 	pane.rflags |= REDRAW_CARET;
Index: uspace/app/tester/console/console1.c
===================================================================
--- uspace/app/tester/console/console1.c	(revision caad59aaedb0d9190a12111b1fd41fed41df0d07)
+++ uspace/app/tester/console/console1.c	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
@@ -53,11 +53,17 @@
 		fflush(stdout);
 		console_set_style(fphone(stdout), STYLE_NORMAL);
-		printf("normal ");
+		printf(" normal ");
 		fflush(stdout);
 		console_set_style(fphone(stdout), STYLE_EMPHASIS);
-		printf("emphasized");
+		printf(" emphasized ");
+		fflush(stdout);
+		console_set_style(fphone(stdout), STYLE_INVERTED);
+		printf(" inverted ");
+		fflush(stdout);
+		console_set_style(fphone(stdout), STYLE_SELECTED);
+		printf(" selected ");
 		fflush(stdout);
 		console_set_style(fphone(stdout), STYLE_NORMAL);
-		printf(".\n");
+		printf("\n");
 		
 		unsigned int i;
@@ -73,5 +79,5 @@
 			}
 			fflush(stdout);
-			console_set_color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);
+			console_set_style(fphone(stdout), STYLE_NORMAL);
 			putchar('\n');
 		}
@@ -86,5 +92,5 @@
 			}
 			fflush(stdout);
-			console_set_color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);
+			console_set_style(fphone(stdout), STYLE_NORMAL);
 			putchar('\n');
 		}
@@ -94,5 +100,5 @@
 		for (i = 0; i < 255; i += 16) {
 			fflush(stdout);
-			console_set_rgb_color(fphone(stdout), 0xffffff, i << 16);
+			console_set_rgb_color(fphone(stdout), (255 - i) << 16, i << 16);
 			putchar('X');
 		}
@@ -103,5 +109,5 @@
 		for (i = 0; i < 255; i += 16) {
 			fflush(stdout);
-			console_set_rgb_color(fphone(stdout), 0xffffff, i << 8);
+			console_set_rgb_color(fphone(stdout), (255 - i) << 8, i << 8);
 			putchar('X');
 		}
@@ -112,9 +118,9 @@
 		for (i = 0; i < 255; i += 16) {
 			fflush(stdout);
-			console_set_rgb_color(fphone(stdout), 0xffffff, i);
+			console_set_rgb_color(fphone(stdout), 255 - i, i);
 			putchar('X');
 		}
 		fflush(stdout);
-		console_set_color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);
+		console_set_style(fphone(stdout), STYLE_NORMAL);
 		putchar('\n');
 	}
Index: uspace/app/tetris/screen.c
===================================================================
--- uspace/app/tetris/screen.c	(revision caad59aaedb0d9190a12111b1fd41fed41df0d07)
+++ uspace/app/tetris/screen.c	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
@@ -53,7 +53,9 @@
 #include <vfs/vfs.h>
 #include <async.h>
+#include <bool.h>
+#include <io/console.h>
+#include <io/style.h>
 #include "screen.h"
 #include "tetris.h"
-#include <io/console.h>
 
 #define STOP  (B_COLS - 3)
@@ -63,5 +65,5 @@
 static int isset;               /* true => terminal is in game mode */
 
-static int use_color;		/* true => use colors */
+static bool use_color;          /* true => use colors */
 
 static const struct shape *lastshape;
@@ -81,5 +83,5 @@
 {
 	fflush(stdout);
-	console_set_rgb_color(fphone(stdout), 0xf0f0f0,
+	console_set_rgb_color(fphone(stdout), 0xffffff,
 	    use_color ? color : 0x000000);
 }
@@ -88,5 +90,5 @@
 {
 	fflush(stdout);
-	console_set_rgb_color(fphone(stdout), 0, 0xf0f0f0);
+	console_set_style(fphone(stdout), STYLE_NORMAL);
 }
 
@@ -118,8 +120,8 @@
 }
 
-void moveto(int r, int c)
+void moveto(ipcarg_t r, ipcarg_t c)
 {
 	fflush(stdout);
-	console_goto(fphone(stdout), c, r);
+	console_set_pos(fphone(stdout), c, r);
 }
 
@@ -131,13 +133,12 @@
 }
 
-static int get_display_color_sup(void)
-{
-	int rc;
-	int ccap;
-
-	rc = console_get_color_cap(fphone(stdout), &ccap);
+static bool get_display_color_sup(void)
+{
+	ipcarg_t ccap;
+	int rc = console_get_color_cap(fphone(stdout), &ccap);
+	
 	if (rc != 0)
-		return 0;
-
+		return false;
+	
 	return (ccap >= CONSOLE_CCAP_RGB);
 }
@@ -308,5 +309,5 @@
  * (We need its length in case we have to overwrite with blanks.)
  */
-void scr_msg(char *s, int set)
+void scr_msg(char *s, bool set)
 {
 	int l = str_size(s);
Index: uspace/app/tetris/screen.h
===================================================================
--- uspace/app/tetris/screen.h	(revision caad59aaedb0d9190a12111b1fd41fed41df0d07)
+++ uspace/app/tetris/screen.h	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
@@ -48,14 +48,16 @@
 
 #include <sys/types.h>
+#include <ipc/ipc.h>
 #include <async.h>
+#include <bool.h>
 
 typedef struct {
-	int ws_row;
-	int ws_col;
+	ipcarg_t ws_row;
+	ipcarg_t ws_col;
 } winsize_t;
 
 extern winsize_t winsize;
 
-extern void moveto(int r, int c);
+extern void moveto(ipcarg_t r, ipcarg_t c);
 extern void clear_screen(void);
 
@@ -65,5 +67,5 @@
 extern void scr_end(void);
 extern void scr_init(void);
-extern void scr_msg(char *, int);
+extern void scr_msg(char *, bool);
 extern void scr_set(void);
 extern void scr_update(void);
Index: uspace/app/top/screen.c
===================================================================
--- uspace/app/top/screen.c	(revision caad59aaedb0d9190a12111b1fd41fed41df0d07)
+++ uspace/app/top/screen.c	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
@@ -37,5 +37,7 @@
 
 #include <stdio.h>
+#include <ipc/ipc.h>
 #include <io/console.h>
+#include <io/style.h>
 #include <vfs/vfs.h>
 #include <stdarg.h>
@@ -45,10 +47,82 @@
 #include "top.h"
 
-#define WHITE  0xf0f0f0
-#define BLACK  0x000000
-
-static int rows;
-static int colls;
-static int up_rows;
+static ipcarg_t warn_col = 0;
+static ipcarg_t warn_row = 0;
+
+static void screen_style_normal(void)
+{
+	fflush(stdout);
+	console_set_style(fphone(stdout), STYLE_NORMAL);
+}
+
+static void screen_style_inverted(void)
+{
+	fflush(stdout);
+	console_set_style(fphone(stdout), STYLE_INVERTED);
+}
+
+static void screen_moveto(ipcarg_t col, ipcarg_t row)
+{
+	fflush(stdout);
+	console_set_pos(fphone(stdout), col, row);
+}
+
+static void screen_get_pos(ipcarg_t *col, ipcarg_t *row)
+{
+	fflush(stdout);
+	console_get_pos(fphone(stdout), col, row);
+}
+
+static void screen_get_size(ipcarg_t *col, ipcarg_t *row)
+{
+	fflush(stdout);
+	console_get_size(fphone(stdout), col, row);
+}
+
+static void screen_restart(bool clear)
+{
+	screen_style_normal();
+	
+	if (clear) {
+		fflush(stdout);
+		console_clear(fphone(stdout));
+	}
+	
+	screen_moveto(0, 0);
+}
+
+static void screen_newline(void)
+{
+	ipcarg_t cols;
+	ipcarg_t rows;
+	screen_get_size(&cols, &rows);
+	
+	ipcarg_t c;
+	ipcarg_t r;
+	screen_get_pos(&c, &r);
+	
+	ipcarg_t i;
+	for (i = c + 1; i < cols; i++)
+		puts(" ");
+	
+	if (r + 1 < rows)
+		puts("\n");
+}
+
+void screen_init(void)
+{
+	fflush(stdout);
+	console_cursor_visibility(fphone(stdout), false);
+	
+	screen_restart(true);
+}
+
+void screen_done(void)
+{
+	screen_restart(true);
+	
+	fflush(stdout);
+	console_cursor_visibility(fphone(stdout), true);
+}
 
 static void print_float(fixed_float ffloat, unsigned int precision)
@@ -64,60 +138,17 @@
 }
 
-static void screen_resume_normal(void)
-{
-	fflush(stdout);
-	console_set_rgb_color(fphone(stdout), 0, WHITE);
-}
-
-static void screen_moveto(int r, int c)
-{
-	fflush(stdout);
-	console_goto(fphone(stdout), c, r);
-}
-
-static void screen_clear(void)
-{
-	console_clear(fphone(stdout));
-	screen_moveto(0, 0);
-	up_rows = 0;
-	fflush(stdout);
-}
-
-void screen_init(void)
-{
-	console_cursor_visibility(fphone(stdout), 0);
-	screen_resume_normal();
-	screen_clear();
-	
-	console_get_size(fphone(stdout), &colls, &rows);
-}
-
-void screen_done(void)
-{
-	screen_resume_normal();
-	screen_clear();
-	console_cursor_visibility(fphone(stdout), 1);
-}
-
-static inline void print_time(data_t *data)
-{
-	printf("%02lu:%02lu:%02lu ", data->hours, data->minutes, data->seconds);
-}
-
-static inline void print_uptime(data_t *data)
-{
-	printf("up %u days, %02u:%02u:%02u, ", data->udays, data->uhours,
-	    data->uminutes, data->useconds);
-}
-
-static inline void print_load(data_t *data)
-{
-	printf("load avarage: ");
+static inline void print_global_head(data_t *data)
+{
+	printf("top - %02lu:%02lu:%02lu up %u days, %02u:%02u:%02u, load avarage:",
+	    data->hours, data->minutes, data->seconds,
+	    data->udays, data->uhours, data->uminutes, data->useconds);
 	
 	size_t i;
 	for (i = 0; i < data->load_count; i++) {
+		puts(" ");
 		stats_print_load_fragment(data->load[i], 2);
-		printf(" ");
-	}
+	}
+	
+	screen_newline();
 }
 
@@ -125,4 +156,5 @@
 {
 	printf("tasks: %u total", data->tasks_count);
+	screen_newline();
 }
 
@@ -137,5 +169,4 @@
 	size_t invalid = 0;
 	
-	
 	size_t i;
 	for (i = 0; i < data->threads_count; i++) {
@@ -167,4 +198,5 @@
 	    "%u other, %u invalid",
 	    total, running, ready, sleeping, lingering, other, invalid);
+	screen_newline();
 }
 
@@ -178,13 +210,13 @@
 			    data->cpus[i].id, data->cpus[i].frequency_mhz,
 			    data->cpus[i].busy_ticks, data->cpus[i].idle_ticks);
-			printf(", idle: ");
+			puts(", idle: ");
 			print_float(data->cpus_perc[i].idle, 2);
-			printf("%%, busy: ");
+			puts("%, busy: ");
 			print_float(data->cpus_perc[i].busy, 2);
-			printf("%%\n");
+			puts("%");
 		} else
-			printf("cpu%u inactive\n", data->cpus[i].id);
-		
-		up_rows++;
+			printf("cpu%u inactive", data->cpus[i].id);
+		
+		screen_newline();
 	}
 }
@@ -209,13 +241,27 @@
 	    PRIu64 "%c used, %" PRIu64 "%c free", total, total_suffix,
 	    unavail, unavail_suffix, used, used_suffix, free, free_suffix);
-}
-
-static inline void print_tasks(data_t *data, int row)
-{
-	size_t i;
-	for (i = 0; i < data->tasks_count; i++, row++) {
-		if (row > rows)
-			break;
-		
+	screen_newline();
+}
+
+static inline void print_task_head(void)
+{
+	screen_style_inverted();
+	printf("      ID  Threads      Mem      %%Mem %%uCycles %%kCycles  Name");
+	screen_newline();
+	screen_style_normal();
+}
+
+static inline void print_tasks(data_t *data)
+{
+	ipcarg_t cols;
+	ipcarg_t rows;
+	screen_get_size(&cols, &rows);
+	
+	ipcarg_t col;
+	ipcarg_t row;
+	screen_get_pos(&col, &row);
+	
+	size_t i;
+	for (i = 0; (i < data->tasks_count) && (row < rows); i++, row++) {
 		uint64_t virtmem;
 		char virtmem_suffix;
@@ -224,53 +270,38 @@
 		printf("%8" PRIu64 " %8u %8" PRIu64 "%c ", data->tasks[i].task_id,
 		    data->tasks[i].threads, virtmem, virtmem_suffix);
-		printf("   ");
+		puts("   ");
 		print_float(data->tasks_perc[i].virtmem, 2);
-		printf("%%   ");
+		puts("%   ");
 		print_float(data->tasks_perc[i].ucycles, 2);
-		printf("%%   ");
+		puts("%   ");
 		print_float(data->tasks_perc[i].kcycles, 2);
-		printf("%% %s\n", data->tasks[i].name);
-	}
-}
-
-static inline void print_task_head(void)
-{
-	fflush(stdout);
-	console_set_rgb_color(fphone(stdout), WHITE, BLACK);
-	
-	printf("      ID  Threads      Mem      %%Mem %%uCycles %%kCycles  Name");
-	
-	int i;
-	for (i = 61; i < colls; ++i)
-		printf(" ");
-	
-	fflush(stdout);
-	console_set_rgb_color(fphone(stdout), BLACK, WHITE);
+		printf("%% %s", data->tasks[i].name);
+		
+		screen_newline();
+	}
 }
 
 static inline void print_ipc_head(void)
 {
-	fflush(stdout);
-	console_set_rgb_color(fphone(stdout), WHITE, BLACK);
-	
+	screen_style_inverted();
 	printf("      ID Calls sent Calls recv Answs sent Answs recv  IRQn recv       Forw Name");
-	
-	int i;
-	for (i = 80; i < colls; ++i)
-		printf(" ");
-	
-	fflush(stdout);
-	console_set_rgb_color(fphone(stdout), BLACK, WHITE);
-}
-
-static inline void print_ipc(data_t *data, int row)
-{
-	size_t i;
-	for (i = 0; i < data->tasks_count; i++, row++) {
-		if (row > rows)
-			break;
-		
+	screen_newline();
+	screen_style_normal();
+}
+
+static inline void print_ipc(data_t *data)
+{
+	ipcarg_t cols;
+	ipcarg_t rows;
+	screen_get_size(&cols, &rows);
+	
+	ipcarg_t col;
+	ipcarg_t row;
+	screen_get_pos(&col, &row);
+	
+	size_t i;
+	for (i = 0; (i < data->tasks_count) && (row < rows); i++, row++) {
 		printf("%8" PRIu64 " %10" PRIu64 " %10" PRIu64 " %10" PRIu64
-		     " %10" PRIu64 " %10" PRIu64 " %10" PRIu64 " %s\n",
+		     " %10" PRIu64 " %10" PRIu64 " %10" PRIu64 " %s",
 		     data->tasks[i].task_id, data->tasks[i].ipc_info.call_sent,
 		     data->tasks[i].ipc_info.call_recieved,
@@ -279,4 +310,6 @@
 		     data->tasks[i].ipc_info.irq_notif_recieved,
 		     data->tasks[i].ipc_info.forwarded, data->tasks[i].name);
+		
+		screen_newline();
 	}
 }
@@ -284,42 +317,21 @@
 void print_data(data_t *data)
 {
-	screen_clear();
-	fflush(stdout);
-	
-	printf("top - ");
-	print_time(data);
-	print_uptime(data);
-	print_load(data);
-	
-	printf("\n");
-	up_rows++;
-	
+	screen_restart(false);
+	print_global_head(data);
 	print_task_summary(data);
-	
-	printf("\n");
-	up_rows++;
-	
 	print_thread_summary(data);
-	
-	printf("\n");
-	up_rows++;
-	
 	print_cpu_info(data);
 	print_physmem_info(data);
 	
-	printf("\n");
-	up_rows++;
-	
 	/* Empty row for warnings */
-	printf("\n");
+	screen_get_pos(&warn_col, &warn_row);
+	screen_newline();
 	
 	if (operation_type == OP_IPC) {
 		print_ipc_head();
-		printf("\n");
-		print_ipc(data, up_rows);
+		print_ipc(data);
 	} else {
 		print_task_head();
-		printf("\n");
-		print_tasks(data, up_rows);
+		print_tasks(data);
 	}
 	
@@ -329,5 +341,5 @@
 void print_warning(const char *fmt, ...)
 {
-	screen_moveto(up_rows, 0);
+	screen_moveto(warn_col, warn_row);
 	
 	va_list args;
@@ -336,4 +348,5 @@
 	va_end(args);
 	
+	screen_newline();
 	fflush(stdout);
 }
Index: uspace/lib/c/generic/io/console.c
===================================================================
--- uspace/lib/c/generic/io/console.c	(revision caad59aaedb0d9190a12111b1fd41fed41df0d07)
+++ uspace/lib/c/generic/io/console.c	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
@@ -45,28 +45,21 @@
 }
 
-int console_get_size(int phone, int *cols, int *rows)
+int console_get_size(int phone, ipcarg_t *cols, ipcarg_t *rows)
 {
-	ipcarg_t cols_v;
-	ipcarg_t rows_v;
-	int rc;
-
-	rc = async_req_0_2(phone, CONSOLE_GET_SIZE, &cols_v, &rows_v);
-
-	*cols = (int) cols_v;
-	*rows = (int) rows_v;
-	return rc;
+	return async_req_0_2(phone, CONSOLE_GET_SIZE, cols, rows);
 }
 
-void console_set_style(int phone, int style)
+void console_set_style(int phone, uint8_t style)
 {
 	async_msg_1(phone, CONSOLE_SET_STYLE, style);
 }
 
-void console_set_color(int phone, int fg_color, int bg_color, int flags)
+void console_set_color(int phone, uint8_t fg_color, uint8_t bg_color,
+    uint8_t flags)
 {
 	async_msg_3(phone, CONSOLE_SET_COLOR, fg_color, bg_color, flags);
 }
 
-void console_set_rgb_color(int phone, int fg_color, int bg_color)
+void console_set_rgb_color(int phone, uint32_t fg_color, uint32_t bg_color)
 {
 	async_msg_2(phone, CONSOLE_SET_RGB_COLOR, fg_color, bg_color);
@@ -75,16 +68,10 @@
 void console_cursor_visibility(int phone, bool show)
 {
-	async_msg_1(phone, CONSOLE_CURSOR_VISIBILITY, show != false);
+	async_msg_1(phone, CONSOLE_CURSOR_VISIBILITY, (show != false));
 }
 
-int console_get_color_cap(int phone, int *ccap)
+int console_get_color_cap(int phone, ipcarg_t *ccap)
 {
-	ipcarg_t ccap_tmp;
-	int rc;
-
-	rc = async_req_0_1(phone, CONSOLE_GET_COLOR_CAP, &ccap_tmp);
-	*ccap = ccap_tmp;
-
-	return rc;
+	return async_req_0_1(phone, CONSOLE_GET_COLOR_CAP, ccap);
 }
 
@@ -94,18 +81,10 @@
 }
 
-int console_get_pos(int phone, int *col, int *row)
+int console_get_pos(int phone, ipcarg_t *col, ipcarg_t *row)
 {
-	ipcarg_t col_v;
-	ipcarg_t row_v;
-	int rc;
-
-	rc = async_req_0_2(phone, CONSOLE_GET_POS, &col_v, &row_v);
-
-	*col = (int) col_v;
-	*row = (int) row_v;
-	return rc;
+	return async_req_0_2(phone, CONSOLE_GET_POS, col, row);
 }
 
-void console_goto(int phone, int col, int row)
+void console_set_pos(int phone, ipcarg_t col, ipcarg_t row)
 {
 	async_msg_2(phone, CONSOLE_GOTO, col, row);
Index: uspace/lib/c/include/io/console.h
===================================================================
--- uspace/lib/c/include/io/console.h	(revision caad59aaedb0d9190a12111b1fd41fed41df0d07)
+++ uspace/lib/c/include/io/console.h	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
@@ -68,14 +68,15 @@
 extern void console_clear(int phone);
 
-extern int console_get_size(int phone, int *cols, int *rows);
-extern int console_get_pos(int phone, int *col, int *row);
-extern void console_goto(int phone, int col, int row);
+extern int console_get_size(int phone, ipcarg_t *cols, ipcarg_t *rows);
+extern int console_get_pos(int phone, ipcarg_t *col, ipcarg_t *row);
+extern void console_set_pos(int phone, ipcarg_t col, ipcarg_t row);
 
-extern void console_set_style(int phone, int style);
-extern void console_set_color(int phone, int fg_color, int bg_color, int flags);
-extern void console_set_rgb_color(int phone, int fg_color, int bg_color);
+extern void console_set_style(int phone, uint8_t style);
+extern void console_set_color(int phone, uint8_t fg_color, uint8_t bg_color,
+    uint8_t flags);
+extern void console_set_rgb_color(int phone, uint32_t fg_color, uint32_t bg_color);
 
 extern void console_cursor_visibility(int phone, bool show);
-extern int console_get_color_cap(int phone, int *ccap);
+extern int console_get_color_cap(int phone, ipcarg_t *ccap);
 extern void console_kcon_enable(int phone);
 
Index: uspace/lib/c/include/io/style.h
===================================================================
--- uspace/lib/c/include/io/style.h	(revision caad59aaedb0d9190a12111b1fd41fed41df0d07)
+++ uspace/lib/c/include/io/style.h	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
@@ -38,5 +38,7 @@
 enum console_style {
 	STYLE_NORMAL   = 0,
-	STYLE_EMPHASIS = 1
+	STYLE_EMPHASIS = 1,
+	STYLE_INVERTED = 2,
+	STYLE_SELECTED = 3
 };
 
Index: uspace/lib/clui/Makefile
===================================================================
--- uspace/lib/clui/Makefile	(revision caad59aaedb0d9190a12111b1fd41fed41df0d07)
+++ uspace/lib/clui/Makefile	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
@@ -28,4 +28,5 @@
 
 USPACE_PREFIX = ../..
+EXTRA_CFLAGS = -I.
 LIBRARY = libclui
 
Index: uspace/lib/clui/tinput.c
===================================================================
--- uspace/lib/clui/tinput.c	(revision caad59aaedb0d9190a12111b1fd41fed41df0d07)
+++ uspace/lib/clui/tinput.c	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
@@ -40,6 +40,5 @@
 #include <assert.h>
 #include <bool.h>
-
-#include "tinput.h"
+#include <tinput.h>
 
 /** Seek direction */
@@ -49,16 +48,16 @@
 } seek_dir_t;
 
-static void tinput_init(tinput_t *ti);
-static void tinput_insert_string(tinput_t *ti, const char *str);
-static void tinput_sel_get_bounds(tinput_t *ti, int *sa, int *sb);
-static bool tinput_sel_active(tinput_t *ti);
-static void tinput_sel_all(tinput_t *ti);
-static void tinput_sel_delete(tinput_t *ti);
-static void tinput_key_ctrl(tinput_t *ti, console_event_t *ev);
-static void tinput_key_shift(tinput_t *ti, console_event_t *ev);
-static void tinput_key_ctrl_shift(tinput_t *ti, console_event_t *ev);
-static void tinput_key_unmod(tinput_t *ti, console_event_t *ev);
-static void tinput_pre_seek(tinput_t *ti, bool shift_held);
-static void tinput_post_seek(tinput_t *ti, bool shift_held);
+static void tinput_init(tinput_t *);
+static void tinput_insert_string(tinput_t *, const char *);
+static void tinput_sel_get_bounds(tinput_t *, size_t *, size_t *);
+static bool tinput_sel_active(tinput_t *);
+static void tinput_sel_all(tinput_t *);
+static void tinput_sel_delete(tinput_t *);
+static void tinput_key_ctrl(tinput_t *, console_event_t *);
+static void tinput_key_shift(tinput_t *, console_event_t *);
+static void tinput_key_ctrl_shift(tinput_t *, console_event_t *);
+static void tinput_key_unmod(tinput_t *, console_event_t *);
+static void tinput_pre_seek(tinput_t *, bool);
+static void tinput_post_seek(tinput_t *, bool);
 
 /** Create a new text input field. */
@@ -66,9 +65,9 @@
 {
 	tinput_t *ti;
-
+	
 	ti = malloc(sizeof(tinput_t));
 	if (ti == NULL)
 		return NULL;
-
+	
 	tinput_init(ti);
 	return ti;
@@ -81,17 +80,17 @@
 }
 
-static void tinput_display_tail(tinput_t *ti, int start, int pad)
-{
-	static wchar_t dbuf[INPUT_MAX_SIZE + 1];
-	int sa, sb;
-	int i, p;
-
+static void tinput_display_tail(tinput_t *ti, size_t start, size_t pad)
+{
+	wchar_t dbuf[INPUT_MAX_SIZE + 1];
+	
+	size_t sa;
+	size_t sb;
 	tinput_sel_get_bounds(ti, &sa, &sb);
-
-	console_goto(fphone(stdout), (ti->col0 + start) % ti->con_cols,
+	
+	console_set_pos(fphone(stdout), (ti->col0 + start) % ti->con_cols,
 	    ti->row0 + (ti->col0 + start) / ti->con_cols);
-	console_set_color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);
-
-	p = start;
+	console_set_style(fphone(stdout), STYLE_NORMAL);
+	
+	size_t p = start;
 	if (p < sa) {
 		memcpy(dbuf, ti->buffer + p, (sa - p) * sizeof(wchar_t));
@@ -100,8 +99,8 @@
 		p = sa;
 	}
-
+	
 	if (p < sb) {
 		fflush(stdout);
-		console_set_color(fphone(stdout), COLOR_BLACK, COLOR_RED, 0);
+		console_set_style(fphone(stdout), STYLE_SELECTED);
 		memcpy(dbuf, ti->buffer + p,
 		    (sb - p) * sizeof(wchar_t));
@@ -110,8 +109,8 @@
 		p = sb;
 	}
-
+	
 	fflush(stdout);
-	console_set_color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);
-
+	console_set_style(fphone(stdout), STYLE_NORMAL);
+	
 	if (p < ti->nc) {
 		memcpy(dbuf, ti->buffer + p,
@@ -120,7 +119,8 @@
 		printf("%ls", dbuf);
 	}
-
-	for (i = 0; i < pad; ++i)
+	
+	for (p = 0; p < pad; p++)
 		putchar(' ');
+	
 	fflush(stdout);
 }
@@ -133,5 +133,5 @@
 static void tinput_position_caret(tinput_t *ti)
 {
-	console_goto(fphone(stdout), (ti->col0 + ti->pos) % ti->con_cols,
+	console_set_pos(fphone(stdout), (ti->col0 + ti->pos) % ti->con_cols,
 	    ti->row0 + (ti->col0 + ti->pos) / ti->con_cols);
 }
@@ -140,33 +140,31 @@
 static void tinput_update_origin(tinput_t *ti)
 {
-	int width, rows;
-
-	width = ti->col0 + ti->nc;
-	rows = (width / ti->con_cols) + 1;
-
+	ipcarg_t width = ti->col0 + ti->nc;
+	ipcarg_t rows = (width / ti->con_cols) + 1;
+	
 	/* Update row0 if the screen scrolled. */
 	if (ti->row0 + rows > ti->con_rows)
-		ti->row0 = ti->con_rows - rows;	
+		ti->row0 = ti->con_rows - rows;
 }
 
 static void tinput_insert_char(tinput_t *ti, wchar_t c)
 {
-	int i;
-	int new_width, new_height;
-
 	if (ti->nc == INPUT_MAX_SIZE)
 		return;
-
-	new_width = ti->col0 + ti->nc + 1;
+	
+	ipcarg_t new_width = ti->col0 + ti->nc + 1;
 	if (new_width % ti->con_cols == 0) {
 		/* Advancing to new line. */
-		new_height = (new_width / ti->con_cols) + 1;
-		if (new_height >= ti->con_rows)
-			return; /* Disallow text longer than 1 page for now. */
-	}
-
-	for (i = ti->nc; i > ti->pos; --i)
+		ipcarg_t new_height = (new_width / ti->con_cols) + 1;
+		if (new_height >= ti->con_rows) {
+			/* Disallow text longer than 1 page for now. */
+			return;
+		}
+	}
+	
+	size_t i;
+	for (i = ti->nc; i > ti->pos; i--)
 		ti->buffer[i] = ti->buffer[i - 1];
-
+	
 	ti->buffer[ti->pos] = c;
 	ti->pos += 1;
@@ -174,5 +172,5 @@
 	ti->buffer[ti->nc] = '\0';
 	ti->sel_start = ti->pos;
-
+	
 	tinput_display_tail(ti, ti->pos - 1, 0);
 	tinput_update_origin(ti);
@@ -182,41 +180,41 @@
 static void tinput_insert_string(tinput_t *ti, const char *str)
 {
-	int i;
-	int new_width, new_height;
-	int ilen;
-	wchar_t c;
-	size_t off;
-
-	ilen = min((ssize_t) str_length(str), INPUT_MAX_SIZE - ti->nc);
+	size_t ilen = min(str_length(str), INPUT_MAX_SIZE - ti->nc);
 	if (ilen == 0)
 		return;
-
-	new_width = ti->col0 + ti->nc + ilen;
-	new_height = (new_width / ti->con_cols) + 1;
-	if (new_height >= ti->con_rows)
-		return; /* Disallow text longer than 1 page for now. */
-
-	for (i = ti->nc - 1; i >= ti->pos; --i)
-		ti->buffer[i + ilen] = ti->buffer[i];
-
-	off = 0; i = 0;
+	
+	ipcarg_t new_width = ti->col0 + ti->nc + ilen;
+	ipcarg_t new_height = (new_width / ti->con_cols) + 1;
+	if (new_height >= ti->con_rows) {
+		/* Disallow text longer than 1 page for now. */
+		return;
+	}
+	
+	if (ti->nc > 0) {
+		size_t i;
+		for (i = ti->nc; i > ti->pos; i--)
+			ti->buffer[i + ilen - 1] = ti->buffer[i - 1];
+	}
+	
+	size_t off = 0;
+	size_t i = 0;
 	while (i < ilen) {
-		c = str_decode(str, &off, STR_NO_LIMIT);
+		wchar_t c = str_decode(str, &off, STR_NO_LIMIT);
 		if (c == '\0')
 			break;
-
+		
 		/* Filter out non-printable chars. */
 		if (c < 32)
 			c = 32;
-
+		
 		ti->buffer[ti->pos + i] = c;
-		++i;
-	}
-
+		i++;
+	}
+	
 	ti->pos += ilen;
 	ti->nc += ilen;
 	ti->buffer[ti->nc] = '\0';
 	ti->sel_start = ti->pos;
-
+	
 	tinput_display_tail(ti, ti->pos - ilen, 0);
 	tinput_update_origin(ti);
@@ -226,21 +224,21 @@
 static void tinput_backspace(tinput_t *ti)
 {
-	int i;
-
 	if (tinput_sel_active(ti)) {
 		tinput_sel_delete(ti);
 		return;
 	}
-
+	
 	if (ti->pos == 0)
 		return;
-
-	for (i = ti->pos; i < ti->nc; ++i)
+	
+	size_t i;
+	for (i = ti->pos; i < ti->nc; i++)
 		ti->buffer[i - 1] = ti->buffer[i];
+	
 	ti->pos -= 1;
 	ti->nc -= 1;
 	ti->buffer[ti->nc] = '\0';
 	ti->sel_start = ti->pos;
-
+	
 	tinput_display_tail(ti, ti->pos, 1);
 	tinput_position_caret(ti);
@@ -253,11 +251,11 @@
 		return;
 	}
-
+	
 	if (ti->pos == ti->nc)
 		return;
-
+	
 	ti->pos += 1;
 	ti->sel_start = ti->pos;
-
+	
 	tinput_backspace(ti);
 }
@@ -266,5 +264,5 @@
 {
 	tinput_pre_seek(ti, shift_held);
-
+	
 	if (dir == seek_forward) {
 		if (ti->pos < ti->nc)
@@ -274,5 +272,5 @@
 			ti->pos -= 1;
 	}
-
+	
 	tinput_post_seek(ti, shift_held);
 }
@@ -281,17 +279,17 @@
 {
 	tinput_pre_seek(ti, shift_held);
-
+	
 	if (dir == seek_forward) {
 		if (ti->pos == ti->nc)
 			return;
-
-		while (1) {
+		
+		while (true) {
 			ti->pos += 1;
-
+			
 			if (ti->pos == ti->nc)
 				break;
-
-			if (ti->buffer[ti->pos - 1] == ' ' &&
-			    ti->buffer[ti->pos] != ' ')
+			
+			if ((ti->buffer[ti->pos - 1] == ' ') &&
+			    (ti->buffer[ti->pos] != ' '))
 				break;
 		}
@@ -299,18 +297,18 @@
 		if (ti->pos == 0)
 			return;
-
-		while (1) {
+		
+		while (true) {
 			ti->pos -= 1;
-
+			
 			if (ti->pos == 0)
 				break;
-
+			
 			if (ti->buffer[ti->pos - 1] == ' ' &&
 			    ti->buffer[ti->pos] != ' ')
 				break;
 		}
-
-	}
-
+	
+	}
+	
 	tinput_post_seek(ti, shift_held);
 }
@@ -319,13 +317,13 @@
 {
 	tinput_pre_seek(ti, shift_held);
-
+	
 	if (dir == seek_forward) {
 		if (ti->pos + ti->con_cols <= ti->nc)
 			ti->pos = ti->pos + ti->con_cols;
 	} else {
-		if (ti->pos - ti->con_cols >= 0)
+		if (ti->pos >= ti->con_cols)
 			ti->pos = ti->pos - ti->con_cols;
 	}
-
+	
 	tinput_post_seek(ti, shift_held);
 }
@@ -334,10 +332,10 @@
 {
 	tinput_pre_seek(ti, shift_held);
-
+	
 	if (dir == seek_backward)
 		ti->pos = 0;
 	else
 		ti->pos = ti->nc;
-
+	
 	tinput_post_seek(ti, shift_held);
 }
@@ -345,5 +343,5 @@
 static void tinput_pre_seek(tinput_t *ti, bool shift_held)
 {
-	if (tinput_sel_active(ti) && !shift_held) {
+	if ((tinput_sel_active(ti)) && (!shift_held)) {
 		/* Unselect and redraw. */
 		ti->sel_start = ti->pos;
@@ -362,4 +360,5 @@
 		ti->sel_start = ti->pos;
 	}
+	
 	tinput_position_caret(ti);
 }
@@ -367,6 +366,4 @@
 static void tinput_history_insert(tinput_t *ti, char *str)
 {
-	int i;
-
 	if (ti->hnum < HISTORY_LEN) {
 		ti->hnum += 1;
@@ -375,10 +372,11 @@
 			free(ti->history[HISTORY_LEN]);
 	}
-
-	for (i = ti->hnum; i > 1; --i)
+	
+	size_t i;
+	for (i = ti->hnum; i > 1; i--)
 		ti->history[i] = ti->history[i - 1];
-
+	
 	ti->history[1] = str_dup(str);
-
+	
 	if (ti->history[0] != NULL) {
 		free(ti->history[0]);
@@ -395,5 +393,5 @@
 }
 
-static void tinput_sel_get_bounds(tinput_t *ti, int *sa, int *sb)
+static void tinput_sel_get_bounds(tinput_t *ti, size_t *sa, size_t *sb)
 {
 	if (ti->sel_start < ti->pos) {
@@ -408,5 +406,5 @@
 static bool tinput_sel_active(tinput_t *ti)
 {
-	return ti->sel_start != ti->pos;
+	return (ti->sel_start != ti->pos);
 }
 
@@ -421,16 +419,18 @@
 static void tinput_sel_delete(tinput_t *ti)
 {
-	int sa, sb;
-
+	size_t sa;
+	size_t sb;
+	
 	tinput_sel_get_bounds(ti, &sa, &sb);
 	if (sa == sb)
 		return;
-
+	
 	memmove(ti->buffer + sa, ti->buffer + sb,
 	    (ti->nc - sb) * sizeof(wchar_t));
+	
 	ti->pos = ti->sel_start = sa;
 	ti->nc -= (sb - sa);
 	ti->buffer[ti->nc] = '\0';
-
+	
 	tinput_display_tail(ti, sa, sb - sa);
 	tinput_position_caret(ti);
@@ -439,9 +439,11 @@
 static void tinput_sel_copy_to_cb(tinput_t *ti)
 {
-	int sa, sb;
+	size_t sa;
+	size_t sb;
+	
+	tinput_sel_get_bounds(ti, &sa, &sb);
+	
 	char *str;
-
-	tinput_sel_get_bounds(ti, &sa, &sb);
-
+	
 	if (sb < ti->nc) {
 		wchar_t tmp_c = ti->buffer[sb];
@@ -454,13 +456,14 @@
 	if (str == NULL)
 		goto error;
-
+	
 	if (clipboard_put_str(str) != EOK)
 		goto error;
-
+	
 	free(str);
 	return;
+	
 error:
+	/* TODO: Give the user some kind of warning. */
 	return;
-	/* TODO: Give the user some warning. */
 }
 
@@ -468,10 +471,11 @@
 {
 	char *str;
-	int rc;
-
-	rc = clipboard_get_str(&str);
-	if (rc != EOK || str == NULL)
-		return; /* TODO: Give the user some warning. */
-
+	int rc = clipboard_get_str(&str);
+	
+	if ((rc != EOK) || (str == NULL)) {
+		/* TODO: Give the user some kind of warning. */
+		return;
+	}
+	
 	tinput_insert_string(ti, str);
 	free(str);
@@ -480,20 +484,24 @@
 static void tinput_history_seek(tinput_t *ti, int offs)
 {
-	int pad;
-
-	if (ti->hpos + offs < 0 || ti->hpos + offs > ti->hnum)
-		return;
-
+	if (offs >= 0) {
+		if (ti->hpos + offs > ti->hnum)
+			return;
+	} else {
+		if (ti->hpos < (size_t) -offs)
+			return;
+	}
+	
 	if (ti->history[ti->hpos] != NULL) {
 		free(ti->history[ti->hpos]);
 		ti->history[ti->hpos] = NULL;
 	}
-
+	
 	ti->history[ti->hpos] = tinput_get_str(ti);
 	ti->hpos += offs;
-
-	pad = ti->nc - str_length(ti->history[ti->hpos]);
-	if (pad < 0) pad = 0;
-
+	
+	int pad = (int) ti->nc - str_length(ti->history[ti->hpos]);
+	if (pad < 0)
+		pad = 0;
+	
 	tinput_set_str(ti, ti->history[ti->hpos]);
 	tinput_display_tail(ti, 0, pad);
@@ -515,55 +523,54 @@
 /** Read in one line of input.
  *
- * @param ti	Text input.
- * @param dstr	Place to save pointer to new string.
- * @return	EOK on success, ENOENT if user requested abort, EIO
- *		if communication with console failed.
+ * @param ti   Text input.
+ * @param dstr Place to save pointer to new string.
+ *
+ * @return EOK on success
+ * @return ENOENT if user requested abort
+ * @return EIO if communication with console failed
+ *
  */
 int tinput_read(tinput_t *ti, char **dstr)
 {
-	console_event_t ev;
-	char *str;
-
 	fflush(stdout);
-
 	if (console_get_size(fphone(stdin), &ti->con_cols, &ti->con_rows) != EOK)
 		return EIO;
+	
 	if (console_get_pos(fphone(stdin), &ti->col0, &ti->row0) != EOK)
 		return EIO;
-
-	ti->pos = ti->sel_start = 0;
+	
+	ti->pos = 0;
+	ti->sel_start = 0;
 	ti->nc = 0;
 	ti->buffer[0] = '\0';
 	ti->done = false;
 	ti->exit_clui = false;
-
+	
 	while (!ti->done) {
 		fflush(stdout);
+		
+		console_event_t ev;
 		if (!console_get_event(fphone(stdin), &ev))
 			return EIO;
-
+		
 		if (ev.type != KEY_PRESS)
 			continue;
-
-		if ((ev.mods & KM_CTRL) != 0 &&
-		    (ev.mods & (KM_ALT | KM_SHIFT)) == 0) {
+		
+		if (((ev.mods & KM_CTRL) != 0) &&
+		    ((ev.mods & (KM_ALT | KM_SHIFT)) == 0))
 			tinput_key_ctrl(ti, &ev);
-		}
-
-		if ((ev.mods & KM_SHIFT) != 0 &&
-		    (ev.mods & (KM_CTRL | KM_ALT)) == 0) {
+		
+		if (((ev.mods & KM_SHIFT) != 0) &&
+		    ((ev.mods & (KM_CTRL | KM_ALT)) == 0))
 			tinput_key_shift(ti, &ev);
-		}
-
-		if ((ev.mods & KM_CTRL) != 0 &&
-		    (ev.mods & KM_SHIFT) != 0 &&
-		    (ev.mods & KM_ALT) == 0) {
+		
+		if (((ev.mods & KM_CTRL) != 0) &&
+		    ((ev.mods & KM_SHIFT) != 0) &&
+		    ((ev.mods & KM_ALT) == 0))
 			tinput_key_ctrl_shift(ti, &ev);
-		}
-
-		if ((ev.mods & (KM_CTRL | KM_ALT | KM_SHIFT)) == 0) {
+		
+		if ((ev.mods & (KM_CTRL | KM_ALT | KM_SHIFT)) == 0)
 			tinput_key_unmod(ti, &ev);
-		}
-
+		
 		if (ev.c >= ' ') {
 			tinput_sel_delete(ti);
@@ -571,18 +578,18 @@
 		}
 	}
-
+	
 	if (ti->exit_clui)
 		return ENOENT;
-
+	
 	ti->pos = ti->nc;
 	tinput_position_caret(ti);
 	putchar('\n');
-
-	str = tinput_get_str(ti);
+	
+	char *str = tinput_get_str(ti);
 	if (str_cmp(str, "") != 0)
 		tinput_history_insert(ti, str);
-
+	
 	ti->hpos = 0;
-
+	
 	*dstr = str;
 	return EOK;
@@ -700,5 +707,5 @@
 		break;
 	case KC_UP:
-		tinput_history_seek(ti, +1);
+		tinput_history_seek(ti, 1);
 		break;
 	case KC_DOWN:
Index: uspace/lib/clui/tinput.h
===================================================================
--- uspace/lib/clui/tinput.h	(revision caad59aaedb0d9190a12111b1fd41fed41df0d07)
+++ uspace/lib/clui/tinput.h	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
@@ -29,5 +29,5 @@
 /** @addtogroup libclui
  * @{
- */ 
+ */
 /**
  * @file
@@ -37,6 +37,8 @@
 #define LIBCLUI_TINPUT_H_
 
-#define HISTORY_LEN 10
-#define INPUT_MAX_SIZE 1024
+#include <ipc/ipc.h>
+
+#define HISTORY_LEN     10
+#define INPUT_MAX_SIZE  1024
 
 /** Text input field (command line).
@@ -47,23 +49,34 @@
 	/** Buffer holding text currently being edited */
 	wchar_t buffer[INPUT_MAX_SIZE + 1];
+	
 	/** Screen coordinates of the top-left corner of the text field */
-	int col0, row0;
+	ipcarg_t col0;
+	ipcarg_t row0;
+	
 	/** Screen dimensions */
-	int con_cols, con_rows;
+	ipcarg_t con_cols;
+	ipcarg_t con_rows;
+	
 	/** Number of characters in @c buffer */
-	int nc;
+	size_t nc;
+	
 	/** Caret position within buffer */
-	int pos;
+	size_t pos;
+	
 	/** Selection mark position within buffer */
-	int sel_start;
-
+	size_t sel_start;
+	
 	/** History (dynamically allocated strings) */
-	char *history[1 + HISTORY_LEN];
+	char *history[HISTORY_LEN + 1];
+	
 	/** Number of entries in @c history, not counting [0] */
-	int hnum;
+	size_t hnum;
+	
 	/** Current position in history */
-	int hpos;
+	size_t hpos;
+	
 	/** @c true if finished with this line (return to caller) */
 	bool done;
+	
 	/** @c true if user requested to abort interactive loop */
 	bool exit_clui;
@@ -71,6 +84,6 @@
 
 extern tinput_t *tinput_new(void);
-extern void tinput_destroy(tinput_t *ti);
-extern int tinput_read(tinput_t *ti, char **str);
+extern void tinput_destroy(tinput_t *);
+extern int tinput_read(tinput_t *, char **);
 
 #endif
@@ -78,3 +91,2 @@
 /** @}
  */
-
Index: uspace/srv/hid/console/console.c
===================================================================
--- uspace/srv/hid/console/console.c	(revision caad59aaedb0d9190a12111b1fd41fed41df0d07)
+++ uspace/srv/hid/console/console.c	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
@@ -71,8 +71,8 @@
 /** Information about framebuffer */
 struct {
-	int phone;      /**< Framebuffer phone */
-	ipcarg_t cols;  /**< Framebuffer columns */
-	ipcarg_t rows;  /**< Framebuffer rows */
-	int color_cap;  /**< Color capabilities (FB_CCAP_xxx) */
+	int phone;           /**< Framebuffer phone */
+	ipcarg_t cols;       /**< Framebuffer columns */
+	ipcarg_t rows;       /**< Framebuffer rows */
+	ipcarg_t color_cap;  /**< Color capabilities (FB_CCAP_xxx) */
 } fb_info;
 
@@ -99,7 +99,7 @@
 /** Information on row-span yet unsent to FB driver. */
 struct {
-	size_t col;  /**< Leftmost column of the span. */
-	size_t row;  /**< Row where the span lies. */
-	size_t cnt;  /**< Width of the span. */
+	ipcarg_t col;  /**< Leftmost column of the span. */
+	ipcarg_t row;  /**< Row where the span lies. */
+	ipcarg_t cnt;  /**< Width of the span. */
 } fb_pending;
 
@@ -117,5 +117,5 @@
 }
 
-static void curs_goto(size_t x, size_t y)
+static void curs_goto(ipcarg_t x, ipcarg_t y)
 {
 	async_msg_2(fb_info.phone, FB_CURSOR_GOTO, x, y);
@@ -147,15 +147,15 @@
 }
 
-static void set_style(int style)
+static void set_style(uint8_t style)
 {
 	async_msg_1(fb_info.phone, FB_SET_STYLE, style);
 }
 
-static void set_color(int fgcolor, int bgcolor, int flags)
+static void set_color(uint8_t fgcolor, uint8_t bgcolor, uint8_t flags)
 {
 	async_msg_3(fb_info.phone, FB_SET_COLOR, fgcolor, bgcolor, flags);
 }
 
-static void set_rgb_color(int fgcolor, int bgcolor)
+static void set_rgb_color(uint32_t fgcolor, uint32_t bgcolor)
 {
 	async_msg_2(fb_info.phone, FB_SET_RGB_COLOR, fgcolor, bgcolor); 
@@ -178,14 +178,23 @@
 }
 
-static int ccap_fb_to_con(int ccap_fb, int *ccap_con)
+static int ccap_fb_to_con(ipcarg_t ccap_fb, ipcarg_t *ccap_con)
 {
 	switch (ccap_fb) {
-	case FB_CCAP_NONE: *ccap_con = CONSOLE_CCAP_NONE; break;
-	case FB_CCAP_STYLE: *ccap_con = CONSOLE_CCAP_STYLE; break;
-	case FB_CCAP_INDEXED: *ccap_con = CONSOLE_CCAP_INDEXED; break;
-	case FB_CCAP_RGB: *ccap_con = CONSOLE_CCAP_RGB; break;
-	default: return EINVAL;
-	}
-
+	case FB_CCAP_NONE:
+		*ccap_con = CONSOLE_CCAP_NONE;
+		break;
+	case FB_CCAP_STYLE:
+		*ccap_con = CONSOLE_CCAP_STYLE;
+		break;
+	case FB_CCAP_INDEXED:
+		*ccap_con = CONSOLE_CCAP_INDEXED;
+		break;
+	case FB_CCAP_RGB:
+		*ccap_con = CONSOLE_CCAP_RGB;
+		break;
+	default:
+		return EINVAL;
+	}
+	
 	return EOK;
 }
@@ -226,5 +235,5 @@
  *
  */
-static void cell_mark_changed(size_t col, size_t row)
+static void cell_mark_changed(ipcarg_t col, ipcarg_t row)
 {
 	if (fb_pending.cnt != 0) {
@@ -253,5 +262,5 @@
 {
 	bool flush_cursor = false;
-
+	
 	switch (ch) {
 	case '\n':
@@ -297,5 +306,5 @@
 			async_msg_1(fb_info.phone, FB_SCROLL, 1);
 	}
-
+	
 	if (cons == active_console && flush_cursor)
 		curs_goto(cons->scr.position_x, cons->scr.position_y);
@@ -327,8 +336,4 @@
 	
 	if (cons != kernel_console) {
-		size_t x;
-		size_t y;
-		int rc = 0;
-		
 		async_serialize_start();
 		
@@ -344,4 +349,9 @@
 		set_attrs(&cons->scr.attrs);
 		curs_visibility(false);
+		
+		ipcarg_t x;
+		ipcarg_t y;
+		int rc = 0;
+		
 		if (interbuffer) {
 			for (y = 0; y < cons->scr.size_y; y++) {
@@ -390,5 +400,4 @@
 	/* Ignore parameters, the connection is already opened */
 	while (true) {
-		
 		ipc_call_t call;
 		ipc_callid_t callid = async_get_call(&call);
@@ -433,16 +442,11 @@
 static void mouse_events(ipc_callid_t iid, ipc_call_t *icall)
 {
-	int button, press;
-	int dx, dy;
-	int newcon;
-
 	/* Ignore parameters, the connection is already opened */
 	while (true) {
-
 		ipc_call_t call;
 		ipc_callid_t callid = async_get_call(&call);
-
+		
 		int retval;
-
+		
 		switch (IPC_GET_METHOD(call)) {
 		case IPC_M_PHONE_HUNGUP:
@@ -450,8 +454,6 @@
 			return;
 		case MEVENT_BUTTON:
-			button = IPC_GET_ARG1(call);
-			press = IPC_GET_ARG2(call);
-			if (button == 1) {
-				newcon = gcons_mouse_btn(press);
+			if (IPC_GET_ARG1(call) == 1) {
+				int newcon = gcons_mouse_btn((bool) IPC_GET_ARG2(call));
 				if (newcon != -1)
 					change_console(&consoles[newcon]);
@@ -460,7 +462,6 @@
 			break;
 		case MEVENT_MOVE:
-			dx = IPC_GET_ARG1(call);
-			dy = IPC_GET_ARG2(call);
-			gcons_mouse_move(dx, dy);
+			gcons_mouse_move((int) IPC_GET_ARG1(call),
+			    (int) IPC_GET_ARG2(call));
 			retval = 0;
 			break;
@@ -520,4 +521,5 @@
 	console_event_t ev;
 	fibril_mutex_lock(&input_mutex);
+	
 recheck:
 	while ((keybuffer_pop(&cons->keybuffer, &ev)) && (pos < size)) {
@@ -536,4 +538,5 @@
 		goto recheck;
 	}
+	
 	fibril_mutex_unlock(&input_mutex);
 }
@@ -542,6 +545,7 @@
 {
 	console_event_t ev;
-
+	
 	fibril_mutex_lock(&input_mutex);
+	
 recheck:
 	if (keybuffer_pop(&cons->keybuffer, &ev)) {
@@ -551,4 +555,5 @@
 		goto recheck;
 	}
+	
 	fibril_mutex_unlock(&input_mutex);
 }
@@ -580,6 +585,5 @@
 	ipcarg_t arg2;
 	ipcarg_t arg3;
-
-	int cons_ccap;
+	
 	int rc;
 	
@@ -622,5 +626,4 @@
 			if (cons == active_console) {
 				async_req_0_0(fb_info.phone, FB_FLUSH);
-				
 				curs_goto(cons->scr.position_x, cons->scr.position_y);
 			}
@@ -650,10 +653,9 @@
 			break;
 		case CONSOLE_GET_COLOR_CAP:
-			rc = ccap_fb_to_con(fb_info.color_cap, &cons_ccap);
+			rc = ccap_fb_to_con(fb_info.color_cap, &arg1);
 			if (rc != EOK) {
 				ipc_answer_0(callid, rc);
 				continue;
 			}
-			arg1 = cons_ccap;
 			break;
 		case CONSOLE_SET_STYLE:
@@ -714,5 +716,5 @@
 		return false;
 	}
-
+	
 	kbd_phone = fd_phone(input_fd);
 	if (kbd_phone < 0) {
@@ -720,5 +722,5 @@
 		return false;
 	}
-
+	
 	/* NB: The callback connection is slotted for removal */
 	ipcarg_t phonehash;
@@ -727,16 +729,16 @@
 		return false;
 	}
-
+	
 	async_new_connection(phonehash, 0, NULL, keyboard_events);
-
+	
 	/* Connect to mouse device */
 	mouse_phone = -1;
 	int mouse_fd = open("/dev/hid_in/mouse", O_RDONLY);
-
+	
 	if (mouse_fd < 0) {
 		printf(NAME ": Notice - failed opening %s\n", "/dev/hid_in/mouse");
 		goto skip_mouse;
 	}
-
+	
 	mouse_phone = fd_phone(mouse_fd);
 	if (mouse_phone < 0) {
@@ -744,5 +746,5 @@
 		goto skip_mouse;
 	}
-
+	
 	if (ipc_connect_to_me(mouse_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) {
 		printf(NAME ": Failed to create callback from mouse device\n");
@@ -750,8 +752,8 @@
 		goto skip_mouse;
 	}
-
+	
 	async_new_connection(phonehash, 0, NULL, mouse_events);
 skip_mouse:
-
+	
 	/* Connect to framebuffer driver */
 	fb_info.phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VIDEO, 0, 0);
@@ -760,5 +762,5 @@
 		return -1;
 	}
-
+	
 	/* Register driver */
 	int rc = devmap_driver_register(NAME, client_connection);
@@ -772,9 +774,7 @@
 	
 	/* Synchronize, the gcons could put something in queue */
-	ipcarg_t color_cap;
 	async_req_0_0(fb_info.phone, FB_FLUSH);
 	async_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.cols, &fb_info.rows);
-	async_req_0_1(fb_info.phone, FB_GET_COLOR_CAP, &color_cap);
-	fb_info.color_cap = color_cap;
+	async_req_0_1(fb_info.phone, FB_GET_COLOR_CAP, &fb_info.color_cap);
 	
 	/* Set up shared memory buffer. */
Index: uspace/srv/hid/console/gcons.c
===================================================================
--- uspace/srv/hid/console/gcons.c	(revision caad59aaedb0d9190a12111b1fd41fed41df0d07)
+++ uspace/srv/hid/console/gcons.c	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
@@ -54,5 +54,30 @@
 #define STATUS_HEIGHT  48
 
-#define MAIN_COLOR  0xffffff
+#define COLOR_MAIN        0xffffff
+#define COLOR_FOREGROUND  0x202020
+#define COLOR_BACKGROUND  0xffffff
+
+extern char _binary_gfx_helenos_ppm_start[0];
+extern int _binary_gfx_helenos_ppm_size;
+extern char _binary_gfx_nameic_ppm_start[0];
+extern int _binary_gfx_nameic_ppm_size;
+
+extern char _binary_gfx_anim_1_ppm_start[0];
+extern int _binary_gfx_anim_1_ppm_size;
+extern char _binary_gfx_anim_2_ppm_start[0];
+extern int _binary_gfx_anim_2_ppm_size;
+extern char _binary_gfx_anim_3_ppm_start[0];
+extern int _binary_gfx_anim_3_ppm_size;
+extern char _binary_gfx_anim_4_ppm_start[0];
+extern int _binary_gfx_anim_4_ppm_size;
+
+extern char _binary_gfx_cons_selected_ppm_start[0];
+extern int _binary_gfx_cons_selected_ppm_size;
+extern char _binary_gfx_cons_idle_ppm_start[0];
+extern int _binary_gfx_cons_idle_ppm_size;
+extern char _binary_gfx_cons_has_data_ppm_start[0];
+extern int _binary_gfx_cons_has_data_ppm_size;
+extern char _binary_gfx_cons_kernel_ppm_start[0];
+extern int _binary_gfx_cons_kernel_ppm_size;
 
 static bool use_gcons = false;
@@ -82,10 +107,10 @@
 static size_t active_console = 0;
 
-size_t mouse_x;
-size_t mouse_y;
-
-bool btn_pressed;
-size_t btn_x;
-size_t btn_y;
+static ipcarg_t mouse_x = 0;
+static ipcarg_t mouse_y= 0;
+
+static bool btn_pressed = false;
+static ipcarg_t btn_x = 0;
+static ipcarg_t btn_y = 0;
 
 static void vp_switch(int vp)
@@ -95,5 +120,5 @@
 
 /** Create view port */
-static int vp_create(size_t x, size_t y, size_t width, size_t height)
+static int vp_create(ipcarg_t x, ipcarg_t y, ipcarg_t width, ipcarg_t height)
 {
 	return async_req_2_0(fbphone, FB_VIEWPORT_CREATE, (x << 16) | y,
@@ -112,5 +137,5 @@
 
 /** Transparent putchar */
-static void tran_putch(wchar_t ch, size_t col, size_t row)
+static void tran_putch(wchar_t ch, ipcarg_t col, ipcarg_t row)
 {
 	async_msg_3(fbphone, FB_PUTCHAR, ch, col, row);
@@ -259,14 +284,17 @@
 void gcons_mouse_move(ssize_t dx, ssize_t dy)
 {
-	mouse_x = limit(mouse_x + dx, 0, xres);
-	mouse_y = limit(mouse_y + dy, 0, yres);
-
+	ssize_t nx = (ssize_t) mouse_x + dx;
+	ssize_t ny = (ssize_t) mouse_y + dy;
+	
+	mouse_x = (size_t) limit(nx, 0, xres);
+	mouse_y = (size_t) limit(ny, 0, yres);
+	
 	if (active_console != KERNEL_CONSOLE)
 		async_msg_2(fbphone, FB_POINTER_MOVE, mouse_x, mouse_y);
 }
 
-static int gcons_find_conbut(int x, int y)
-{
-	int status_start = STATUS_START + (xres - 800) / 2;
+static int gcons_find_conbut(ipcarg_t x, ipcarg_t y)
+{
+	ipcarg_t status_start = STATUS_START + (xres - 800) / 2;
 	
 	if ((y < STATUS_TOP) || (y >= STATUS_TOP + STATUS_HEIGHT))
@@ -278,8 +306,14 @@
 	if (x >= status_start + (STATUS_WIDTH + STATUS_SPACE) * CONSOLE_COUNT)
 		return -1;
+	
 	if (((x - status_start) % (STATUS_WIDTH + STATUS_SPACE)) < STATUS_SPACE)
 		return -1;
 	
-	return (x - status_start) / (STATUS_WIDTH + STATUS_SPACE);
+	ipcarg_t btn = (x - status_start) / (STATUS_WIDTH + STATUS_SPACE);
+	
+	if (btn < CONSOLE_COUNT)
+		return btn;
+	
+	return -1;
 }
 
@@ -287,11 +321,15 @@
  *
  * @param state New state (true - pressed, false - depressed)
+ *
  */
 int gcons_mouse_btn(bool state)
 {
-	int conbut;
+	/* Ignore mouse clicks if no buttons
+	   are drawn at all */
+	if (xres < 800)
+		return -1;
 	
 	if (state) {
-		conbut = gcons_find_conbut(mouse_x, mouse_y);
+		int conbut = gcons_find_conbut(mouse_x, mouse_y);
 		if (conbut != -1) {
 			btn_pressed = true;
@@ -307,5 +345,5 @@
 	btn_pressed = false;
 	
-	conbut = gcons_find_conbut(mouse_x, mouse_y);
+	int conbut = gcons_find_conbut(mouse_x, mouse_y);
 	if (conbut == gcons_find_conbut(btn_x, btn_y))
 		return conbut;
@@ -313,5 +351,4 @@
 	return -1;
 }
-
 
 /** Draw a PPM pixmap to framebuffer
@@ -321,12 +358,10 @@
  * @param x Coordinate of upper left corner
  * @param y Coordinate of upper left corner
- */
-static void draw_pixmap(char *logo, size_t size, int x, int y)
-{
-	char *shm;
-	int rc;
-	
+ *
+ */
+static void draw_pixmap(char *logo, size_t size, ipcarg_t x, ipcarg_t y)
+{
 	/* Create area */
-	shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
+	char *shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
 	    MAP_ANONYMOUS, 0, 0);
 	if (shm == MAP_FAILED)
@@ -336,5 +371,5 @@
 	
 	/* Send area */
-	rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
+	int rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
 	if (rc)
 		goto exit;
@@ -356,19 +391,12 @@
 }
 
-extern char _binary_gfx_helenos_ppm_start[0];
-extern int _binary_gfx_helenos_ppm_size;
-extern char _binary_gfx_nameic_ppm_start[0];
-extern int _binary_gfx_nameic_ppm_size;
-
 /** Redraws console graphics */
 void gcons_redraw_console(void)
 {
-	int i;
-	
 	if (!use_gcons)
 		return;
 	
 	vp_switch(0);
-	set_rgb_color(MAIN_COLOR, MAIN_COLOR);
+	set_rgb_color(COLOR_MAIN, COLOR_MAIN);
 	clear();
 	draw_pixmap(_binary_gfx_helenos_ppm_start,
@@ -377,4 +405,5 @@
 	    (size_t) &_binary_gfx_nameic_ppm_size, 5, 17);
 	
+	unsigned int i;
 	for (i = 0; i < CONSOLE_COUNT; i++)
 		redraw_state(i);
@@ -393,10 +422,6 @@
 static int make_pixmap(char *data, size_t size)
 {
-	char *shm;
-	int rc;
-	int pxid = -1;
-	
 	/* Create area */
-	shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
+	char *shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
 	    MAP_ANONYMOUS, 0, 0);
 	if (shm == MAP_FAILED)
@@ -405,6 +430,8 @@
 	memcpy(shm, data, size);
 	
+	int pxid = -1;
+	
 	/* Send area */
-	rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
+	int rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
 	if (rc)
 		goto exit;
@@ -432,16 +459,8 @@
 }
 
-extern char _binary_gfx_anim_1_ppm_start[0];
-extern int _binary_gfx_anim_1_ppm_size;
-extern char _binary_gfx_anim_2_ppm_start[0];
-extern int _binary_gfx_anim_2_ppm_size;
-extern char _binary_gfx_anim_3_ppm_start[0];
-extern int _binary_gfx_anim_3_ppm_size;
-extern char _binary_gfx_anim_4_ppm_start[0];
-extern int _binary_gfx_anim_4_ppm_size;
-
 static void make_anim(void)
 {
-	int an = async_req_1_0(fbphone, FB_ANIM_CREATE, cstatus_vp[KERNEL_CONSOLE]);
+	int an = async_req_1_0(fbphone, FB_ANIM_CREATE,
+	    cstatus_vp[KERNEL_CONSOLE]);
 	if (an < 0)
 		return;
@@ -467,13 +486,4 @@
 	animation = an;
 }
-
-extern char _binary_gfx_cons_selected_ppm_start[0];
-extern int _binary_gfx_cons_selected_ppm_size;
-extern char _binary_gfx_cons_idle_ppm_start[0];
-extern int _binary_gfx_cons_idle_ppm_size;
-extern char _binary_gfx_cons_has_data_ppm_start[0];
-extern int _binary_gfx_cons_has_data_ppm_size;
-extern char _binary_gfx_cons_kernel_ppm_start[0];
-extern int _binary_gfx_cons_kernel_ppm_size;
 
 /** Initialize nice graphical console environment */
@@ -500,5 +510,5 @@
 	
 	/* Create status buttons */
-	size_t status_start = STATUS_START + (xres - 800) / 2;
+	ipcarg_t status_start = STATUS_START + (xres - 800) / 2;
 	size_t i;
 	for (i = 0; i < CONSOLE_COUNT; i++) {
@@ -511,5 +521,5 @@
 		
 		vp_switch(cstatus_vp[i]);
-		set_rgb_color(0x202020, 0xffffff);
+		set_rgb_color(COLOR_FOREGROUND, COLOR_BACKGROUND);
 	}
 	
Index: uspace/srv/hid/console/gcons.h
===================================================================
--- uspace/srv/hid/console/gcons.h	(revision caad59aaedb0d9190a12111b1fd41fed41df0d07)
+++ uspace/srv/hid/console/gcons.h	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
@@ -38,15 +38,15 @@
 #include <sys/types.h>
 
-void gcons_init(int phone);
+void gcons_init(int);
 
 void gcons_redraw_console(void);
-void gcons_change_console(size_t index);
-void gcons_notify_char(size_t index);
+void gcons_change_console(size_t);
+void gcons_notify_char(size_t);
 void gcons_in_kernel(void);
 
-void gcons_notify_connect(size_t index);
-void gcons_notify_disconnect(size_t index);
+void gcons_notify_connect(size_t);
+void gcons_notify_disconnect(size_t);
 
-void gcons_mouse_move(ssize_t dx, ssize_t dy);
+void gcons_mouse_move(ssize_t, ssize_t);
 int gcons_mouse_btn(bool state);
 
Index: uspace/srv/hid/console/keybuffer.h
===================================================================
--- uspace/srv/hid/console/keybuffer.h	(revision caad59aaedb0d9190a12111b1fd41fed41df0d07)
+++ uspace/srv/hid/console/keybuffer.h	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
@@ -47,7 +47,7 @@
 typedef struct {
 	console_event_t fifo[KEYBUFFER_SIZE];
-	unsigned long head;
-	unsigned long tail;
-	unsigned long items;
+	size_t head;
+	size_t tail;
+	size_t items;
 } keybuffer_t;
 
Index: uspace/srv/hid/console/screenbuffer.c
===================================================================
--- uspace/srv/hid/console/screenbuffer.c	(revision caad59aaedb0d9190a12111b1fd41fed41df0d07)
+++ uspace/srv/hid/console/screenbuffer.c	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
@@ -67,5 +67,6 @@
  *
  */
-screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, size_t size_x, size_t size_y)
+screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, ipcarg_t size_x,
+    ipcarg_t size_y)
 {
 	scr->buffer = (keyfield_t *) malloc(sizeof(keyfield_t) * size_x * size_y);
@@ -109,7 +110,7 @@
  *
  */
-void screenbuffer_clear_line(screenbuffer_t *scr, size_t line)
+void screenbuffer_clear_line(screenbuffer_t *scr, ipcarg_t line)
 {
-	size_t x;
+	ipcarg_t x;
 	
 	for (x = 0; x < scr->size_x; x++) {
@@ -140,5 +141,5 @@
  *
  */
-void screenbuffer_goto(screenbuffer_t *scr, size_t x, size_t y)
+void screenbuffer_goto(screenbuffer_t *scr, ipcarg_t x, ipcarg_t y)
 {
 	scr->position_x = x % scr->size_x;
@@ -166,5 +167,6 @@
  *
  */
-void screenbuffer_set_color(screenbuffer_t *scr, uint8_t fg_color, uint8_t bg_color, uint8_t flags)
+void screenbuffer_set_color(screenbuffer_t *scr, uint8_t fg_color,
+    uint8_t bg_color, uint8_t flags)
 {
 	scr->attrs.t = at_idx;
@@ -181,5 +183,6 @@
  *
  */
-void screenbuffer_set_rgb_color(screenbuffer_t *scr, uint32_t fg_color, uint32_t bg_color)
+void screenbuffer_set_rgb_color(screenbuffer_t *scr, uint32_t fg_color,
+    uint32_t bg_color)
 {
 	scr->attrs.t = at_rgb;
Index: uspace/srv/hid/console/screenbuffer.h
===================================================================
--- uspace/srv/hid/console/screenbuffer.h	(revision caad59aaedb0d9190a12111b1fd41fed41df0d07)
+++ uspace/srv/hid/console/screenbuffer.h	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
@@ -38,7 +38,8 @@
 #include <stdint.h>
 #include <sys/types.h>
+#include <ipc/ipc.h>
 #include <bool.h>
 
-#define DEFAULT_FOREGROUND  0x0       /**< default console foreground color */
+#define DEFAULT_FOREGROUND  0x000000  /**< default console foreground color */
 #define DEFAULT_BACKGROUND  0xf0f0f0  /**< default console background color */
 
@@ -82,10 +83,10 @@
 	keyfield_t *buffer;      /**< Screen content - characters and
 	                              their attributes (used as a circular buffer) */
-	size_t size_x;           /**< Number of columns  */
-	size_t size_y;           /**< Number of rows */
+	ipcarg_t size_x;         /**< Number of columns  */
+	ipcarg_t size_y;         /**< Number of rows */
 	
 	/** Coordinates of last printed character for determining cursor position */
-	size_t position_x;
-	size_t position_y;
+	ipcarg_t position_x;
+	ipcarg_t position_y;
 	
 	attrs_t attrs;           /**< Current attributes. */
@@ -107,5 +108,5 @@
  *
  */
-static inline keyfield_t *get_field_at(screenbuffer_t *scr, size_t x, size_t y)
+static inline keyfield_t *get_field_at(screenbuffer_t *scr, ipcarg_t x, ipcarg_t y)
 {
 	return scr->buffer + x + ((y + scr->top_line) % scr->size_y) * scr->size_x;
@@ -140,17 +141,14 @@
 }
 
+extern void screenbuffer_putchar(screenbuffer_t *, wchar_t);
+extern screenbuffer_t *screenbuffer_init(screenbuffer_t *, ipcarg_t, ipcarg_t);
 
-void screenbuffer_putchar(screenbuffer_t *scr, wchar_t c);
-screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, size_t size_x, size_t size_y);
-
-void screenbuffer_clear(screenbuffer_t *scr);
-void screenbuffer_clear_line(screenbuffer_t *scr, size_t line);
-void screenbuffer_copy_buffer(screenbuffer_t *scr, keyfield_t *dest);
-void screenbuffer_goto(screenbuffer_t *scr, size_t x, size_t y);
-void screenbuffer_set_style(screenbuffer_t *scr, uint8_t style);
-void screenbuffer_set_color(screenbuffer_t *scr, uint8_t fg_color,
-    uint8_t bg_color, uint8_t attr);
-void screenbuffer_set_rgb_color(screenbuffer_t *scr, uint32_t fg_color,
-    uint32_t bg_color);
+extern void screenbuffer_clear(screenbuffer_t *);
+extern void screenbuffer_clear_line(screenbuffer_t *, ipcarg_t);
+extern void screenbuffer_copy_buffer(screenbuffer_t *, keyfield_t *);
+extern void screenbuffer_goto(screenbuffer_t *, ipcarg_t, ipcarg_t);
+extern void screenbuffer_set_style(screenbuffer_t *, uint8_t);
+extern void screenbuffer_set_color(screenbuffer_t *, uint8_t, uint8_t, uint8_t);
+extern void screenbuffer_set_rgb_color(screenbuffer_t *, uint32_t, uint32_t);
 
 #endif
Index: uspace/srv/hid/fb/ega.c
===================================================================
--- uspace/srv/hid/fb/ega.c	(revision caad59aaedb0d9190a12111b1fd41fed41df0d07)
+++ uspace/srv/hid/fb/ega.c	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
@@ -28,8 +28,8 @@
 
 /** @defgroup egafb EGA framebuffer
- * @brief	HelenOS EGA framebuffer.
+ * @brief HelenOS EGA framebuffer.
  * @ingroup fbs
  * @{
- */ 
+ */
 /** @file
  */
@@ -58,5 +58,6 @@
 #include "main.h"
 
-#define MAX_SAVED_SCREENS 256
+#define MAX_SAVED_SCREENS  256
+
 typedef struct saved_screen {
 	short *data;
@@ -65,24 +66,70 @@
 saved_screen saved_screens[MAX_SAVED_SCREENS];
 
-#define EGA_IO_BASE ((ioport8_t *) 0x3d4)
-#define EGA_IO_SIZE 2
-
-int ega_normal_color = 0x0f;
-int ega_inverted_color = 0xf0;
-
-#define NORMAL_COLOR		ega_normal_color
-#define INVERTED_COLOR		ega_inverted_color
+#define EGA_IO_BASE  ((ioport8_t *) 0x3d4)
+#define EGA_IO_SIZE  2
 
 /* Allow only 1 connection */
 static int client_connected = 0;
 
-static unsigned int scr_width;
-static unsigned int scr_height;
+static sysarg_t scr_width;
+static sysarg_t scr_height;
 static uint8_t *scr_addr;
 
-static unsigned int style;
-
-static unsigned attr_to_ega_style(const attrs_t *a);
-static uint8_t ega_glyph(wchar_t ch);
+static uint8_t style_normal = 0xf0;
+static uint8_t style_inverted = 0x0f;
+static uint8_t style;
+
+static uint8_t style_to_ega_style(uint8_t style)
+{
+	switch (style) {
+	case STYLE_EMPHASIS:
+		return (style_normal | 0x04);
+	case STYLE_SELECTED:
+		return (style_inverted | 0x40);
+	case STYLE_INVERTED:
+		return style_inverted;
+	}
+	
+	return style_normal;
+}
+
+static uint8_t color_to_ega_style(uint8_t fg_color, uint8_t bg_color,
+    uint8_t attr)
+{
+	uint8_t style = (fg_color & 7) | ((bg_color & 7) << 4);
+	
+	if (attr & CATTR_BRIGHT)
+		style |= 0x08;
+	
+	return style;
+}
+
+static uint8_t rgb_to_ega_style(uint32_t fg, uint32_t bg)
+{
+	return (fg > bg) ? style_inverted : style_normal;
+}
+
+static uint8_t attr_to_ega_style(const attrs_t *attr)
+{
+	switch (attr->t) {
+	case at_style:
+		return style_to_ega_style(attr->a.s.style);
+	case at_idx:
+		return color_to_ega_style(attr->a.i.fg_color,
+		    attr->a.i.bg_color, attr->a.i.flags);
+	case at_rgb:
+		return rgb_to_ega_style(attr->a.r.fg_color, attr->a.r.bg_color);
+	default:
+		return style_normal;
+	}
+}
+
+static uint8_t ega_glyph(wchar_t ch)
+{
+	if (ch >= 0 && ch < 128)
+		return ch;
+	
+	return '?';
+}
 
 static void clrscr(void)
@@ -96,22 +143,20 @@
 }
 
-static void cursor_goto(unsigned int col, unsigned int row)
-{
-	int ega_cursor;
-
-	ega_cursor = col + scr_width * row;
+static void cursor_goto(sysarg_t col, sysarg_t row)
+{
+	sysarg_t cursor = col + scr_width * row;
 	
 	pio_write_8(EGA_IO_BASE, 0xe);
-	pio_write_8(EGA_IO_BASE + 1, (ega_cursor >> 8) & 0xff);
+	pio_write_8(EGA_IO_BASE + 1, (cursor >> 8) & 0xff);
 	pio_write_8(EGA_IO_BASE, 0xf);
-	pio_write_8(EGA_IO_BASE + 1, ega_cursor & 0xff);
+	pio_write_8(EGA_IO_BASE + 1, cursor & 0xff);
 }
 
 static void cursor_disable(void)
 {
-	uint8_t stat;
-
 	pio_write_8(EGA_IO_BASE, 0xa);
-	stat = pio_read_8(EGA_IO_BASE + 1);
+	
+	uint8_t stat = pio_read_8(EGA_IO_BASE + 1);
+	
 	pio_write_8(EGA_IO_BASE, 0xa);
 	pio_write_8(EGA_IO_BASE + 1, stat | (1 << 5));
@@ -120,16 +165,16 @@
 static void cursor_enable(void)
 {
-	uint8_t stat;
-
 	pio_write_8(EGA_IO_BASE, 0xa);
-	stat = pio_read_8(EGA_IO_BASE + 1);
+	
+	uint8_t stat = pio_read_8(EGA_IO_BASE + 1);
+	
 	pio_write_8(EGA_IO_BASE, 0xa);
 	pio_write_8(EGA_IO_BASE + 1, stat & (~(1 << 5)));
 }
 
-static void scroll(int rows)
-{
-	unsigned i;
-
+static void scroll(ssize_t rows)
+{
+	size_t i;
+	
 	if (rows > 0) {
 		memmove(scr_addr, ((char *) scr_addr) + rows * scr_width * 2,
@@ -142,9 +187,9 @@
 		    scr_width * scr_height * 2 + rows * scr_width * 2);
 		for (i = 0; i < -rows * scr_width; i++)
-			((short *)scr_addr)[i] = ((style << 8 ) + ' ');
-	}
-}
-
-static void printchar(wchar_t c, unsigned int col, unsigned int row)
+			((short *) scr_addr)[i] = ((style << 8 ) + ' ');
+	}
+}
+
+static void printchar(wchar_t c, sysarg_t col, sysarg_t row)
 {
 	scr_addr[(row * scr_width + col) * 2] = ega_glyph(c);
@@ -158,21 +203,23 @@
  * @param vport Viewport id
  * @param data  Text data.
- * @param x	Leftmost column of the area.
- * @param y	Topmost row of the area.
- * @param w	Number of rows.
- * @param h	Number of columns.
+ * @param x     Leftmost column of the area.
+ * @param y     Topmost row of the area.
+ * @param w     Number of rows.
+ * @param h     Number of columns.
+ *
  */
-static void draw_text_data(keyfield_t *data, unsigned int x,
-    unsigned int y, unsigned int w, unsigned int h)
-{
-	unsigned int i, j;
+static void draw_text_data(keyfield_t *data, sysarg_t x, sysarg_t y,
+    sysarg_t w, sysarg_t h)
+{
+	sysarg_t i;
+	sysarg_t j;
 	keyfield_t *field;
 	uint8_t *dp;
-
+	
 	for (j = 0; j < h; j++) {
 		for (i = 0; i < w; i++) {
 			field = &data[j * w + i];
 			dp = &scr_addr[2 * ((y + j) * scr_width + (x + i))];
-
+			
 			dp[0] = ega_glyph(field->character);
 			dp[1] = attr_to_ega_style(&field->attrs);
@@ -183,96 +230,34 @@
 static int save_screen(void)
 {
-	int i;
-
-	for (i = 0; (i < MAX_SAVED_SCREENS) && (saved_screens[i].data); i++)
-		;
-	if (i == MAX_SAVED_SCREENS) 
+	ipcarg_t i;
+	
+	/* Find empty screen */
+	for (i = 0; (i < MAX_SAVED_SCREENS) && (saved_screens[i].data); i++);
+	
+	if (i == MAX_SAVED_SCREENS)
 		return EINVAL;
-	if (!(saved_screens[i].data = malloc(2 * scr_width * scr_height))) 
+	
+	if (!(saved_screens[i].data = malloc(2 * scr_width * scr_height)))
 		return ENOMEM;
+	
 	memcpy(saved_screens[i].data, scr_addr, 2 * scr_width * scr_height);
-
-	return i;
-}
-
-static int print_screen(int i)
-{
-	if (saved_screens[i].data)
+	return (int) i;
+}
+
+static int print_screen(ipcarg_t i)
+{
+	if ((i >= MAX_SAVED_SCREENS) || (saved_screens[i].data))
 		memcpy(scr_addr, saved_screens[i].data, 2 * scr_width *
 		    scr_height);
 	else
 		return EINVAL;
-	return i;
-}
-
-static int style_to_ega_style(int style)
-{
-	unsigned int ega_style;
-
-	switch (style) {
-	case STYLE_NORMAL:
-		ega_style = INVERTED_COLOR;
-		break;
-	case STYLE_EMPHASIS:
-		ega_style = INVERTED_COLOR | 4;
-		break;
-	default:
-		return INVERTED_COLOR;
-	}
-
-	return ega_style;
-}
-
-static unsigned int color_to_ega_style(int fg_color, int bg_color, int attr)
-{
-	unsigned int style;
-
-	style = (fg_color & 7) | ((bg_color & 7) << 4);
-	if (attr & CATTR_BRIGHT)
-		style = style | 0x08;
-
-	return style;
-}
-
-static unsigned int rgb_to_ega_style(uint32_t fg, uint32_t bg)
-{
-	return (fg > bg) ? NORMAL_COLOR : INVERTED_COLOR;
-}
-
-static unsigned attr_to_ega_style(const attrs_t *a)
-{
-	switch (a->t) {
-	case at_style:
-		return style_to_ega_style(a->a.s.style);
-	case at_rgb:
-		return rgb_to_ega_style(a->a.r.fg_color, a->a.r.bg_color);
-	case at_idx:
-		return color_to_ega_style(a->a.i.fg_color,
-		    a->a.i.bg_color, a->a.i.flags);
-	default:
-		return INVERTED_COLOR;
-	}
-}
-
-static uint8_t ega_glyph(wchar_t ch)
-{
-	if (ch >= 0 && ch < 128)
-		return ch;
-
-	return '?';
+	
+	return (int) i;
 }
 
 static void ega_client_connection(ipc_callid_t iid, ipc_call_t *icall)
 {
-	int retval;
-	ipc_callid_t callid;
-	ipc_call_t call;
-	wchar_t c;
-	unsigned int row, col, w, h;
-	int bg_color, fg_color, attr;
-	uint32_t bg_rgb, fg_rgb;
+	size_t intersize = 0;
 	keyfield_t *interbuf = NULL;
-	size_t intersize = 0;
-	int i;
 
 	if (client_connected) {
@@ -280,14 +265,39 @@
 		return;
 	}
+	
+	/* Accept connection */
 	client_connected = 1;
-	ipc_answer_0(iid, EOK); /* Accept connection */
-
-	while (1) {
-		callid = async_get_call(&call);
- 		switch (IPC_GET_METHOD(call)) {
+	ipc_answer_0(iid, EOK);
+	
+	while (true) {
+		ipc_call_t call;
+		ipc_callid_t callid = async_get_call(&call);
+		
+		wchar_t c;
+		
+		ipcarg_t col;
+		ipcarg_t row;
+		ipcarg_t w;
+		ipcarg_t h;
+		
+		ssize_t rows;
+		
+		uint8_t bg_color;
+		uint8_t fg_color;
+		uint8_t attr;
+		
+		uint32_t fg_rgb;
+		uint32_t bg_rgb;
+		
+		ipcarg_t scr;
+		int retval;
+		
+		switch (IPC_GET_METHOD(call)) {
 		case IPC_M_PHONE_HUNGUP:
 			client_connected = 0;
 			ipc_answer_0(callid, EOK);
-			return; /* Exit thread */
+			
+			/* Exit thread */
+			return;
 		case IPC_M_SHARE_OUT:
 			/* We accept one area for data interchange */
@@ -299,19 +309,23 @@
 				continue;
 			}
+			
 			retval = EINVAL;
 			break;
 		case FB_DRAW_TEXT_DATA:
+			if (!interbuf) {
+				retval = EINVAL;
+				break;
+			}
+			
 			col = IPC_GET_ARG1(call);
 			row = IPC_GET_ARG2(call);
 			w = IPC_GET_ARG3(call);
 			h = IPC_GET_ARG4(call);
-			if (!interbuf) {
+			
+			if ((col + w > scr_width) || (row + h > scr_height)) {
 				retval = EINVAL;
 				break;
 			}
-			if (col + w > scr_width || row + h > scr_height) {
-				retval = EINVAL;
-				break;
-			}
+			
 			draw_text_data(interbuf, col, row, w, h);
 			retval = 0;
@@ -331,28 +345,41 @@
 			col = IPC_GET_ARG2(call);
 			row = IPC_GET_ARG3(call);
-			if (col >= scr_width || row >= scr_height) {
+			
+			if ((col >= scr_width) || (row >= scr_height)) {
 				retval = EINVAL;
 				break;
 			}
+			
 			printchar(c, col, row);
 			retval = 0;
 			break;
- 		case FB_CURSOR_GOTO:
- 			col = IPC_GET_ARG1(call);
+		case FB_CURSOR_GOTO:
+			col = IPC_GET_ARG1(call);
 			row = IPC_GET_ARG2(call);
-			if (row >= scr_height || col >= scr_width) {
+			
+			if ((row >= scr_height) || (col >= scr_width)) {
 				retval = EINVAL;
 				break;
 			}
+			
 			cursor_goto(col, row);
- 			retval = 0;
- 			break;
+			retval = 0;
+			break;
 		case FB_SCROLL:
-			i = IPC_GET_ARG1(call);
-			if (i > (int) scr_height || i < -((int) scr_height)) {
-				retval = EINVAL;
-				break;
-			}
-			scroll(i);
+			rows = IPC_GET_ARG1(call);
+			
+			if (rows >= 0) {
+				if ((ipcarg_t) rows > scr_height) {
+					retval = EINVAL;
+					break;
+				}
+			} else {
+				if ((ipcarg_t) (-rows) > scr_height) {
+					retval = EINVAL;
+					break;
+				}
+			}
+			
+			scroll(rows);
 			retval = 0;
 			break;
@@ -362,4 +389,5 @@
 			else
 				cursor_disable();
+			
 			retval = 0;
 			break;
@@ -372,4 +400,5 @@
 			bg_color = IPC_GET_ARG2(call);
 			attr = IPC_GET_ARG3(call);
+			
 			style = color_to_ega_style(fg_color, bg_color, attr);
 			retval = 0;
@@ -378,10 +407,11 @@
 			fg_rgb = IPC_GET_ARG1(call);
 			bg_rgb = IPC_GET_ARG2(call);
+			
 			style = rgb_to_ega_style(fg_rgb, bg_rgb);
 			retval = 0;
 			break;
 		case FB_VP_DRAW_PIXMAP:
-			i = IPC_GET_ARG2(call);
-			retval = print_screen(i);
+			scr = IPC_GET_ARG2(call);
+			retval = print_screen(scr);
 			break;
 		case FB_VP2PIXMAP:
@@ -389,13 +419,16 @@
 			break;
 		case FB_DROP_PIXMAP:
-			i = IPC_GET_ARG1(call);
-			if (i >= MAX_SAVED_SCREENS) {
+			scr = IPC_GET_ARG1(call);
+			
+			if (scr >= MAX_SAVED_SCREENS) {
 				retval = EINVAL;
 				break;
 			}
-			if (saved_screens[i].data) {
-				free(saved_screens[i].data);
-				saved_screens[i].data = NULL;
-			}
+			
+			if (saved_screens[scr].data) {
+				free(saved_screens[scr].data);
+				saved_screens[scr].data = NULL;
+			}
+			
 			retval = 0;
 			break;
@@ -413,17 +446,12 @@
 int ega_init(void)
 {
-	void *ega_ph_addr;
-	size_t sz;
-	
 	sysarg_t paddr;
 	if (sysinfo_get_value("fb.address.physical", &paddr) != EOK)
 		return -1;
 	
-	sysarg_t width;
-	if (sysinfo_get_value("fb.width", &width) != EOK)
+	if (sysinfo_get_value("fb.width", &scr_width) != EOK)
 		return -1;
 	
-	sysarg_t height;
-	if (sysinfo_get_value("fb.width", &height) != EOK)
+	if (sysinfo_get_value("fb.height", &scr_height) != EOK)
 		return -1;
 	
@@ -432,17 +460,15 @@
 		blinking = false;
 	
-	ega_ph_addr = (void *) paddr;
-	scr_width = width;
-	scr_height = height;
+	void *ega_ph_addr = (void *) paddr;
 	if (blinking) {
-		ega_normal_color &= 0x77;
-		ega_inverted_color &= 0x77;
-	}
-	
-	style = NORMAL_COLOR;
+		style_normal &= 0x77;
+		style_inverted &= 0x77;
+	}
+	
+	style = style_normal;
 	
 	iospace_enable(task_get_id(), (void *) EGA_IO_BASE, 2);
 	
-	sz = scr_width * scr_height * 2;
+	size_t sz = scr_width * scr_height * 2;
 	scr_addr = as_get_mappable_page(sz);
 	
@@ -450,10 +476,9 @@
 	    PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE) != 0)
 		return -1;
-
+	
 	async_set_client_connection(ega_client_connection);
-
+	
 	return 0;
 }
-
 
 /**
Index: uspace/srv/hid/fb/fb.c
===================================================================
--- uspace/srv/hid/fb/fb.c	(revision caad59aaedb0d9190a12111b1fd41fed41df0d07)
+++ uspace/srv/hid/fb/fb.c	(revision 9f1362d4e7eaaca0f48042dc579d07341d14e38a)
@@ -72,10 +72,10 @@
 #define DEFAULT_FGCOLOR  0x000000
 
-#define GLYPH_UNAVAIL    '?'
-
-#define MAX_ANIM_LEN     8
-#define MAX_ANIMATIONS   4
-#define MAX_PIXMAPS      256  /**< Maximum number of saved pixmaps */
-#define MAX_VIEWPORTS    128  /**< Viewport is a rectangular area on the screen */
+#define GLYPH_UNAVAIL  '?'
+
+#define MAX_ANIM_LEN    8
+#define MAX_ANIMATIONS  4
+#define MAX_PIXMAPS     256  /**< Maximum number of saved pixmaps */
+#define MAX_VIEWPORTS   128  /**< Viewport is a rectangular area on the screen */
 
 /** Function to render a pixel from a RGB value. */
@@ -956,5 +956,4 @@
 	bb_cell_t *bbp;
 	attrs_t *a;
-	attr_rgb_t rgb;
 	
 	for (j = 0; j < h; j++) {
@@ -966,4 +965,8 @@
 			
 			a = &data[j * w + i].attrs;
+			
+			attr_rgb_t rgb;
+			rgb.fg_color = 0;
+			rgb.bg_color = 0;
 			rgb_from_attr(&rgb, a);
 			
@@ -1511,8 +1514,16 @@
 		rgb->bg_color = color_table[COLOR_WHITE];
 		break;
+	case STYLE_INVERTED:
+		rgb->fg_color = color_table[COLOR_WHITE];
+		rgb->bg_color = color_table[COLOR_BLACK];
+		break;
+	case STYLE_SELECTED:
+		rgb->fg_color = color_table[COLOR_WHITE];
+		rgb->bg_color = color_table[COLOR_RED];
+		break;
 	default:
 		return EINVAL;
 	}
-
+	
 	return EOK;
 }
