Skip to content

Commit

Permalink
Merge f94717e into 8791c5b
Browse files Browse the repository at this point in the history
  • Loading branch information
fdodino committed Aug 23, 2020
2 parents 8791c5b + f94717e commit ca44c47
Show file tree
Hide file tree
Showing 12 changed files with 162 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class WollokRepl {
val WollokInterpreter interpreter
val File mainFile
val reader = new BufferedReader(new InputStreamReader(System.in))
val static prompt = ">>> "
var static whiteSpaces = ""
val WFile parsedMainFile
val extension ReplOutputFormatter formatter
Expand Down Expand Up @@ -73,7 +72,7 @@ class WollokRepl {
}

def synchronized printPrompt() {
print(prompt.messageStyle)
print(REPL_PROMPT.messageStyle)
}

def synchronized void printEndStructure() {
Expand Down Expand Up @@ -114,14 +113,13 @@ class WollokRepl {
'''
}


def synchronized executeInput(String input) {
var isImport = input.startsWith("import")

try {
val returnValue = interpreter.interpret(input.createReplExpression(isImport).parseRepl(mainFile), true)

if (isImport )
if (isImport)
// Parsing didn't fail, commit adding manual import to global list.
// No need to print nothing
manualImports += input
Expand Down Expand Up @@ -231,8 +229,4 @@ class WollokRepl {
printlnIdent(e.convertToString.errorStyle)
}

def getPrompt() {
prompt.messageStyle.toString
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,34 @@ package org.uqbar.project.wollok.ui.console

import java.io.ByteArrayInputStream
import java.text.SimpleDateFormat
import java.util.ArrayList
import java.util.Date
import java.util.List
import org.eclipse.core.resources.IContainer
import org.eclipse.core.resources.ResourcesPlugin
import org.eclipse.core.runtime.Path
import org.eclipse.debug.core.ILaunchConfiguration
import org.eclipse.debug.core.model.IProcess
import org.eclipse.debug.core.model.IStreamsProxy
import org.eclipse.debug.internal.ui.DebugUIPlugin
import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants
import org.eclipse.debug.ui.DebugUITools
import org.eclipse.swt.graphics.Color
import org.eclipse.swt.widgets.Display
import org.eclipse.ui.console.IConsoleView
import org.eclipse.ui.console.TextConsole
import org.eclipse.ui.console.TextConsolePage
import org.eclipse.xtend.lib.annotations.Accessors
import org.uqbar.project.tools.OrderedBoundedSet
import org.uqbar.project.wollok.WollokConstants
import org.uqbar.project.wollok.ui.console.editor.WollokReplConsolePartitioner
import org.uqbar.project.wollok.ui.launch.Activator
import org.uqbar.project.wollok.ui.launch.shortcut.WollokLaunchShortcut

import static org.uqbar.project.wollok.WollokConstants.*
import static org.uqbar.project.wollok.ui.console.RunInBackground.*
import static org.uqbar.project.wollok.ui.console.RunInUI.*

import static extension org.uqbar.project.wollok.ui.launch.WollokLaunchConstants.*
import static extension org.uqbar.project.wollok.utils.WEclipseUtils.*

/**
Expand All @@ -35,7 +39,7 @@ class WollokReplConsole extends TextConsole {
IProcess process
IStreamsProxy streamsProxy
@Accessors
TextConsolePage page
WollokReplConsolePage page
@Accessors
int outputTextEnd = 0
@Accessors
Expand All @@ -47,24 +51,38 @@ class WollokReplConsole extends TextConsole {
@Accessors
List<String> sessionCommands = newArrayList
@Accessors
val lastCommands = new OrderedBoundedSet<String>(10)
val lastCommands = new OrderedBoundedSet<String>(30)
List<String> lastSessionCommands
List<String> lastSessionCommandsToRun
@Accessors(PUBLIC_GETTER)
Long timeStart
public static Color ENABLED = new Color(Display.current, 255, 255, 255)

public static Color ENABLED = new Color(Display.current, 255, 255, 255)
public static Color DISABLED = new Color(Display.current, 220, 220, 220)


ILaunchConfiguration configuration
String mode

boolean restartingLastSession = false

def static getConsoleName() { "Wollok REPL Console" }

new() {
new(ILaunchConfiguration configuration, String mode) {
super(consoleName, null, Activator.getDefault.getImageDescriptor("icons/w.png"), true)
background = ENABLED
this.background = ENABLED
this.partitioner = new WollokReplConsolePartitioner(this)
this.document.documentPartitioner = this.partitioner

// Parameters needed to restart the console
this.configuration = configuration
this.mode = mode
this.restartingLastSession = configuration.restartingState
this.lastSessionCommandsToRun = configuration.lastCommands
}

def startForProcess(IProcess process) {
timeStart = System.currentTimeMillis
lastSessionCommands = newArrayList
loadHistory
this.process = process
streamsProxy = process.streamsProxy
Expand All @@ -75,22 +93,51 @@ class WollokReplConsole extends TextConsole {
clearConsole
DebugUIPlugin.getDefault.preferenceStore.setValue(IDebugPreferenceConstants.CONSOLE_OPEN_ON_OUT, false)
DebugUIPlugin.getDefault.preferenceStore.setValue(IDebugPreferenceConstants.CONSOLE_OPEN_ON_ERR, false)

]

streamsProxy.outputStreamMonitor.addListener [ text, monitor |
runInUI("WollokReplConsole-UpdateText") [
if (page !== null && page.viewer !== null && page.viewer.textWidget !== null) {
page.viewer.textWidget.append(text)
outputTextEnd = page.viewer.textWidget.charCount
inputBufferStartOffset = page.viewer.textWidget.text.length
page.viewer.textWidget.selection = outputTextEnd
updateInputBuffer
activate
text.processInput
val promptReady = text.contains(REPL_PROMPT)
if (this.restartingLastSession && promptReady && !this.lastSessionCommandsToRun.isEmpty) {
val nextCommand = this.lastSessionCommandsToRun.remove(0)
nextCommand.execute
}
}
]
]
}

def processInput(String text) {
page.viewer.textWidget.append(text)
outputTextEnd = page.viewer.textWidget.charCount
inputBufferStartOffset = page.viewer.textWidget.text.length
page.viewer.textWidget.selection = outputTextEnd
updateInputBuffer
activate
}

def restart() {
DebugUITools.launch(this.configuration, this.mode)
}

def restartLastSession() {
val newConfiguration = this.configuration.getWorkingCopy => [
setRestartingState(true)
setLastCommands(new ArrayList(lastSessionCommands))
]
DebugUITools.launch(newConfiguration, this.mode)
}

def synchronized void execute(String command) {
runInUI [
inputBuffer = command
page.viewer.textWidget.content.replaceTextRange(outputTextEnd, document.length - outputTextEnd, inputBuffer)
page.setCursorToEnd
sendInputBuffer
]
}

def cleanViewOfConsole() {
val wordToWrite = "/^*^?/" + System.lineSeparator
Expand All @@ -103,8 +150,8 @@ class WollokReplConsole extends TextConsole {
process.terminate
}

def isRunning() {
val terminated = process.terminated
def isRunning() {
val terminated = process.terminated
if (terminated) {
background = DISABLED
}
Expand All @@ -124,19 +171,19 @@ class WollokReplConsole extends TextConsole {
name = consoleDescription
]
}

def consoleDescription() {
consoleName + if (hasMainFile) ": " + project() + "/" + fileName() else ""
consoleName + if(hasMainFile) ": " + project() + "/" + fileName() else ""
}

def hasMainFile() {
return fileName() !== null && fileName.endsWith("." + WollokConstants.WOLLOK_DEFINITION_EXTENSION)
}

def fileName() {
WollokLaunchShortcut.getWollokFile(process.launch)
}

def project() {
WollokLaunchShortcut.getWollokProject(process.launch)
}
Expand Down Expand Up @@ -171,11 +218,12 @@ class WollokReplConsole extends TextConsole {
}

def addCommandToHistory() {
if (!inputBuffer.empty) {
if (!inputBuffer.trim.empty) {
lastCommands => [
remove(inputBuffer)
add(inputBuffer)
]
lastSessionCommands.add(inputBuffer)
saveHistory
}
}
Expand Down Expand Up @@ -206,7 +254,7 @@ class WollokReplConsole extends TextConsole {
def sendInputBuffer() {
addCommandToHistory
sessionCommands += inputBuffer

streamsProxy.write(inputBuffer)
outputTextEnd = page.viewer.textWidget.charCount
updateInputBuffer
Expand All @@ -223,10 +271,11 @@ class WollokReplConsole extends TextConsole {
val ps = if(pos >= lastCommands.size) 0 else pos
lastCommands.last(ps)
}
page.viewer.textWidget.content.replaceTextRange(outputTextEnd, document.length - outputTextEnd, inputBuffer.replace(System.lineSeparator, ""))
page.viewer.textWidget.content.replaceTextRange(outputTextEnd, document.length - outputTextEnd,
inputBuffer.replace(System.lineSeparator, ""))
]
}

def clearHistory() { lastCommands.clear }

def canWriteAt(int offset) { !partitioner.isReadOnly(offset) }
Expand All @@ -238,5 +287,5 @@ class WollokReplConsole extends TextConsole {
inputBuffer = inputBuffer.replaceAll(System.lineSeparator, '')
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.eclipse.ui.console.IScrollLockStateProvider
import org.eclipse.ui.console.TextConsole
import org.eclipse.ui.console.TextConsolePage
import org.eclipse.ui.console.TextConsoleViewer
import org.eclipse.xtend.lib.annotations.Accessors
import org.uqbar.project.wollok.ui.console.editor.WollokReplStyledText

/**
Expand All @@ -30,7 +31,7 @@ class WollokReplConsolePage extends TextConsolePage implements KeyListener {
static val KEY_RETURN = 0x0d
val WollokReplConsole console
val IConsoleView view
var int historyPosition = -1
@Accessors var int historyPosition = -1

new(WollokReplConsole console, IConsoleView view) {
super(console, view)
Expand Down
Loading

0 comments on commit ca44c47

Please sign in to comment.