diff --git a/org.uqbar.project.wollok.launch/src/org/uqbar/project/wollok/launch/repl/ReplOutputFormatter.xtend b/org.uqbar.project.wollok.launch/src/org/uqbar/project/wollok/launch/repl/ReplOutputFormatter.xtend index a682adbb35..9266b4e32f 100644 --- a/org.uqbar.project.wollok.launch/src/org/uqbar/project/wollok/launch/repl/ReplOutputFormatter.xtend +++ b/org.uqbar.project.wollok.launch/src/org/uqbar/project/wollok/launch/repl/ReplOutputFormatter.xtend @@ -1,13 +1,17 @@ package org.uqbar.project.wollok.launch.repl +import org.fusesource.jansi.Ansi +import org.fusesource.jansi.AnsiConsole + import static org.fusesource.jansi.Ansi.* import static org.fusesource.jansi.Ansi.Color.* -import org.fusesource.jansi.Ansi /** * An strategy to allow ANSI colors output * or regular output without special characters * + * https://github.com/fusesource/jansi + * * @author jfernandes */ interface ReplOutputFormatter { @@ -40,6 +44,9 @@ class AnsiColoredReplOutputFormatter implements ReplOutputFormatter { override def importantMessageStyle(CharSequence msg) { ansi.fg(COLOR_REPL_MESSAGE).bold.a(msg).reset.toString() } override def messageStyle(CharSequence msg) { ansi.fg(COLOR_REPL_MESSAGE).a(msg).reset.toString() } override def returnStyle(CharSequence msg) { ansi().fg(COLOR_RETURN_VALUE).a(msg).reset.toString() } - override def linkStyle(CharSequence msg) { ansi.fg(COLOR_LINK_FILE).a(Ansi.Attribute.UNDERLINE).boldOff.a(msg).reset.a(Ansi.Attribute.UNDERLINE_OFF).bold.a("").toString() } + override def linkStyle(CharSequence msg) { + // https://mihai-nita.net/2013/06/03/eclipse-plugin-ansi-in-console/ + ansi.fg(COLOR_LINK_FILE).a(Ansi.Attribute.UNDERLINE).boldOff.a(msg).reset.a(Ansi.Attribute.UNDERLINE_OFF).bold.a(Ansi.Attribute.RESET).toString + } override def normalStyle(CharSequence msg) { ansi.fg(COLOR_DEFAULT).a(msg).reset.toString() } } \ No newline at end of file diff --git a/org.uqbar.project.wollok.launch/src/org/uqbar/project/wollok/launch/repl/WollokRepl.xtend b/org.uqbar.project.wollok.launch/src/org/uqbar/project/wollok/launch/repl/WollokRepl.xtend index c9c5f0a91a..215895e75d 100644 --- a/org.uqbar.project.wollok.launch/src/org/uqbar/project/wollok/launch/repl/WollokRepl.xtend +++ b/org.uqbar.project.wollok.launch/src/org/uqbar/project/wollok/launch/repl/WollokRepl.xtend @@ -106,7 +106,7 @@ class WollokRepl { // TODO: should be WollokObject def printReturnValue(Object obj) { - if (obj == null) + if (obj === null) println("null".returnStyle) else if (obj instanceof WollokObject && !(obj as WollokObject).isVoid) doPrintReturnValue(obj) @@ -194,7 +194,7 @@ class WollokRepl { .toList .reverse .map [ stackDTO | stackDTO.toLinkForConsole ] - .join("") + .join(System.lineSeparator) printlnIdent(errorLine.errorStyle) } @@ -204,7 +204,7 @@ class WollokRepl { append(" ") append("at") append(" ") - if (st.contextDescription != null) { + if (st.contextDescription !== null) { append(st.contextDescription) append(" ") } @@ -212,7 +212,7 @@ class WollokRepl { var link = new StringBuffer if (st.hasFileName) { - link.append("(" + st.fileName + ":" + st.lineNumber + ")\n") + link.append("(" + st.fileName + ":" + st.lineNumber + ")") } result.toString.errorStyle + link.toString.linkStyle diff --git a/org.uqbar.project.wollok.ui.launch/src/org/uqbar/project/wollok/ui/console/WollokReplConsole.xtend b/org.uqbar.project.wollok.ui.launch/src/org/uqbar/project/wollok/ui/console/WollokReplConsole.xtend index 14792f32fe..d7ba9f386b 100644 --- a/org.uqbar.project.wollok.ui.launch/src/org/uqbar/project/wollok/ui/console/WollokReplConsole.xtend +++ b/org.uqbar.project.wollok.ui.launch/src/org/uqbar/project/wollok/ui/console/WollokReplConsole.xtend @@ -185,7 +185,7 @@ class WollokReplConsole extends TextConsole { def sendInputBuffer() { addCommandToHistory sessionCommands += inputBuffer - streamsProxy.write(inputBuffer) + streamsProxy.write(inputBuffer) outputTextEnd = page.viewer.textWidget.charCount updateInputBuffer page.viewer.textWidget.selection = outputTextEnd @@ -202,7 +202,7 @@ class WollokReplConsole extends TextConsole { lastCommands.last(ps) } - page.viewer.textWidget.content.replaceTextRange(outputTextEnd, document.length - outputTextEnd, inputBuffer) + page.viewer.textWidget.content.replaceTextRange(outputTextEnd, document.length - outputTextEnd, inputBuffer.replace(System.lineSeparator, "")) ] } diff --git a/org.uqbar.project.wollok.ui.launch/src/org/uqbar/project/wollok/ui/console/editor/WollokReplStyledText.xtend b/org.uqbar.project.wollok.ui.launch/src/org/uqbar/project/wollok/ui/console/editor/WollokReplStyledText.xtend index 5f571a1621..42d4197701 100644 --- a/org.uqbar.project.wollok.ui.launch/src/org/uqbar/project/wollok/ui/console/editor/WollokReplStyledText.xtend +++ b/org.uqbar.project.wollok.ui.launch/src/org/uqbar/project/wollok/ui/console/editor/WollokReplStyledText.xtend @@ -1,6 +1,5 @@ package org.uqbar.project.wollok.ui.console.editor -import java.lang.reflect.Field import java.util.List import org.eclipse.swt.SWTError import org.eclipse.swt.custom.StyleRange @@ -14,6 +13,7 @@ import org.eclipse.swt.widgets.Composite import org.uqbar.project.wollok.ui.console.editor.rtf.WollokRTFWriter import static extension org.uqbar.project.wollok.ui.console.highlight.AnsiUtils.* +import static extension org.uqbar.project.wollok.utils.ReflectionExtensions.* /** * Styled Text Wrapper for Wollok @@ -40,7 +40,7 @@ class WollokReplStyledText extends StyledText { def doCopySelection(int type) { if(type != DND.CLIPBOARD && type != DND.SELECTION_CLIPBOARD) return false try { - val blockXLocation = getFieldValue("blockXLocation") as Integer + val blockXLocation = this.getFieldValue("blockXLocation") as Integer if (blockSelection && blockXLocation != -1) { val text = getEscapedBlockText() if (text.length() > 0) { @@ -48,7 +48,7 @@ class WollokReplStyledText extends StyledText { val plainTextTransfer = TextTransfer.getInstance() val Object[] data = #{text} val Transfer[] types = #{plainTextTransfer} - val clipboard = getFieldValue("clipboard") as Clipboard + val clipboard = this.getFieldValue("clipboard") as Clipboard clipboard.setContents(data, types, type) return true } @@ -68,7 +68,7 @@ class WollokReplStyledText extends StyledText { } def void setClipboardContent(int start, int length, int clipboardType) throws SWTError { - val boolean isGtk = getFieldValue("IS_GTK") as Boolean + val boolean isGtk = this.getFieldValue("IS_GTK") as Boolean if(clipboardType == DND.SELECTION_CLIPBOARD && !isGtk) return; // Fix: when you select a line from start, it doesn't catch special characters @@ -94,34 +94,18 @@ class WollokReplStyledText extends StyledText { types = #[plainTextTransfer] } } - val clipboard = getFieldValue("clipboard") as Clipboard + val clipboard = this.getFieldValue("clipboard") as Clipboard clipboard.setContents(data, types, clipboardType) } private def getEscapedBlockText() { - val text = executeMethod("getBlockSelectionText", #{System.getProperty("line.separator")}) as String + val text = this.executeMethod("getBlockSelectionText", #{System.getProperty("line.separator")}) as String text.deleteAnsiCharacters } - private def getField(String name) { - val Field field = typeof(StyledText).getDeclaredField(name) as Field - field.accessible = true - field - } - - private def getFieldValue(String name) { - getField(name).get(this) - } - - def executeMethod(String methodName, Object[] args) { - val method = typeof(StyledText).getDeclaredMethod(methodName, args.map[it.class]) - method.accessible = true - method.invoke(this, args) - } - def void addStyle(int offset, List styles) { val line = content.getLineAtOffset(offset) style.applyStyle(line, styles) } - + } diff --git a/org.uqbar.project.wollok.ui.launch/src/org/uqbar/project/wollok/ui/console/highlight/WollokAnsiColorLineStyleListener.xtend b/org.uqbar.project.wollok.ui.launch/src/org/uqbar/project/wollok/ui/console/highlight/WollokAnsiColorLineStyleListener.xtend index fea51bf721..7baa017c64 100644 --- a/org.uqbar.project.wollok.ui.launch/src/org/uqbar/project/wollok/ui/console/highlight/WollokAnsiColorLineStyleListener.xtend +++ b/org.uqbar.project.wollok.ui.launch/src/org/uqbar/project/wollok/ui/console/highlight/WollokAnsiColorLineStyleListener.xtend @@ -23,10 +23,10 @@ class WollokAnsiColorLineStyleListener implements LineStyleListener { var currentAttributes = new WollokConsoleAttributes public static val Character ESCAPE_SGR = 'm' - int lastRangeEnd = 0; + int lastRangeEnd = 0 override lineGetStyle(LineStyleEvent event) { - if (event == null || event.lineText == null || event.lineText.length() == 0) + if (event === null || event.lineText === null || event.lineText.length() == 0) return val currentPalette = WollokConsolePreferenceUtils.getString(WollokConsolePreferenceConstants.PREF_COLOR_PALETTE) @@ -67,13 +67,13 @@ class WollokAnsiColorLineStyleListener implements LineStyleListener { } if (lastRangeEnd != start) - addRange(ranges, event.lineOffset + lastRangeEnd, start - lastRangeEnd, defStyle.foreground, false) + addRange(ranges, event.lineOffset + lastRangeEnd, start - lastRangeEnd, defStyle, false) lastAttributes = currentAttributes.clone - addRange(ranges, event.lineOffset + start, end - start, defStyle.foreground, true) + addRange(ranges, event.lineOffset + start, end - start, defStyle, true) } if (lastRangeEnd != currentText.length) - addRange(ranges, event.lineOffset + lastRangeEnd, currentText.length - lastRangeEnd, defStyle.foreground, false) + addRange(ranges, event.lineOffset + lastRangeEnd, currentText.length - lastRangeEnd, defStyle, false) lastAttributes = currentAttributes.clone @@ -81,8 +81,9 @@ class WollokAnsiColorLineStyleListener implements LineStyleListener { event.styles = ranges } - def void addRange(List ranges, int start, int length, Color foreground, boolean isCode) { - val range = new StyleRange(start, length, foreground, null) + def void addRange(List ranges, int start, int length, StyleRange defStyle, boolean isCode) { + val range = new StyleRange(start, length, defStyle.foreground, null) + range.underline = defStyle.underline WollokConsoleAttributes.updateRangeStyle(range, lastAttributes) if (isCode) { val showEscapeCodes = WollokConsolePreferenceUtils.getBoolean(WollokConsolePreferenceConstants.PREF_SHOW_ESCAPES) diff --git a/org.uqbar.project.wollok.ui.launch/src/org/uqbar/project/wollok/ui/console/highlight/WollokCodeHighLightLineStyleListener.xtend b/org.uqbar.project.wollok.ui.launch/src/org/uqbar/project/wollok/ui/console/highlight/WollokCodeHighLightLineStyleListener.xtend index 103570302b..bcede4e99f 100644 --- a/org.uqbar.project.wollok.ui.launch/src/org/uqbar/project/wollok/ui/console/highlight/WollokCodeHighLightLineStyleListener.xtend +++ b/org.uqbar.project.wollok.ui.launch/src/org/uqbar/project/wollok/ui/console/highlight/WollokCodeHighLightLineStyleListener.xtend @@ -59,7 +59,7 @@ class WollokCodeHighLightLineStyleListener implements LineStyleListener { } override lineGetStyle(LineStyleEvent event) { - if (event == null || event.lineText == null || event.lineText.length == 0 || !event.isCodeInputLine) + if (event === null || event.lineText === null || event.lineText.length == 0 || !event.isCodeInputLine) return; val originalText = (event.widget as StyledText).text @@ -78,6 +78,7 @@ class WollokCodeHighLightLineStyleListener implements LineStyleListener { val style = stylesProvider.getAttribute(styleId) val s = new StyleRange(event.lineOffset + offset - headerLength, length, style.foreground, style.background) + // TODO: Ver underline s.underline = style.underline s.data = styleId if (s.start <= originalText.length && s.end <= originalText.length) { diff --git a/org.uqbar.project.wollok.ui.launch/src/org/uqbar/project/wollok/ui/console/highlight/WollokConsoleAttributes.xtend b/org.uqbar.project.wollok.ui.launch/src/org/uqbar/project/wollok/ui/console/highlight/WollokConsoleAttributes.xtend index a2ba37a843..61b2876e7d 100644 --- a/org.uqbar.project.wollok.ui.launch/src/org/uqbar/project/wollok/ui/console/highlight/WollokConsoleAttributes.xtend +++ b/org.uqbar.project.wollok.ui.launch/src/org/uqbar/project/wollok/ui/console/highlight/WollokConsoleAttributes.xtend @@ -63,7 +63,7 @@ class WollokConsoleAttributes implements Cloneable { // This function maps from the current attributes as "described" by escape sequences to real, // Eclipse console specific attributes (resolving color palette, default colors, etc.) def static updateRangeStyle(StyleRange range, WollokConsoleAttributes attribute) { - val useWindowsMapping = getBoolean(WollokConsolePreferenceConstants.PREF_WINDOWS_MAPPING); + val useWindowsMapping = getBoolean(WollokConsolePreferenceConstants.PREF_WINDOWS_MAPPING) val WollokConsoleAttributes tempAttrib = attribute.clone as WollokConsoleAttributes var hilite = false diff --git a/org.uqbar.project.wollok.ui.launch/src/org/uqbar/project/wollok/ui/console/highlight/WollokStyleRangeListener.xtend b/org.uqbar.project.wollok.ui.launch/src/org/uqbar/project/wollok/ui/console/highlight/WollokStyleRangeListener.xtend index 352562630c..0ed1157055 100644 --- a/org.uqbar.project.wollok.ui.launch/src/org/uqbar/project/wollok/ui/console/highlight/WollokStyleRangeListener.xtend +++ b/org.uqbar.project.wollok.ui.launch/src/org/uqbar/project/wollok/ui/console/highlight/WollokStyleRangeListener.xtend @@ -22,5 +22,5 @@ class WollokStyleRangeListener implements LineStyleListener { } styledText.addStyle(event.lineOffset, styles) } - + } \ No newline at end of file diff --git a/org.uqbar.project.wollok/src/org/uqbar/project/wollok/utils/ReflectionExtensions.xtend b/org.uqbar.project.wollok/src/org/uqbar/project/wollok/utils/ReflectionExtensions.xtend index 87d025bd85..4f97f1fe1a 100644 --- a/org.uqbar.project.wollok/src/org/uqbar/project/wollok/utils/ReflectionExtensions.xtend +++ b/org.uqbar.project.wollok/src/org/uqbar/project/wollok/utils/ReflectionExtensions.xtend @@ -5,18 +5,34 @@ import java.lang.reflect.Field class ReflectionExtensions { static def assign(Object receiver, String variableName, Object object) { - var Class receiverClass = receiver.class + val Field f1 = getField(receiver.class, variableName) + f1.set(receiver, object) + } + + static def getField(Class c, String variableName) { + var Class receiverClass = c var mustCheck = true while (mustCheck) { try { val Field f1 = receiverClass.getDeclaredField(variableName) f1.accessible = true - f1.set(receiver, object) - mustCheck = false + return f1 } catch (NoSuchFieldException e) { receiverClass = receiverClass.superclass mustCheck = receiverClass !== null } } + return null + } + + static def getFieldValue(Object o, String name) { + getField(o.class, name).get(o) } + + static def executeMethod(Object o, String methodName, Object[] args) { + val method = (o.class).getDeclaredMethod(methodName, args.map[it.class]) + method.accessible = true + method.invoke(o, args) + } + } \ No newline at end of file diff --git a/org.uqbar.project.wollok/src/org/uqbar/project/wollok/utils/WEclipseUtils.xtend b/org.uqbar.project.wollok/src/org/uqbar/project/wollok/utils/WEclipseUtils.xtend index 558200d378..e3a9208c9c 100644 --- a/org.uqbar.project.wollok/src/org/uqbar/project/wollok/utils/WEclipseUtils.xtend +++ b/org.uqbar.project.wollok/src/org/uqbar/project/wollok/utils/WEclipseUtils.xtend @@ -108,7 +108,7 @@ class WEclipseUtils { iPath.exists else { val s = URI.toFileString - s != null && new File(s).exists + s !== null && new File(s).exists } } def static iPath(Resource it) { Path.fromOSString(URI.toPlatformString(true)) } @@ -156,11 +156,11 @@ class WEclipseUtils { def static openEditor(ITextEditor textEditor, String fileName, int lineNumber) { try { val IDocument document = textEditor.documentProvider.getDocument(textEditor.editorInput) - if(document == null) throw new RuntimeException("Could not open file " + fileName + " in editor") + if(document === null) throw new RuntimeException("Could not open file " + fileName + " in editor") var IRegion lineInfo = null // line count internaly starts with 0, and not with 1 like in GUI lineInfo = document.getLineInformation(lineNumber - 1) - if (lineInfo != null) { + if (lineInfo !== null) { textEditor.selectAndReveal(lineInfo.getOffset(), lineInfo.getLength()) } } catch (BadLocationException e) {