Fixed Multiline entry and written Multiline output

This commit is contained in:
Helio 2022-04-26 15:56:42 +02:00
parent da0def2486
commit 43675af036
3 changed files with 80 additions and 28 deletions

View file

@ -29,18 +29,19 @@ namespace cce {
CursorVisible = false;
var entry = new List<string>();
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;

View file

@ -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);
static internal void Encode(List<string> entry, out string encrypted) {
var temp = new List<string>();
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();
}
static internal void Decode(string entry) {
encrypted = String.Join("\n", temp);
}
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();
//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<char> { sentence[j] });
}
}
@ -183,23 +219,6 @@ namespace cce {
ResetColor();
//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() {
if (common_dict != null && extended_dict != null) return true;
var checker = true;

View file

@ -61,11 +61,38 @@ namespace cce {
}
static internal List<string> Entry() {
var list = new List<string>();
ConsoleKeyInfo cki;
ConsoleKeyInfo input = new ConsoleKeyInfo();
bool exit = false;
do {
cki = ReadKey();
} while (cki.Key == ConsoleKey.Enter && cki.Modifiers != ConsoleModifiers.Shift);
List<char> chars = new List<char>();
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;
}
}
}