Search in sources :

Example 6 with PreElement

use of com.google.gwt.dom.client.PreElement in project che by eclipse.

the class OutputConsoleViewImpl method print.

@Override
public void print(final String text, boolean carriageReturn, String color) {
    if (this.carriageReturn) {
        Node lastChild = consoleLines.getElement().getLastChild();
        if (lastChild != null) {
            lastChild.removeFromParent();
        }
    }
    this.carriageReturn = carriageReturn;
    final SafeHtml colorOutput = new SafeHtml() {

        @Override
        public String asString() {
            if (Strings.isNullOrEmpty(text)) {
                return " ";
            }
            for (final Pair<RegExp, String> pair : output2Color) {
                final MatchResult matcher = pair.first.exec(text);
                if (matcher != null) {
                    return text.replaceAll(matcher.getGroup(1), "<span style=\"color: " + pair.second + "\">" + matcher.getGroup(1) + "</span>");
                }
            }
            return text;
        }
    };
    PreElement pre = DOM.createElement("pre").cast();
    pre.setInnerSafeHtml(colorOutput);
    if (color != null) {
        pre.getStyle().setColor(color);
    }
    consoleLines.getElement().appendChild(pre);
    followOutput();
}
Also used : RegExp(com.google.gwt.regexp.shared.RegExp) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) PreElement(com.google.gwt.dom.client.PreElement) Node(com.google.gwt.dom.client.Node) MatchResult(com.google.gwt.regexp.shared.MatchResult)

Example 7 with PreElement

use of com.google.gwt.dom.client.PreElement in project rstudio by rstudio.

the class DomUtilsTests method testTrimExcess.

public void testTrimExcess() {
    PreElement pre = Document.get().createPreElement();
    pre.setInnerText("Line1\nLine2\nLine3\n");
    int trimmed = DomUtils.trimLines(pre, 2);
    Assert.assertEquals("Line3\n", pre.getInnerText());
    Assert.assertEquals(trimmed, 2);
}
Also used : PreElement(com.google.gwt.dom.client.PreElement)

Example 8 with PreElement

use of com.google.gwt.dom.client.PreElement in project rstudio by rstudio.

the class VirtualConsoleTests method testColorSplit.

public void testColorSplit() {
    PreElement ele = Document.get().createPreElement();
    VirtualConsole vc = new VirtualConsole(ele);
    vc.submit("123456");
    vc.submit("\b\b\b\bXX", "X");
    Assert.assertEquals("<span>12</span>" + "<span class=\"X\">XX</span>" + "<span>56</span>", ele.getInnerHTML());
}
Also used : VirtualConsole(org.rstudio.core.client.VirtualConsole) PreElement(com.google.gwt.dom.client.PreElement)

Example 9 with PreElement

use of com.google.gwt.dom.client.PreElement in project rstudio by rstudio.

the class VirtualConsoleTests method testTwoColors.

public void testTwoColors() {
    PreElement ele = Document.get().createPreElement();
    VirtualConsole vc = new VirtualConsole(ele);
    vc.submit("Output 1", "one");
    vc.submit("Output 2", "two");
    Assert.assertEquals("<span class=\"one\">Output 1</span>" + "<span class=\"two\">Output 2</span>", ele.getInnerHTML());
}
Also used : VirtualConsole(org.rstudio.core.client.VirtualConsole) PreElement(com.google.gwt.dom.client.PreElement)

Example 10 with PreElement

use of com.google.gwt.dom.client.PreElement in project rstudio by rstudio.

the class VirtualConsoleTests method testColorOverlap.

public void testColorOverlap() {
    PreElement ele = Document.get().createPreElement();
    VirtualConsole vc = new VirtualConsole(ele);
    vc.submit("123", "A");
    vc.submit("456", "B");
    vc.submit("\b\b\b\bXX", "X");
    Assert.assertEquals("<span class=\"A\">12</span>" + "<span class=\"X\">XX</span>" + "<span class=\"B\">56</span>", ele.getInnerHTML());
}
Also used : VirtualConsole(org.rstudio.core.client.VirtualConsole) PreElement(com.google.gwt.dom.client.PreElement)

Aggregations

PreElement (com.google.gwt.dom.client.PreElement)11 VirtualConsole (org.rstudio.core.client.VirtualConsole)6 Node (com.google.gwt.dom.client.Node)1 SpanElement (com.google.gwt.dom.client.SpanElement)1 MatchResult (com.google.gwt.regexp.shared.MatchResult)1 RegExp (com.google.gwt.regexp.shared.RegExp)1 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)1