Esempio n. 1
0
        public void ScrollToEnd()
        {
            Trace.Call();

            MessageTextView.ScrollToEnd();
        }
Esempio n. 2
0
        public virtual void AddMessage(MessageModel msg)
        {
            // OPT: typical message length
            var line      = new StringBuilder(512);
            int msgLength = 0;

            switch (msg.MessageType)
            {
            case MessageType.Normal:
                HasMessage = true;
                break;

            case MessageType.Event:
                HasEvent = true;
                break;
            }
            bool hasHighlight = false;

            foreach (MessagePartModel msgPart in msg.MessageParts)
            {
                if (msgPart.IsHighlight)
                {
                    HasHighlight = true;
                }
                // TODO: implement other types
                if (msgPart is UrlMessagePartModel)
                {
                    var urlPart    = (UrlMessagePartModel)msgPart;
                    var escapedUrl = StflApi.EscapeRichText(urlPart.Url);
                    line.Append(String.Format("<url>{0}</url>", escapedUrl));
                    msgLength += urlPart.Url.Length;
                }
                else if (msgPart is TextMessagePartModel)
                {
                    var txtPart = (TextMessagePartModel)msgPart;
                    if (String.IsNullOrEmpty(txtPart.Text))
                    {
                        continue;
                    }

                    var tags = new List <string>();
                    if (txtPart.ForegroundColor != TextColor.None)
                    {
                        var palette = TextColorPalettes.LinuxConsole;
                        var color   = TextColorTools.GetNearestColor(
                            txtPart.ForegroundColor,
                            palette
                            );
                        var colorNumber = palette.IndexOf(color);
                        tags.Add(String.Format("color{0}", colorNumber));
                    }
                    // HACK: STFL doesn't support applying multiple styles at
                    // the same time and thus simply overwrites any previous
                    // style. As a workaround we only apply one style with the
                    // highest priority in this order:
                    // color >> underline >> bold >> italic
                    if (txtPart.Underline && tags.Count == 0)
                    {
                        tags.Add("u");
                    }
                    if (txtPart.Bold && tags.Count == 0)
                    {
                        tags.Add("b");
                    }
                    if (txtPart.Italic && tags.Count == 0)
                    {
                        tags.Add("i");
                    }

                    string escapedText = StflApi.EscapeRichText(txtPart.Text);
                    if (tags.Count > 0)
                    {
                        tags.Reverse();
                        string markup = escapedText;
                        foreach (string tag in tags)
                        {
                            markup = String.Format("<{0}>{1}</{2}>",
                                                   tag, markup, tag);
                        }
                        line.Append(markup);
                    }
                    else
                    {
                        line.Append(escapedText);
                    }
                    msgLength += txtPart.Text.Length;
                }
            }

            string timestamp;

            try {
                timestamp = msg.TimeStamp.ToLocalTime().ToString((string)Frontend.UserConfig["Interface/Notebook/TimestampFormat"]);
            } catch (FormatException e) {
                timestamp = "Timestamp Format ERROR: " + e.Message;
            }
            var finalMsg = String.Format("{0} {1}", timestamp, line.ToString());

            MessageTextView.AppendLine(finalMsg);

            ScrollToEnd();
        }
Esempio n. 3
0
        public void ScrollDown()
        {
            Trace.Call();

            MessageTextView.ScrollDown();
        }