Index: uspace/app/edit/edit.c
===================================================================
--- uspace/app/edit/edit.c	(revision 6df564c1a6c22444f93b935ba00952ba2e8b47d3)
+++ uspace/app/edit/edit.c	(revision 68632b48554bac37d2c3c33bd391ce23dcffeaef)
@@ -1,4 +1,4 @@
 /*
- * Copyright (c) 2009 Jiri Svoboda
+ * Copyright (c) 2021 Jiri Svoboda
  * Copyright (c) 2012 Martin Sucha
  * All rights reserved.
@@ -36,17 +36,20 @@
  */
 
+#include <align.h>
+#include <clipboard.h>
+#include <errno.h>
+#include <io/kbd_event.h>
+#include <io/keycode.h>
+#include <io/pos_event.h>
+#include <io/style.h>
+#include <macros.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stddef.h>
 #include <stdbool.h>
+#include <types/common.h>
+#include <ui/ui.h>
+#include <ui/window.h>
 #include <vfs/vfs.h>
-#include <io/console.h>
-#include <io/style.h>
-#include <io/keycode.h>
-#include <errno.h>
-#include <align.h>
-#include <macros.h>
-#include <clipboard.h>
-#include <types/common.h>
 
 #include "sheet.h"
@@ -94,4 +97,12 @@
 } pane_t;
 
+/** Text editor */
+typedef struct {
+	/** User interface */
+	ui_t *ui;
+	/** Editor window */
+	ui_window_t *window;
+} edit_t;
+
 /** Document
  *
@@ -103,5 +114,5 @@
 } doc_t;
 
-static console_ctrl_t *con;
+static edit_t edit;
 static doc_t doc;
 static bool done;
@@ -185,15 +196,23 @@
 
 static void status_display(char const *str);
+static errno_t edit_ui_create(edit_t *);
+static void edit_ui_destroy(edit_t *);
 
 int main(int argc, char *argv[])
 {
-	cons_event_t ev;
+//	cons_event_t ev;
 	bool new_file;
 	errno_t rc;
 
-	con = console_init(stdin, stdout);
-	console_clear(con);
-
-	console_get_size(con, &scr_columns, &scr_rows);
+	(void) pos_handle;
+	(void) key_handle_press;
+	(void) pane_row_display;
+
+//	con = console_init(stdin, stdout);
+//	console_clear(con);
+
+//	console_get_size(con, &scr_columns, &scr_rows);
+	scr_columns = 80;
+	scr_rows = 25;
 
 	pane.rows = scr_rows - 1;
@@ -236,9 +255,19 @@
 	caret_move(sof, true, true);
 
+	/* Create UI */
+	rc = edit_ui_create(&edit);
+	if (rc != EOK)
+		return 1;
+
 	/* Initial display */
 	cursor_visible = true;
+	rc = ui_window_paint(edit.window);
+	if (rc != EOK) {
+		printf("Error painting window.\n");
+		return rc;
+	}
 
 	cursor_hide();
-	console_clear(con);
+//	console_clear(con);
 	pane_text_display();
 	pane_status_display();
@@ -247,5 +276,5 @@
 	pane_caret_display();
 	cursor_show();
-
+/*
 	done = false;
 
@@ -268,5 +297,5 @@
 		}
 
-		/* Redraw as necessary. */
+		/ Redraw as necessary. /
 
 		cursor_hide();
@@ -285,6 +314,121 @@
 
 	console_clear(con);
-
+*/
+
+	ui_run(edit.ui);
+
+	edit_ui_destroy(&edit);
 	return 0;
+}
+
+/** Create text editor UI.
+ *
+ * @param edit Editor
+ * @return EOK on success or an error code
+ */
+static errno_t edit_ui_create(edit_t *edit)
+{
+	errno_t rc;
+	ui_wnd_params_t params;
+
+	rc = ui_create(UI_CONSOLE_DEFAULT, &edit->ui);
+	if (rc != EOK) {
+		printf("Error creating UI on display %s.\n",
+		    UI_CONSOLE_DEFAULT);
+		goto error;
+	}
+
+	ui_wnd_params_init(&params);
+	params.caption = "Text Editor";
+	params.rect.p0.x = 0;
+	params.rect.p0.y = 0;
+	params.rect.p1.x = 38;
+	params.rect.p1.y = 18;
+
+	rc = ui_window_create(edit->ui, &params, &edit->window);
+	if (rc != EOK) {
+		printf("Error creating window.\n");
+		goto error;
+	}
+/*
+	ui_window_set_cb(window, &window_cb, (void *) &calc);
+	calc.ui = ui;
+
+	ui_res = ui_window_get_res(window);
+	calc.ui_res = ui_res;
+
+	rc = ui_fixed_create(&fixed);
+	if (rc != EOK) {
+		printf("Error creating fixed layout.\n");
+		return rc;
+	}
+
+	rc = ui_menu_bar_create(ui, window, &calc.menubar);
+	if (rc != EOK) {
+		printf("Error creating menu bar.\n");
+		return rc;
+	}
+
+	rc = ui_menu_create(calc.menubar, "File", &mfile);
+	if (rc != EOK) {
+		printf("Error creating menu.\n");
+		return rc;
+	}
+
+	rc = ui_menu_entry_create(mfile, "Exit", "Alt-F4", &mexit);
+	if (rc != EOK) {
+		printf("Error creating menu.\n");
+		return rc;
+	}
+
+	ui_menu_entry_set_cb(mexit, calc_file_exit, (void *) &calc);
+
+	rc = ui_menu_create(calc.menubar, "Edit", &medit);
+	if (rc != EOK) {
+		printf("Error creating menu.\n");
+		return rc;
+	}
+
+	rc = ui_menu_entry_create(medit, "Copy", "Ctrl-C", &mcopy);
+	if (rc != EOK) {
+		printf("Error creating menu.\n");
+		return rc;
+	}
+
+	ui_menu_entry_set_cb(mcopy, calc_edit_copy, (void *) &calc);
+
+	rc = ui_menu_entry_create(medit, "Paste", "Ctrl-V", &mpaste);
+	if (rc != EOK) {
+		printf("Error creating menu.\n");
+		return rc;
+	}
+
+	ui_menu_entry_set_cb(mpaste, calc_edit_paste, (void *) &calc);
+
+	ui_menu_bar_set_rect(calc.menubar, &calc.geom.menubar_rect);
+
+	rc = ui_fixed_add(fixed, ui_menu_bar_ctl(calc.menubar));
+	if (rc != EOK) {
+		printf("Error adding control to layout.\n");
+		return rc;
+	}
+*/
+	return EOK;
+error:
+	if (edit->window != NULL)
+		ui_window_destroy(edit->window);
+	if (edit->ui != NULL)
+		ui_destroy(edit->ui);
+	return rc;
+}
+
+/** Destroy text editor UI.
+ *
+ * @param edit Editor
+ */
+static void edit_ui_destroy(edit_t *edit)
+{
+	ui_window_destroy(edit->window);
+	ui_destroy(edit->ui);
 }
 
@@ -322,5 +466,5 @@
 {
 	if (cursor_visible != visible) {
-		console_cursor_visibility(con, visible);
+//		console_cursor_visibility(con, visible);
 		cursor_visible = visible;
 	}
@@ -630,66 +774,5 @@
 static char *prompt(char const *prompt, char const *init_value)
 {
-	cons_event_t ev;
-	kbd_event_t *kev;
-	char *str;
-	char32_t buffer[INFNAME_MAX_LEN + 1];
-	int max_len;
-	int nc;
-	bool done;
-	errno_t rc;
-
-	asprintf(&str, "%s: %s", prompt, init_value);
-	status_display(str);
-	console_set_pos(con, 1 + str_length(str), scr_rows - 1);
-	free(str);
-
-	console_set_style(con, STYLE_INVERTED);
-
-	max_len = min(INFNAME_MAX_LEN, scr_columns - 4 - str_length(prompt));
-	str_to_wstr(buffer, max_len + 1, init_value);
-	nc = wstr_length(buffer);
-	done = false;
-
-	while (!done) {
-		rc = console_get_event(con, &ev);
-		if (rc != EOK)
-			return NULL;
-
-		if (ev.type == CEV_KEY && ev.ev.key.type == KEY_PRESS) {
-			kev = &ev.ev.key;
-
-			/* Handle key press. */
-			if ((kev->mods & (KM_CTRL | KM_ALT)) == 0) {
-				switch (kev->key) {
-				case KC_ESCAPE:
-					return NULL;
-				case KC_BACKSPACE:
-					if (nc > 0) {
-						putchar('\b');
-						console_flush(con);
-						--nc;
-					}
-					break;
-				case KC_ENTER:
-					done = true;
-					break;
-				default:
-					if (kev->c >= 32 && nc < max_len) {
-						putuchar(kev->c);
-						console_flush(con);
-						buffer[nc++] = kev->c;
-					}
-					break;
-				}
-			}
-		}
-	}
-
-	buffer[nc] = '\0';
-	str = wstr_to_astr(buffer);
-
-	console_set_style(con, STYLE_NORMAL);
-
-	return str;
+	return str_dup("42");
 }
 
@@ -817,5 +900,5 @@
 	/* Draw rows from the sheet. */
 
-	console_set_pos(con, 0, 0);
+//	console_set_pos(con, 0, 0);
 	pane_row_range_display(0, rows);
 
@@ -825,8 +908,8 @@
 	sysarg_t j;
 	for (i = rows; i < pane.rows; ++i) {
-		console_set_pos(con, 0, i);
+//		console_set_pos(con, 0, i);
 		for (j = 0; j < scr_columns; ++j)
 			putchar(' ');
-		console_flush(con);
+//		console_flush(con);
 	}
 
@@ -877,5 +960,5 @@
 	/* Draw rows from the sheet. */
 
-	console_set_pos(con, 0, 0);
+//	console_set_pos(con, 0, 0);
 	for (i = r0; i < r1; ++i) {
 		/* Starting point for row display */
@@ -896,10 +979,10 @@
 		if (coord_cmp(&csel_start, &rbc) <= 0 &&
 		    coord_cmp(&rbc, &csel_end) < 0) {
-			console_flush(con);
-			console_set_style(con, STYLE_SELECTED);
-			console_flush(con);
+//			console_flush(con);
+//			console_set_style(con, STYLE_SELECTED);
+//			console_flush(con);
 		}
 
-		console_set_pos(con, 0, i);
+//		console_set_pos(con, 0, i);
 		size = str_size(row_buf);
 		pos = 0;
@@ -907,13 +990,13 @@
 		while (pos < size) {
 			if ((csel_start.row == rbc.row) && (csel_start.column == s_column)) {
-				console_flush(con);
-				console_set_style(con, STYLE_SELECTED);
-				console_flush(con);
+//				console_flush(con);
+//				console_set_style(con, STYLE_SELECTED);
+//				console_flush(con);
 			}
 
 			if ((csel_end.row == rbc.row) && (csel_end.column == s_column)) {
-				console_flush(con);
-				console_set_style(con, STYLE_NORMAL);
-				console_flush(con);
+//				console_flush(con);
+//				console_set_style(con, STYLE_NORMAL);
+//				console_flush(con);
 			}
 
@@ -933,7 +1016,7 @@
 
 		if ((csel_end.row == rbc.row) && (csel_end.column == s_column)) {
-			console_flush(con);
-			console_set_style(con, STYLE_NORMAL);
-			console_flush(con);
+//			console_flush(con);
+//			console_set_style(con, STYLE_NORMAL);
+//			console_flush(con);
 		}
 
@@ -947,6 +1030,6 @@
 		for (j = 0; j < fill; ++j)
 			putchar(' ');
-		console_flush(con);
-		console_set_style(con, STYLE_NORMAL);
+//		console_flush(con);
+//		console_set_style(con, STYLE_NORMAL);
 	}
 
@@ -987,6 +1070,6 @@
 		return;
 
-	console_set_pos(con, 0, scr_rows - 1);
-	console_set_style(con, STYLE_INVERTED);
+//	console_set_pos(con, 0, scr_rows - 1);
+//	console_set_style(con, STYLE_INVERTED);
 
 	/*
@@ -1041,6 +1124,6 @@
 	pos = scr_columns - 1 - n;
 	printf("%*s", pos, "");
-	console_flush(con);
-	console_set_style(con, STYLE_NORMAL);
+//	console_flush(con);
+//	console_set_style(con, STYLE_NORMAL);
 
 	pane.rflags |= REDRAW_CARET;
@@ -1056,6 +1139,6 @@
 
 	spt_get_coord(&caret_pt, &coord);
-	console_set_pos(con, coord.column - pane.sh_column,
-	    coord.row - pane.sh_row);
+//	console_set_pos(con, coord.column - pane.sh_column,
+//	    coord.row - pane.sh_row);
 }
 
@@ -1719,11 +1802,11 @@
 static void status_display(char const *str)
 {
-	console_set_pos(con, 0, scr_rows - 1);
-	console_set_style(con, STYLE_INVERTED);
+//	console_set_pos(con, 0, scr_rows - 1);
+//	console_set_style(con, STYLE_INVERTED);
 
 	int pos = -(scr_columns - 3);
 	printf(" %*s ", pos, str);
-	console_flush(con);
-	console_set_style(con, STYLE_NORMAL);
+//	console_flush(con);
+//	console_set_style(con, STYLE_NORMAL);
 
 	pane.rflags |= REDRAW_CARET;
Index: uspace/app/edit/meson.build
===================================================================
--- uspace/app/edit/meson.build	(revision 6df564c1a6c22444f93b935ba00952ba2e8b47d3)
+++ uspace/app/edit/meson.build	(revision 68632b48554bac37d2c3c33bd391ce23dcffeaef)
@@ -1,3 +1,4 @@
 #
+# Copyright (c) 2021 Jiri Svoboda
 # Copyright (c) 2005 Martin Decky
 # Copyright (c) 2007 Jakub Jermar
@@ -28,4 +29,5 @@
 #
 
+deps = [ 'ui' ]
 src = files(
 	'edit.c',
Index: uspace/lib/ui/include/types/ui/ui.h
===================================================================
--- uspace/lib/ui/include/types/ui/ui.h	(revision 6df564c1a6c22444f93b935ba00952ba2e8b47d3)
+++ uspace/lib/ui/include/types/ui/ui.h	(revision 68632b48554bac37d2c3c33bd391ce23dcffeaef)
@@ -42,6 +42,8 @@
 typedef struct ui ui_t;
 
-/** Use the default display service (argument to ui_create() */
+/** Use the default display service (argument to ui_create()) */
 #define UI_DISPLAY_DEFAULT NULL
+/** Use the default console service (argument to ui_create()) */
+#define UI_CONSOLE_DEFAULT "cons@"
 
 /** Window system */
