From f4eee05ce694b4d86676c1e7a9743d75a47232c4 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Fri, 13 Dec 2019 20:59:46 +0100 Subject: [PATCH] emoji refactor --- telegram/Command.cs | 1 + telegram/Util.cs | 29 +++++++++++++++++------------ telegram/tgcli.cs | 1 - 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/telegram/Command.cs b/telegram/Command.cs index 296fb48..64c6309 100644 --- a/telegram/Command.cs +++ b/telegram/Command.cs @@ -545,6 +545,7 @@ namespace telegram if (inputParams.Count == 0) { currentInputLine = "/e " + ((TdApi.MessageContent.MessageText) lastMessage?.Content)?.Text?.Text; + Emojis.ForEach(em => currentInputLine = currentInputLine.Replace(em.Item2, em.Item1)); return; } diff --git a/telegram/Util.cs b/telegram/Util.cs index e649751..00eb3bd 100644 --- a/telegram/Util.cs +++ b/telegram/Util.cs @@ -194,10 +194,7 @@ namespace telegram public static void ClearCurrentConsoleLine() { - do - { - Console.Write("\b \b"); - } while (Console.CursorLeft > 0); + Console.Write("\u001b[2K\r"); //TODO is there a better solution? //Console.SetCursorPosition(0, Console.WindowHeight); @@ -238,14 +235,7 @@ namespace telegram { if (string.IsNullOrWhiteSpace(message)) return; - message = message.Replace("⏎", "\n") - .Replace(":xd:", Emoji.FaceWithTearsOfJoy.Sequence.AsString) - .Replace(":check:", Emoji.WhiteHeavyCheckMark.Sequence.AsString) - .Replace(":thinking:", Emoji.ThinkingFace.Sequence.AsString) - .Replace(":heart:", Emoji.RedHeart.Sequence.AsString) - .Replace(":shrug:", Emoji.PersonShrugging.Sequence.AsString) - .Replace(":shrugf:", Emoji.WomanShrugging.Sequence.AsString) - .Replace(":shrugm:", Emoji.ManShrugging.Sequence.AsString); + Emojis.ForEach(em => message = message.Replace(em.Item1, em.Item2)); client.ExecuteAsync(new SendMessage { ChatId = chatId, @@ -263,6 +253,8 @@ namespace telegram public static Message EditMessage(string newText, Message message) { + Emojis.ForEach(em => newText = newText.Replace(em.Item1, em.Item2)); + var msg = client.ExecuteAsync(new EditMessageText { ChatId = message.ChatId, @@ -403,6 +395,19 @@ namespace telegram return input.Length <= maxLen ? input : "<" + input.Substring(input.Length - maxLen + 1); } + public static readonly List> Emojis = new List> + { + new Tuple("⏎", "\n"), + new Tuple(":xd:", Emoji.FaceWithTearsOfJoy.Sequence.AsString), + new Tuple(":check:", Emoji.WhiteHeavyCheckMark.Sequence.AsString), + new Tuple(":thinking:", Emoji.ThinkingFace.Sequence.AsString), + new Tuple(":eyes:", Emoji.Eyes.Sequence.AsString), + new Tuple(":heart:", Emoji.RedHeart.Sequence.AsString), + new Tuple(":shrug:", Emoji.PersonShrugging.Sequence.AsString), + new Tuple(":shrugf:", Emoji.WomanShrugging.Sequence.AsString), + new Tuple(":shrugm:", Emoji.ManShrugging.Sequence.AsString) + }; + public static readonly List SpecialKeys = new List { ConsoleKey.Backspace, diff --git a/telegram/tgcli.cs b/telegram/tgcli.cs index f1fcd1e..45e458e 100644 --- a/telegram/tgcli.cs +++ b/telegram/tgcli.cs @@ -14,7 +14,6 @@ namespace telegram { /* * TODO: - * replace emoji on send & un-replace on edit, two-way dictionary!! * waaay more error messages instead of just doing nothing or crashing (search for "do something") * add option to disable terminal bell * make commands & keybinds more consistent (maybe configurable?)