diff --git a/cce/Program.cs b/cce/Program.cs index 9f38c0c..20b15ad 100644 --- a/cce/Program.cs +++ b/cce/Program.cs @@ -29,18 +29,19 @@ namespace cce { CursorVisible = false; var entry = new List(); if ((new int[] {1,2}).Contains(choice)) { - Utils.LagWrite("Please enter the sentence (Enter to submit, Shift+Enter for another line: "); + Utils.LagWrite("Please enter the sentence (Enter to submit, Ctrl+Enter for another line):", true); CursorVisible = true; //Write("Please enter the sentence: "); entry = Utils.Entry(); CursorVisible = false; } bool skip = false; - if (choice == 1) { Transcoder.Encode(entry); Utils.Clip(Transcoder.result); } + if (choice == 1) { Transcoder.Encode(entry, out string enc); Utils.Clip(enc); } else if (choice == 2) Transcoder.Decode(entry); else if (choice == 5) Transcoder.Teacher(); else if (choice == 8) skip = App.Settings(); else if (choice == 9) App.Dev(); + else if (choice == 253) { Clear(); continue; } else if (choice == 254) Help(); else if (choice == 255) { Beep(4000, 200); return; } @@ -62,6 +63,7 @@ namespace cce { +"\n-------------------------" +"\n[8] Settings" +"\n[9] DEV" ++"\n[c] Clear Console" +"\n[?] Help" +"\n[Backspace] Exit" +"\n>>> "); @@ -91,6 +93,10 @@ namespace cce { case ',': if ((new char[] { '?','/','-',','}).Contains(choice.KeyChar)) return 254; return byte.Parse(choice.KeyChar.ToString()); + case 'c': + case 'C': + if ((new char[] { 'c', 'C' }).Contains(choice.KeyChar)) return 253; + return byte.Parse(choice.KeyChar.ToString()); default: WriteLine("Not a valid option"); break; diff --git a/cce/Transcoder.cs b/cce/Transcoder.cs index 0483d7a..f05f2b0 100644 --- a/cce/Transcoder.cs +++ b/cce/Transcoder.cs @@ -108,12 +108,47 @@ namespace cce { WriteLine("Translation Added"); ResetColor(); update(); } - static internal void Encode(string entry) { - result = raw_encode(entry); - WriteLine("Transcoding:\n{0}\n", entry); - Utils.LagWrite(result); + static internal void Encode(List entry, out string encrypted) { + var temp = new List(); + WriteLine("Transcoding:\n{0}\n", String.Join("\n", entry)); + for (int i = 0; i < entry.Count; i++) { + result = raw_encode(entry[i]); + Utils.LagWrite(result); + temp.Add(result); + if(entry.Count>1) WriteLine(); + } + encrypted = String.Join("\n", temp); } - static internal void Decode(string entry) { + static internal void Decode(List lines) { + for (int i = 0; i < lines.Count; i++) { + raw_decode(lines[i]); + if (lines.Count <= 1 || i == lines.Count-1) break; + SetCursorPosition(0, WindowHeight - 2); + Write("Press Enter to write the next line"); + while (true) { + var cki = ReadKey(); + if (cki.Key == ConsoleKey.Enter) break; + } + } + } + static private void update() { + uniquere(); + var dict = new Dictionary>(); + File.WriteAllText(AppSettings.Dictionary, JsonConvert.SerializeObject(dict)); + } + static private string raw_encode(string entry) { + var sentence = entry.ToLower(); + char[] encoded = new char[entry.Length]; + for (int i = 0; i < sentence.Length; i++) { + if (substitution.TryGetValue(sentence[i], out char substituted)) { + encoded[i] = Char.IsUpper(entry[i]) ? Char.ToUpper(substituted) : Char.ToLower(substituted); + } else { + encoded[i] = entry[i]; + } + } + return String.Join("", encoded); + } + static private void raw_decode(string entry) { var sentence = entry.ToLower(); //120x30, buffer 240x60 if (sentence.Length >= 120) { BufferWidth = sentence.Length * 2; WindowWidth = sentence.Length + 20; } @@ -159,7 +194,8 @@ namespace cce { letterlist.Add(substituted[h]); } letter_decode.Add(letterlist); - } else { + } + else { letter_decode.Add(new List { sentence[j] }); } } @@ -183,23 +219,6 @@ namespace cce { ResetColor(); //return string.Join(" ", decoded); } - static private void update() { - uniquere(); - var dict = new Dictionary>(); - File.WriteAllText(AppSettings.Dictionary, JsonConvert.SerializeObject(dict)); - } - static private string raw_encode(string entry) { - var sentence = entry.ToLower(); - char[] encoded = new char[entry.Length]; - for (int i = 0; i < sentence.Length; i++) { - if (substitution.TryGetValue(sentence[i], out char substituted)) { - encoded[i] = Char.IsUpper(entry[i]) ? Char.ToUpper(substituted) : Char.ToLower(substituted); - } else { - encoded[i] = entry[i]; - } - } - return String.Join("", encoded); - } static internal bool init() { if (common_dict != null && extended_dict != null) return true; var checker = true; diff --git a/cce/Utils.cs b/cce/Utils.cs index 24ce0b3..d1169bf 100644 --- a/cce/Utils.cs +++ b/cce/Utils.cs @@ -61,11 +61,38 @@ namespace cce { } static internal List Entry() { var list = new List(); - ConsoleKeyInfo cki; + ConsoleKeyInfo input = new ConsoleKeyInfo(); + bool exit = false; do { - cki = ReadKey(); - } while (cki.Key == ConsoleKey.Enter && cki.Modifiers != ConsoleModifiers.Shift); + List chars = new List(); + exit = false; + for (int i = 0; i < 30; i++) { + input = ReadKey(); + if (chars.Count > 0 && input.Key == ConsoleKey.Enter && input.Modifiers == ConsoleModifiers.Control) { + list.Add(String.Join("", chars)); + break; + } + else if (i > 20 && input.Key == ConsoleKey.Spacebar || i > 29) { + list.Add(String.Join("", chars)); + WriteLine(); + break; + } + else if (chars.Count > 0 && input.Key == ConsoleKey.Enter && input.Modifiers == 0) { + list.Add(String.Join("", chars)); + exit = true; + break; + } + else if (input.Key == ConsoleKey.Backspace) { + chars.RemoveAt(chars.Count-1); + if (CursorLeft >0) { + Write(" "); CursorLeft--; + } + } + else chars.Add(input.KeyChar); + } + } while (!exit); + return list; } } }