diff -Nauwr --exclude Makefile.in --exclude Makefile xchat-1.8.9.orig/src/fe-text/Makefile.am xchat-1.8.9/src/fe-text/Makefile.am
--- xchat-1.8.9.orig/src/fe-text/Makefile.am	Sun Jun 17 11:44:44 2001
+++ xchat-1.8.9/src/fe-text/Makefile.am	Sat Jul 13 21:46:32 2002
@@ -8,4 +8,7 @@
 
 INCLUDES = -I$(includedir)	-DLOCALEDIR=\"$(datadir)/locale\"
 
-xchat_text_SOURCES = fe-text.c $(glibc)
+xchat_text_SOURCES = fe-text.c ui.c color.c $(glibc)
+
+xchat_text_LDFLAGS=-lncurses -lreadline
+
diff -Nauwr --exclude Makefile.in --exclude Makefile xchat-1.8.9.orig/src/fe-text/color.c xchat-1.8.9/src/fe-text/color.c
--- xchat-1.8.9.orig/src/fe-text/color.c	Thu Jan  1 01:00:00 1970
+++ xchat-1.8.9/src/fe-text/color.c	Sat Jul 13 22:23:32 2002
@@ -0,0 +1,134 @@
+
+
+#include <curses.h>
+#include <ctype.h>
+
+
+/**
+ * Parse and output text in the window win.
+ *
+ * @param win: print text in this window.
+ * @param prefix: output this string after each new line (can be NULL)
+ * @param text: print this text (need to be terminated by a null character)
+ */
+void
+print_color_text(WINDOW *win, const char *prefix, const char *text)
+{
+  int print_prefix = TRUE;
+  int attr=A_NORMAL;
+  const char *ptext;
+  int code,code2;
+  int k;
+
+  struct {
+     int car;
+     int attr;
+  } attr_tab [] = {
+      { '\026', A_REVERSE },
+      { '\037', A_UNDERLINE },
+      { '\002', A_BOLD },
+      { '\017', A_NORMAL },
+      { '\000', 0 },
+  };
+
+  struct {
+     int fg,bg;
+  } colors_code [16] = {
+      { COLOR_WHITE|A_BOLD,COLOR_WHITE },
+      { COLOR_BLACK|A_BOLD,COLOR_BLACK },
+      { COLOR_BLUE,COLOR_BLUE },
+      { COLOR_GREEN,COLOR_GREEN },
+      { COLOR_RED,COLOR_RED },
+      { COLOR_YELLOW,COLOR_YELLOW },
+      { COLOR_MAGENTA,COLOR_MAGENTA },
+      { COLOR_RED|A_BOLD,COLOR_RED },
+      { COLOR_YELLOW,COLOR_YELLOW },
+      { COLOR_GREEN|A_BOLD,COLOR_GREEN },
+      { COLOR_CYAN,COLOR_CYAN },
+      { COLOR_CYAN|A_BOLD,COLOR_CYAN },
+      { COLOR_BLUE|A_BOLD,COLOR_BLUE },
+      { COLOR_MAGENTA|A_BOLD,COLOR_MAGENTA },
+      { COLOR_BLACK|A_BOLD,COLOR_BLACK },
+      { COLOR_WHITE|A_BOLD,COLOR_WHITE }
+  };
+
+  ptext=text;
+  while (*ptext)
+   {
+     if (prefix && print_prefix)
+      {
+	print_color_text(win,NULL,prefix);
+	print_prefix = FALSE;
+      }
+
+     for (k=0;attr_tab[k].car;k++)
+      {
+	if (attr_tab[k].car==*ptext)
+	 {
+	   if (attr & attr_tab[k].attr)
+	     attr &=~attr_tab[k].attr;
+	   else
+	     attr |=attr_tab[k].attr;
+	   wattrset(win,attr);
+	   break;
+	 }
+      }
+     if (attr_tab[k].car==0)
+      {
+	switch (*ptext)
+	 {
+	  case '\003': /* ^Cxx Mirc color */
+	     {
+	       if (isdigit(*++ptext))
+		 {
+		   /* FIXME: Need to test the end of the string */
+		   code = *ptext++ - '0';
+		   if (isdigit (*ptext))
+		     code = code * 10 + *ptext++ - '0';
+		   if (code > 15 || code <= 0)
+		     code = code % 16;
+		   code = colors_code[code].fg;
+
+		   if (code & A_BOLD)
+		    {
+//		      attr |= A_BOLD;
+		      code &= ~A_BOLD;
+		    }
+//		   else
+//		     attr &= ~A_BOLD;
+
+		   wattr_set(win,attr,code,0);
+		   if (*ptext == ',')
+		    {
+		      code2 = *++ptext - '0';
+		      if (isdigit (*++ptext))
+			code2 = code2 * 10 + *ptext++ - '0';
+		      if (code2 > 15 || code2 <= 0)
+		       	code2 = code2 % 16;
+		      code2 = colors_code[code2].bg * COLORS + code;
+		      wattr_set(win,attr,code2,0);
+		    }
+		 }
+	       else
+		{ /* Reset ? */
+		  attr=A_NORMAL;
+		  wattrset(win,attr);
+		}
+	       ptext--;
+	       break;
+	     }
+	  case '\r':
+	  case '\n':
+	    waddch(win,'\n');
+	    attr=A_NORMAL;
+	    wattrset(win,attr);
+	    print_prefix = TRUE;
+	    break;
+	  default:
+	    waddch(win,*ptext);
+	 } /* end of switch(*ptext) */
+      } /* if not special attribute */
+     ptext++;
+   }
+}
+
diff -Nauwr --exclude Makefile.in --exclude Makefile xchat-1.8.9.orig/src/fe-text/color.h xchat-1.8.9/src/fe-text/color.h
--- xchat-1.8.9.orig/src/fe-text/color.h	Thu Jan  1 01:00:00 1970
+++ xchat-1.8.9/src/fe-text/color.h	Sat Jul 13 21:49:11 2002
@@ -0,0 +1,9 @@
+
+#ifndef _COLOR_H_
+#define _COLOR_H_
+
+void print_color_text(WINDOW *win, const char *prefix, const char *text);
+
+
+#endif /* #ifndef _COLOR_H_ */
+
diff -Nauwr --exclude Makefile.in --exclude Makefile xchat-1.8.9.orig/src/fe-text/fe-text.c xchat-1.8.9/src/fe-text/fe-text.c
--- xchat-1.8.9.orig/src/fe-text/fe-text.c	Thu Apr  4 12:58:46 2002
+++ xchat-1.8.9/src/fe-text/fe-text.c	Sat Jul 13 22:16:44 2002
@@ -32,6 +32,8 @@
 #include "../common/util.h"
 #include "../common/fe.h"
 #include "fe-text.h"
+#include "ui.h"
+#include "color.h"
 
 
 static GSList *tmr_list;		  /* timer list */
@@ -44,39 +46,7 @@
 static void
 send_command (char *cmd)
 {
-	handle_command (cmd, sess_list->data, TRUE, FALSE);
-}
-
-static void
-read_stdin (void)
-{
-	int len, i = 0;
-	static int pos = 0;
-	static char inbuf[1024];
-	char tmpbuf[512];
-
-	len = read (STDIN_FILENO, tmpbuf, sizeof tmpbuf - 1);
-
-	while (i < len)
-	{
-		switch (tmpbuf[i])
-		{
-		case '\r':
-			break;
-
-		case '\n':
-			inbuf[pos] = 0;
-			pos = 0;
-			send_command (inbuf);
-			break;
-
-		default:
-			inbuf[pos] = tmpbuf[i];
-			if (pos < (sizeof inbuf - 2))
-				pos++;
-		}
-		i++;
-	}
+	handle_command (cmd, sess_list->data, FALSE, FALSE);
 }
 
 static int done_intro = 0;
@@ -138,8 +108,8 @@
 	"IPv6"
 #endif
 	"\n\n");
-	fflush (stdout);
-	fflush (stdin);
+//	fflush (stdout);
+//	fflush (stdin);
 }
 
 static int
@@ -148,6 +118,7 @@
 	return strftime (dest, size, prefs.stamp_format, localtime (&tim));
 }
 
+/*
 static int
 timecat (char *buf)
 {
@@ -157,6 +128,7 @@
 	strcat (buf, stampbuf);
 	return strlen (stampbuf);
 }
+*/
 
 /*                       0  1  2  3  4  5  6  7   8   9   10 11  12  13  14 15 */
 static const short colconv[] = { 0, 7, 4, 2, 1, 3, 5, 11, 13, 12, 6, 16, 14, 15, 10, 7 };
@@ -164,162 +136,19 @@
 void
 fe_print_text (struct session *sess, char *text)
 {
-	int dotime = FALSE;
-	char num[8];
-	int reverse = 0, under = 0, bold = 0,
-		comma, k, i = 0, j = 0, len = strlen (text);
-	unsigned char *newtext = malloc (len + 1024);
-
+  char stampbuf[64];
 	if (prefs.timestamp)
 	{
-		newtext[0] = 0;
-		j += timecat (newtext);
-	}
-	while (i < len)
-	{
-		if (dotime && text[i] != 0)
-		{
-			dotime = FALSE;
-			newtext[j] = 0;
-			j += timecat (newtext);
+     time_t t=time(0);
+     strftime (stampbuf, sizeof(stampbuf), "\00314,14[\00303%H:%M:%S\00314]\017", localtime (&t));
+     print_color_text(chatwin,stampbuf,text);
 		}
-		switch (text[i])
-		{
-		case 3:
-			i++;
-			if (!isdigit (text[i]))
-			{
-				newtext[j] = 27;
-				j++;
-				newtext[j] = '[';
-				j++;
-				newtext[j] = 'm';
-				j++;
-				i--;
-				goto jump2;
-			}
-			k = 0;
-			comma = FALSE;
-			while (i < len)
-			{
-				if (text[i] >= '0' && text[i] <= '9' && k < 2)
-				{
-					num[k] = text[i];
-					k++;
-				} else
-				{
-					int col, mirc;
-					num[k] = 0;
-					newtext[j] = 27;
-					j++;
-					newtext[j] = '[';
-					j++;
-					if (k == 0)
-					{
-						newtext[j] = 'm';
-						j++;
-					} else
-					{
-						if (comma)
-							col = 40;
 						else
-							col = 30;
-						mirc = atoi (num);
-						mirc = colconv[mirc];
-						if (mirc > 9)
 						{
-							mirc += 50;
-							sprintf ((char *) &newtext[j], "%dm", mirc + col);
-						} else
-						{
-							sprintf ((char *) &newtext[j], "%dm", mirc + col);
-						}
-						j = strlen (newtext);
-					}
-					switch (text[i])
-					{
-					case ',':
-						comma = TRUE;
-						break;
-					default:
-						goto jump;
-					}
-					k = 0;
+     print_color_text(chatwin,stampbuf,text);
 				}
-				i++;
-			}
-			break;
-		case '\026':				  /* REVERSE */
-			if (reverse)
-			{
-				reverse = FALSE;
-				strcpy (&newtext[j], "\033[27m");
-			} else
-			{
-				reverse = TRUE;
-				strcpy (&newtext[j], "\033[7m");
-			}
-			j = strlen (newtext);
-			break;
-		case '\037':				  /* underline */
-			if (under)
-			{
-				under = FALSE;
-				strcpy (&newtext[j], "\033[24m");
-			} else
-			{
-				under = TRUE;
-				strcpy (&newtext[j], "\033[4m");
-			}
-			j = strlen (newtext);
-			break;
-		case '\002':				  /* bold */
-			if (bold)
-			{
-				bold = FALSE;
-				strcpy (&newtext[j], "\033[22m");
-			} else
-			{
-				bold = TRUE;
-				strcpy (&newtext[j], "\033[1m");
-			}
-			j = strlen (newtext);
-			break;
-		case '\007':
-			if (!prefs.filterbeep)
-			{
-				newtext[j] = text[i];
-				j++;
-			}
-			break;
-		case '\017':				  /* reset all */
-			strcpy (&newtext[j], "\033[m");
-			j += 3;
-			reverse = FALSE;
-			bold = FALSE;
-			under = FALSE;
-			break;
-		case '\t':
-			newtext[j] = ' ';
-			j++;
-			break;
-		case '\n':
-			newtext[j] = '\r';
-			j++;
-			if (prefs.timestamp)
-				dotime = TRUE;
-		default:
-			newtext[j] = text[i];
-			j++;
-		}
-	 jump2:
-		i++;
-	 jump:
-		i += 0;
-	}
-	newtext[j] = 0;
-	write (STDOUT_FILENO, newtext, j);
-	free (newtext);
+
+  wrefresh(chatwin);
 }
 
 void
@@ -429,6 +258,8 @@
 	prefs.autodialog = 0;
 	prefs.lagometer = 0;
 	prefs.skipserverlist = 1;
+
+  win_init(send_command);
 }
 
 void
@@ -484,8 +315,9 @@
 
 		select (FD_SETSIZE, &rd, &wd, &ex, &timeout);
 
+     //read_stdin ();
 		if (FD_ISSET (STDIN_FILENO, &rd))
-			read_stdin ();
+       win_readline();
 
 		/* set all checked flags to false */
 		list = se_list;
@@ -552,6 +384,7 @@
 void
 fe_exit (void)
 {
+  win_close();
 	done = TRUE;
 }
 
@@ -587,6 +420,7 @@
 void
 fe_set_topic (struct session *sess, char *topic)
 {
+  win_update_topic(topic);
 }
 void
 fe_cleanup (void)
@@ -795,3 +629,13 @@
 {
 	return FALSE;
 }
+
+
+
+
+
+
+
+
+
+
diff -Nauwr --exclude Makefile.in --exclude Makefile xchat-1.8.9.orig/src/fe-text/ui.c xchat-1.8.9/src/fe-text/ui.c
--- xchat-1.8.9.orig/src/fe-text/ui.c	Thu Jan  1 01:00:00 1970
+++ xchat-1.8.9/src/fe-text/ui.c	Sat Jul 13 22:33:17 2002
@@ -0,0 +1,253 @@
+
+
+#include <curses.h>
+#include <stdlib.h>
+#include "ui.h"
+#include "color.h"
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#define HAVE_READLINE_READLINE_H
+#define HAVE_READLINE_HISTORY_H
+
+#if defined(HAVE_READLINE_READLINE_H)
+# include <readline/readline.h>
+#elif defined(HAVE_READLINE_H)
+# include <readline.h>
+#else
+# error "You need to have libreadline to compile this file"
+#endif
+
+#if defined(HAVE_READLINE_HISTORY_H)
+# include <readline/history.h>
+#elif defined(HAVE_HISTORY_H)
+# include <history.h>
+#else
+# error "You need to have libreadline to compile this file"
+#endif
+
+/* Global variables */
+
+WINDOW *chatwin;
+WINDOW *statuswin;
+WINDOW *cmdwin;
+
+/* Local global variables */
+static char cmd_prompt[256];
+static int  cmd_prompt_len;
+static void (*send_cmd_callback)(char *);
+
+/* static functions */
+
+static void win_readline_init(void *fct);
+static int win_readline_getc(FILE *dummy);
+static void win_readline_redisplay(void);
+static void win_readline_prompt(void);
+static void win_readline_set_prompt(const char *prompt);
+
+
+
+
+
+static void win_resized(int i)
+{
+  refresh();
+}
+
+
+/**
+ * Create all window needed to display a chat
+ * The screen is split into 3 windows:
+ *   the chat window, the status, the command line
+ *   
+ */
+static void win_create(void)
+{
+  chatwin = newwin(LINES - 2, COLS, 0, 0);
+  scrollok(chatwin,TRUE);
+
+  statuswin = newwin(1, COLS, LINES-2, 0);
+
+  cmdwin = newwin(1, COLS, LINES-1, 0);
+  nodelay(cmdwin,TRUE);
+}
+
+void win_init(void *fct)
+{
+  initscr();
+  cbreak();
+  noecho();
+  nonl();
+  intrflush(stdscr, FALSE);
+  keypad(stdscr, TRUE);
+
+  if (has_colors())
+   {
+     int i;
+     start_color();
+     for (i = 1; i < COLOR_PAIRS; i++)
+	init_pair(i, i % COLORS, i / COLORS);
+   }
+
+#ifdef SIGWINCH
+  signal(SIGWINCH, win_changed);
+#endif
+  
+  win_create();
+
+  win_readline_init(fct);
+}
+
+void win_close(void)
+{
+  rl_callback_handler_remove();
+  clear();
+  refresh();
+  endwin();
+}
+
+
+void win_print_text(WINDOW *win, const char *text)
+{
+  waddstr(win,text);
+  refresh();
+  wrefresh(win);
+}
+
+static void win_readline_callback(char *line)
+{
+  if (!line)
+   {
+     win_print_text(chatwin,"Want to quit ?\n");
+     return;
+   }
+  if (*line)
+   {
+     wprintw(chatwin,"%s\n",line);
+     wrefresh(chatwin);
+     add_history(line);
+     send_cmd_callback(line);
+     win_readline_prompt();
+     wrefresh(cmdwin);
+     free(line);
+
+     win_update_status();
+   }
+}
+
+static int win_readline_getc(FILE *dummy)
+{
+  return wgetch(chatwin);
+}
+
+static void win_readline_init(void *fct)
+{
+  rl_readline_name = "xchat";
+  rl_already_prompted = 1;
+  rl_redisplay_function = win_readline_redisplay;
+//  rl_getc_function = win_readline_getc;
+  rl_callback_handler_install(NULL,win_readline_callback);
+
+//  rl_unbind_function_in_map(rl_clear_screen, rl_get_keymap());
+//  rl_unbind_function_in_map(rl_reverse_search_history, rl_get_keymap());
+
+  rl_bind_key('\t', rl_menu_complete);
+
+  send_cmd_callback=fct;
+
+  win_readline_set_prompt("> ");
+}
+
+static void win_readline_prompt(void)
+{
+  wmove(cmdwin,0,0);
+  wclrtoeol(cmdwin);
+  waddstr(cmdwin,cmd_prompt);
+}
+
+static void win_readline_redisplay(void)
+{
+  int w,y;
+  w=cmd_prompt_len + rl_point;
+  y=0;
+
+  win_readline_prompt();
+  
+  if(w > (COLS - 1))
+   {
+     waddnstr(cmdwin,
+	 rl_line_buffer + (1 + rl_point - COLS),
+	 COLS - cmd_prompt_len - 1);
+   }
+  else
+   {
+     waddnstr(cmdwin, rl_line_buffer, rl_end);
+     wmove(cmdwin,y,w);
+   }
+  wrefresh(cmdwin);
+}
+
+static void win_readline_set_prompt(const char *prompt)
+{
+  if (prompt)
+   {
+     strncpy(cmd_prompt,prompt,sizeof(cmd_prompt));
+     cmd_prompt_len=strlen(cmd_prompt);
+   }
+  else
+   {
+     cmd_prompt[0]=0;
+     cmd_prompt_len=0;
+   }
+
+  win_readline_prompt();
+  wrefresh(cmdwin);
+}
+
+void win_readline(void)
+{
+  /*
+  int c = wgetch(cmdwin);
+  if (c==ERR)
+    return;
+  rl_stuff_char(c);
+  */
+  rl_callback_read_char();
+}
+
+
+
+
+void win_update_topic(const char *topic)
+{
+  win_print_text(statuswin,topic);
+  wclrtoeol(statuswin);
+  //wrefresh(statuswin);
+}
+
+void win_update_status(void)
+{
+//  wbkgdset(statuswin,COLOR_BLUE);
+//  wattron(statuswin,COLOR_WHITE);
+//  print_color_text(statuswin,NULL,"%H:%S [W:xxxx] [Nick +mode] #channel");
+  wmove(statuswin,0,0);
+  win_print_text(statuswin,"%H:%S [W:xxxx] [Nick +mode] #channel");
+  wclrtoeol(statuswin);
+  refresh();
+  wrefresh(statuswin);
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
diff -Nauwr --exclude Makefile.in --exclude Makefile xchat-1.8.9.orig/src/fe-text/ui.h xchat-1.8.9/src/fe-text/ui.h
--- xchat-1.8.9.orig/src/fe-text/ui.h	Thu Jan  1 01:00:00 1970
+++ xchat-1.8.9/src/fe-text/ui.h	Sat Jul 13 21:04:01 2002
@@ -0,0 +1,18 @@
+
+#ifndef _UI_H_
+#define _UI_H_
+
+#include <curses.h>
+
+void win_init(void *fct);
+void win_close(void);
+void win_print_text(WINDOW *win, const char *text);
+void win_readline();
+void win_update_topic(const char *topic);
+
+extern WINDOW *chatwin;
+extern WINDOW *statuswin;
+extern WINDOW *cmdwin;
+
+#endif
+

