From ff8cba68ab22e681b25dbc174baad2673b6e8370 Mon Sep 17 00:00:00 2001 From: Daniel Herrmann Date: Thu, 27 Mar 2014 12:07:02 +0100 Subject: [PATCH] Terminal Klasse entfernt --- Program.cs | 8 ++--- Terminal.cs | 101 ---------------------------------------------------- 2 files changed, 3 insertions(+), 106 deletions(-) delete mode 100644 Terminal.cs diff --git a/Program.cs b/Program.cs index a177381..6491687 100644 --- a/Program.cs +++ b/Program.cs @@ -1,9 +1,9 @@ using System.Net.Sockets; using System.Threading; +using System; public class Program { - private Terminal Term; private Receiver Rec; private Sender Send; private Thread SenderThread; @@ -17,7 +17,6 @@ public class Program public Program () { - Term = new Terminal (); TcpClient client = new TcpClient ("localhost", 9999); Rec = new Receiver (client); Send = new Sender (client); @@ -36,16 +35,15 @@ public class Program string line; while ((line = Rec.Receive()) != null) { - Term.PrintLine(line); + Console.WriteLine(line); } SenderThread.Abort(); - Term.Close(); } public void doSend () { while (true) { - Send.Send(Term.ReadLine()); + Send.Send(Console.ReadLine()); } } diff --git a/Terminal.cs b/Terminal.cs deleted file mode 100644 index 5846f1c..0000000 --- a/Terminal.cs +++ /dev/null @@ -1,101 +0,0 @@ -using System; -using System.Threading; - -// Wrapper class for the console allowing concurrent read and write operations -public class Terminal -{ - private Object TerminalLock = new Object (); - private Object ReadLineLock = new Object (); - private AutoResetEvent ResetEvent = new AutoResetEvent (false); - private String InputBuffer = ""; - private bool AcceptInput = false; - private int OutLinePos; - private Thread catchInputThread; - - public Terminal () - { - OutLinePos = Console.CursorTop; - catchInputThread = new Thread (new ThreadStart (this.CatchInput)); - catchInputThread.Start (); - } - - private void CatchInput () - { - while (true) { - ConsoleKeyInfo key = Console.ReadKey (false); - lock (TerminalLock) { - if (!AcceptInput) { - Console.CursorLeft--; - Console.Write (" "); - Console.CursorLeft--; - continue; - } - if (key.Key == ConsoleKey.Backspace) { - if (InputBuffer.Length == 0) - continue; - InputBuffer = InputBuffer.Substring (0, InputBuffer.Length - 1); - ClearInputLine (); - Console.Write (InputBuffer); - } else if (key.Key == ConsoleKey.Enter) { - AcceptInput = false; - ResetEvent.Set (); - OutLinePos = Console.CursorTop; - } else { - InputBuffer += key.KeyChar; - ClearInputLine (); - Console.Write (InputBuffer); - } - } - } - } - - public void PrintLine (String s) - { - lock (TerminalLock) { - ClearInputLine (); - Console.WriteLine (s); - OutLinePos = Console.CursorTop; - Console.Write (InputBuffer); - } - } - - public String ReadLine () - { - lock (ReadLineLock) { - try { - String result; - AcceptInput = true; - ResetEvent.WaitOne (); - result = InputBuffer; - InputBuffer = ""; - return result; - } catch (ThreadAbortException e) { - lock (TerminalLock) { - AcceptInput = false; - InputBuffer = ""; - ClearInputLine (); - } - throw e; - } - } - } - - public void ClearInputLine () - { - lock (TerminalLock) { - int top = Console.CursorTop; - int left = Console.CursorLeft; - Console.SetCursorPosition (0, OutLinePos); - while (left != Console.CursorLeft || top != Console.CursorTop) { - Console.Write (" "); - } - Console.SetCursorPosition (0, OutLinePos); - } - } - - public void Close () - { - catchInputThread.Abort(); - } -} -