Index: client/Client/main.cpp
===================================================================
--- client/Client/main.cpp	(revision 9a3e6b166fac0f317e650d6c558d94c60ef9600e)
+++ client/Client/main.cpp	(revision 2488852e451359e9522acfbd77cbb1c85fc0f292)
@@ -26,6 +26,8 @@
 #include "../../common/message.h"
 
+#include "chat.h"
+
 #ifdef WINDOWS
-	#pragma comment(lib, "ws2_32.lib")
+   #pragma comment(lib, "ws2_32.lib")
 #endif
 
@@ -56,7 +58,5 @@
    bool doexit = false;
 
-   vector<string> vctChat;
-   string strPrompt;
-   string strEnteredInput;
+   chat chatConsole;
 
    if(!al_init()) {
@@ -161,5 +161,5 @@
       error("receiveMessage");
 	
-   vctChat.push_back(string(msgFrom.buffer));
+   chatConsole.addLine(msgFrom.buffer);
 
    al_start_timer(timer);
@@ -193,56 +193,42 @@
       }
       else if(ev.type == ALLEGRO_EVENT_KEY_DOWN) {
-         switch(ev.keyboard.keycode) {
-            case ALLEGRO_KEY_UP:
-               key[KEY_UP] = true;
-               break;
- 
-            case ALLEGRO_KEY_DOWN:
-               key[KEY_DOWN] = true;
-               break;
- 
-            case ALLEGRO_KEY_LEFT: 
-               key[KEY_LEFT] = true;
-               break;
- 
-            case ALLEGRO_KEY_RIGHT:
-               key[KEY_RIGHT] = true;
-               break;
-
-			case ALLEGRO_KEY_ENTER:
-			   strEnteredInput = strPrompt;
-			   strPrompt.clear();
-
-			   if (strEnteredInput.compare("q") == 0) {
-			      doexit = true;
-		       }
-			   else
-			   {
-                  strcpy(msgTo.buffer, strEnteredInput.c_str());
-		          n=sendMessage(&msgTo, sock, &server);
-		          if (n < 0)
-			         error("sendMessage");
-
-		          n = receiveMessage(&msgFrom, sock, &from);
-		          if (n < 0)
-			         error("receiveMessage");
-
-		          vctChat.push_back(string(msgFrom.buffer));
-			   }
-
-			   break;
-         }
-
-		 if(ALLEGRO_KEY_A <= ev.keyboard.keycode && ev.keyboard.keycode <= ALLEGRO_KEY_Z)
-		 {
-            char newChar = 'a'+ev.keyboard.keycode-ALLEGRO_KEY_A;
-            strPrompt.append(1, newChar);
-		 }
-
-		 if(ALLEGRO_KEY_0 <= ev.keyboard.keycode && ev.keyboard.keycode <= ALLEGRO_KEY_9)
-		 {
-            char newChar = '0'+ev.keyboard.keycode-ALLEGRO_KEY_0;
-            strPrompt.append(1, newChar);
-		 }
+         bool eventConsumed = chatConsole.processEvent(ev);
+
+         if (eventConsumed) {
+            string input = chatConsole.getInput();
+            if (!input.empty()) {
+               cout << "input: " << input << endl;
+               strcpy(msgTo.buffer, input.c_str());
+               
+               n=sendMessage(&msgTo, sock, &server);
+               if (n < 0)
+                  error("sendMessage");
+
+               n = receiveMessage(&msgFrom, sock, &from);
+               if (n < 0)
+                  error("receiveMessage");
+
+               chatConsole.addLine(string(msgFrom.buffer));
+               cout << "Added new line" << endl;
+            }
+         }else {
+            switch(ev.keyboard.keycode) {
+               case ALLEGRO_KEY_UP:
+                  key[KEY_UP] = true;
+                  break;
+ 
+               case ALLEGRO_KEY_DOWN:
+                  key[KEY_DOWN] = true;
+                  break;
+ 
+               case ALLEGRO_KEY_LEFT: 
+                  key[KEY_LEFT] = true;
+                  break;
+ 
+               case ALLEGRO_KEY_RIGHT:
+                  key[KEY_RIGHT] = true;
+                  break;
+            }
+         }
       }
       else if(ev.type == ALLEGRO_EVENT_KEY_UP) {
@@ -277,9 +263,6 @@
          al_draw_bitmap(bouncer, bouncer_x, bouncer_y, 0);
 
-		 for(int x=0; x<vctChat.size(); x++)
-            al_draw_text(font, al_map_rgb(255,255,255), 10, 10+x*15, ALLEGRO_ALIGN_LEFT, vctChat[x].c_str());
-
-		 al_draw_text(font, al_map_rgb(255,255,255), 10, 460, ALLEGRO_ALIGN_LEFT, strPrompt.c_str());
-         
+         chatConsole.draw(font, al_map_rgb(255,255,255));
+
          al_flip_display();
       }
