Fixed Multiline entry and written Multiline output
This commit is contained in:
parent
da0def2486
commit
43675af036
|
@ -29,18 +29,19 @@ namespace cce {
|
||||||
CursorVisible = false;
|
CursorVisible = false;
|
||||||
var entry = new List<string>();
|
var entry = new List<string>();
|
||||||
if ((new int[] {1,2}).Contains(choice)) {
|
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;
|
CursorVisible = true;
|
||||||
//Write("Please enter the sentence: ");
|
//Write("Please enter the sentence: ");
|
||||||
entry = Utils.Entry();
|
entry = Utils.Entry();
|
||||||
CursorVisible = false;
|
CursorVisible = false;
|
||||||
}
|
}
|
||||||
bool skip = 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 == 2) Transcoder.Decode(entry);
|
||||||
else if (choice == 5) Transcoder.Teacher();
|
else if (choice == 5) Transcoder.Teacher();
|
||||||
else if (choice == 8) skip = App.Settings();
|
else if (choice == 8) skip = App.Settings();
|
||||||
else if (choice == 9) App.Dev();
|
else if (choice == 9) App.Dev();
|
||||||
|
else if (choice == 253) { Clear(); continue; }
|
||||||
else if (choice == 254) Help();
|
else if (choice == 254) Help();
|
||||||
else if (choice == 255) { Beep(4000, 200); return; }
|
else if (choice == 255) { Beep(4000, 200); return; }
|
||||||
|
|
||||||
|
@ -62,6 +63,7 @@ namespace cce {
|
||||||
+"\n-------------------------"
|
+"\n-------------------------"
|
||||||
+"\n[8] Settings"
|
+"\n[8] Settings"
|
||||||
+"\n[9] DEV"
|
+"\n[9] DEV"
|
||||||
|
+"\n[c] Clear Console"
|
||||||
+"\n[?] Help"
|
+"\n[?] Help"
|
||||||
+"\n[Backspace] Exit"
|
+"\n[Backspace] Exit"
|
||||||
+"\n>>> ");
|
+"\n>>> ");
|
||||||
|
@ -91,6 +93,10 @@ namespace cce {
|
||||||
case ',':
|
case ',':
|
||||||
if ((new char[] { '?','/','-',','}).Contains(choice.KeyChar)) return 254;
|
if ((new char[] { '?','/','-',','}).Contains(choice.KeyChar)) return 254;
|
||||||
return byte.Parse(choice.KeyChar.ToString());
|
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:
|
default:
|
||||||
WriteLine("Not a valid option");
|
WriteLine("Not a valid option");
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -108,12 +108,47 @@ namespace cce {
|
||||||
WriteLine("Translation Added"); ResetColor();
|
WriteLine("Translation Added"); ResetColor();
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
static internal void Encode(string entry) {
|
static internal void Encode(List<string> entry, out string encrypted) {
|
||||||
result = raw_encode(entry);
|
var temp = new List<string>();
|
||||||
WriteLine("Transcoding:\n{0}\n", entry);
|
WriteLine("Transcoding:\n{0}\n", String.Join("\n", entry));
|
||||||
Utils.LagWrite(result);
|
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<string> 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<string, List<string>>();
|
||||||
|
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();
|
var sentence = entry.ToLower();
|
||||||
//120x30, buffer 240x60
|
//120x30, buffer 240x60
|
||||||
if (sentence.Length >= 120) { BufferWidth = sentence.Length * 2; WindowWidth = sentence.Length + 20; }
|
if (sentence.Length >= 120) { BufferWidth = sentence.Length * 2; WindowWidth = sentence.Length + 20; }
|
||||||
|
@ -159,7 +194,8 @@ namespace cce {
|
||||||
letterlist.Add(substituted[h]);
|
letterlist.Add(substituted[h]);
|
||||||
}
|
}
|
||||||
letter_decode.Add(letterlist);
|
letter_decode.Add(letterlist);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
letter_decode.Add(new List<char> { sentence[j] });
|
letter_decode.Add(new List<char> { sentence[j] });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -183,23 +219,6 @@ namespace cce {
|
||||||
ResetColor();
|
ResetColor();
|
||||||
//return string.Join(" ", decoded);
|
//return string.Join(" ", decoded);
|
||||||
}
|
}
|
||||||
static private void update() {
|
|
||||||
uniquere();
|
|
||||||
var dict = new Dictionary<string, List<string>>();
|
|
||||||
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() {
|
static internal bool init() {
|
||||||
if (common_dict != null && extended_dict != null) return true;
|
if (common_dict != null && extended_dict != null) return true;
|
||||||
var checker = true;
|
var checker = true;
|
||||||
|
|
33
cce/Utils.cs
33
cce/Utils.cs
|
@ -61,11 +61,38 @@ namespace cce {
|
||||||
}
|
}
|
||||||
static internal List<string> Entry() {
|
static internal List<string> Entry() {
|
||||||
var list = new List<string>();
|
var list = new List<string>();
|
||||||
ConsoleKeyInfo cki;
|
ConsoleKeyInfo input = new ConsoleKeyInfo();
|
||||||
|
bool exit = false;
|
||||||
do {
|
do {
|
||||||
cki = ReadKey();
|
List<char> chars = new List<char>();
|
||||||
} while (cki.Key == ConsoleKey.Enter && cki.Modifiers != ConsoleModifiers.Shift);
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue