Пример #1
0
        public static ANSIString Color(this string String, ConsoleColor color)
        {
            var ret = new ANSIString(String);

            ret.ForegroundColor = color;
            return(ret);
        }
Пример #2
0
        public AutoSplitString(ANSIString String)
        {
            _MaxLength = ConsoleHelper.Size.Width - 1;
            _String    = String;

            ResplitString();
        }
Пример #3
0
        public static void WriteANSIString(ANSIString String, Point?p = null, ConsoleColor?background = null, ConsoleColor?foreground = null)
        {
            CursorChanger cursor = null;

            if (p.HasValue)
            {
                cursor = new CursorChanger(p);
            }

            using (var color = new ColorChanger(background, foreground))
            {
                var oldBack = Console.BackgroundColor;
                var oldFore = Console.ForegroundColor;

                ConsoleColor?lastBack = null, lastFore = null;

                foreach (var ansichar in String as IEnumerable <ANSIString.ANSIChar> )
                {
                    if (lastBack != ansichar.BackgroundColor)
                    {
                        lastBack = ansichar.BackgroundColor;
                        if (lastBack.HasValue)
                        {
                            Console.BackgroundColor = lastBack.Value;
                        }
                        else
                        {
                            Console.BackgroundColor = oldBack;
                        }
                    }
                    if (lastFore != ansichar.ForegroundColor)
                    {
                        lastFore = ansichar.ForegroundColor;
                        if (lastFore.HasValue)
                        {
                            Console.ForegroundColor = lastFore.Value;
                        }
                        else
                        {
                            Console.ForegroundColor = oldFore;
                        }
                    }

                    Console.Write(ansichar.UnicodeChar);
                }
            }

            if (cursor != null)
            {
                cursor.Dispose();
            }
        }
Пример #4
0
        // TODO: Pre-render messages into row-lists, split on \n and width.
        ANSIString RenderMessage(ChatBuffer.MessageData msg)
        {
            if (msg.RenderedMessage == null)
            {
                var build = new ANSIString();

                if (msg.Timestamp.Date == DateTime.Now.Date)
                {
                    build.Append($"[{msg.Timestamp.ToString("HH:mm")}]".Color(ConsoleColor.Gray));
                }
                else
                {
                    build.Append($"[{msg.Timestamp.ToString("yyyy-MM-dd")}]".Color(ConsoleColor.Gray));
                }

                ANSIString message = new ANSIRenderer().Render(msg.RawMessage);
                bool       action  = message.PlainString.StartsWith("/me", StringComparison.CurrentCultureIgnoreCase);
                build.Append(action ? "*" : " ");

                if (msg.Sender?.Name != null)
                {
                    build.Append(msg.Sender.ToANSIString(Channel, true));
                }
                else
                {
                    build.Append("System".Color(ConsoleColor.DarkGray));
                }

                if (action)
                {
                    if (message.PlainString.StartsWith("/me's", StringComparison.CurrentCultureIgnoreCase))
                    {
                        build.Append(message.Substring(3));
                    }
                    else
                    {
                        build.Append(new ANSIString(" ") + message.Substring(4));
                    }
                }
                else
                {
                    build.Append(new ANSIString(": ") + message);
                }

                msg.RenderedMessage = build;
            }

            return(msg.RenderedMessage);
        }
Пример #5
0
        public void Call()
        {
            var buf = Application.CurrentChannelBuffer.ChatBuf;

            if (buf is ConsoleChatBuffer)
            {
                Debug.WriteLine("No users in console");
            }
            else if (buf is CharacterChatBuffer)
            {
                buf.PushMessage(null, (buf as CharacterChatBuffer).Character.Name, MessageType.Preview);
            }
            else
            {
                var chan = (buf as ChannelChatBuffer).Channel;
                buf.PushMessage(null, $"{chan.Characters.Count} characters in {chan.Title}:", MessageType.Preview);
                buf.PushMessage(null, ANSIString.Join(", ", chan.Characters.OrderBy(c => c.ToSortable(chan)).Select(c => c.ToANSIString(chan, true))).ToBBCode(), MessageType.Preview);
            }
        }
Пример #6
0
 public override string ToString()
 {
     return(ANSIString.Join("\n", _SplitString).PlainString);
 }
Пример #7
0
 public ANSIString ToANSIString()
 {
     return(ANSIString.Join("\n", _SplitString));
 }