Add "IOStreams" to interpreter, add basic IO to GUI

This commit is contained in:
Jacob
2018-11-20 00:05:32 -05:00
parent 22efb546f1
commit aa68debd81
7 changed files with 138 additions and 53 deletions

View File

@@ -6,7 +6,7 @@ import javafx.animation.Timeline
import javafx.util.Duration
import tornadofx.*
class ActionView(val interp: Interpreter) : View() {
class ActionView(val interp: Interpreter, val ioView: IOView) : View() {
var runTimeline: Timeline = timeline(false) {
keyframe(Duration.seconds(0.0)) {
setOnFinished {
@@ -25,7 +25,10 @@ class ActionView(val interp: Interpreter) : View() {
}
button("reset") {
setOnAction { interp.reset() }
setOnAction {
interp.reset()
ioView.reset()
}
}
button("run") {

View File

@@ -14,6 +14,5 @@ class CodeView(val interp: Interpreter) : View() {
}
override val root = textarea(srcProperty) {
}
}

View File

@@ -8,9 +8,9 @@ class EditorView : View("Befide") {
private var interp: Interpreter = B93Interpreter()
private val codeView = CodeView(interp)
private val actionView = ActionView(interp)
private val stackView = StackView(interp)
private val ioView = IOView(interp)
private val actionView = ActionView(interp, ioView)
override val root = borderpane {
top { add(actionView) }

View File

@@ -2,24 +2,50 @@ package befide.ide
import befide.befunge.core.Interpreter
import javafx.beans.property.SimpleStringProperty
import javafx.event.EventHandler
import tornadofx.*
import tornadofx.getValue
import tornadofx.setValue
class IOView(val interp: Interpreter) : View() {
val outputProperty = SimpleStringProperty("")
var output by outputProperty
val oldinputProperty = SimpleStringProperty("")
var oldinput by oldinputProperty
init {
interp.outputChanged += {
while (!interp.stdOutput.isEmpty()) {
output += interp.stdOutput.remove()
}
}
// add listeners to interp, handle streams, idk
}
override val root = vbox {
addClass("")
textarea(outputProperty) {
isWrapText = true
isEditable = false
// width, height, idk
prefHeight = 200.0
}
textarea(oldinputProperty) {
isEditable = false
prefHeight = 0.0
}
textfield {
onAction = EventHandler {
oldinput += this.text + '\n'
this.text.forEach { c -> interp.stdInput.add(c) }
this.clear()
}
}
}
fun reset() {
output = ""
oldinput = ""
}
}