Added muted

This commit is contained in:
obscuren 2014-04-28 23:24:42 +02:00
parent c0de11955b
commit 922974c760
7 changed files with 291 additions and 177 deletions

View File

@ -7,20 +7,63 @@
<script src="lib/codemirror.js"></script> <script src="lib/codemirror.js"></script>
<script src="lib/matchbrackets.js"></script> <script src="lib/matchbrackets.js"></script>
<script src="lib/go.js"></script> <script src="lib/go.js"></script>
<script src="muted.js"></script>
<style type="text/css"> <style type="text/css">
html, body { html, body {
margin: 0; padding: 0; margin: 0; padding: 0;
min-height: 100%;
}
#debugger {
height: 30%;
font-family: "Monaco";
border-top: 5px solid grey;
}
#debugger .line {
overflow: none;
}
#debugger .col1, #debugger .col2 {
float: left;
padding: 3px;
}
#debugger .col1 {
width: 10px;
padding-left: 10px
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
#debugger .col2 {
width: 90%;
}
.prompt {
color: "#5089D4";
} }
.CodeMirror { .CodeMirror {
height: 100%; height: 70%;
font-size: 14pt;
} }
</style> </style>
</head> </head>
<body> <body>
<textarea id="editor"></textarea> <textarea id="editor"></textarea>
<div id="debugger">
<div class="line">
<div class="col1 prompt">
&gt;
</div>
<div class="col2" contenteditable>
</div>
</div>
</div>
<script> <script>
var textArea = document.querySelector("#editor") var textArea = document.querySelector("#editor")
var editor = CodeMirror.fromTextArea(textArea, { var editor = CodeMirror.fromTextArea(textArea, {
@ -33,6 +76,5 @@
indentWithTabs: true, indentWithTabs: true,
}); });
</script> </script>
</body> </body>
</html> </html>

View File

@ -0,0 +1,61 @@
// Helper function for generating pseudo callbacks and sending data to the QML part of the application
function postData(data, cb) {
data._seed = Math.floor(Math.random() * 1000000)
if(cb) {
Muted._callbacks[data._seed] = cb;
}
if(data.args === undefined) {
data.args = [];
}
navigator.qt.postMessage(JSON.stringify(data));
}
window.Muted = {
prototype: Object(),
}
window.Muted._callbacks = {}
window.Muted._onCallbacks = {}
function debug(/**/) {
console.log("hello world")
var args = arguments;
var msg = ""
for(var i = 0; i < args.length; i++){
if(typeof args[i] == "object") {
msg += " " + JSON.stringify(args[i])
} else {
msg += args[i]
}
}
document.querySelector("#debugger").innerHTML += "<div class='line'><div class='col1'></div><div class='col2'>"+msg+"</div></div>";
}
console.log = function() {
var args = []
for(var i = 0; i < arguments.length; i++) {
args.push(arguments[i]);
}
postData({call:"log", args:args})
}
navigator.qt.onmessage = function(ev) {
var data = JSON.parse(ev.data)
if(data._event !== undefined) {
Muted.trigger(data._event, data.data);
} else {
if(data._seed) {
var cb = Muted._callbacks[data._seed];
if(cb) {
// Call the callback
cb(data.data);
// Remove the "trigger" callback
delete Muted._callbacks[ev._seed];
}
}
}
}

View File

@ -14,7 +14,6 @@ ApplicationWindow {
minimumHeight: 300 minimumHeight: 300
property alias url: webView.url property alias url: webView.url
property alias debugUrl: debugView.url
property alias webView: webView property alias webView: webView
@ -28,10 +27,30 @@ ApplicationWindow {
top: root.top top: root.top
right: root.right right: root.right
left: root.left left: root.left
bottom: sizeGrip.top bottom: root.bottom
//bottom: sizeGrip.top
}
experimental.preferences.javascriptEnabled: true
experimental.preferences.navigatorQtObjectEnabled: true
experimental.onMessageReceived: {
var data = JSON.parse(message.data)
switch(data.call) {
case "log":
console.log.apply(this, data.args)
break;
}
}
function postData(seed, data) {
webview.experimental.postMessage(JSON.stringify({data: data, _seed: seed}))
}
function postEvent(event, data) {
webview.experimental.postMessage(JSON.stringify({data: data, _event: event}))
} }
} }
/*
Rectangle { Rectangle {
id: sizeGrip id: sizeGrip
color: "gray" color: "gray"
@ -50,16 +69,6 @@ ApplicationWindow {
drag.axis: Drag.YAxis drag.axis: Drag.YAxis
} }
} }
*/
WebView {
id: debugView
objectName: "debugView"
anchors {
left: root.left
right: root.right
bottom: root.bottom
top: sizeGrip.bottom
}
}
} }
} }

View File

@ -78,6 +78,7 @@ ApplicationWindow {
if(data.args.length > 0) { if(data.args.length > 0) {
eth.watch(data.args[0]); eth.watch(data.args[0]);
} }
break
} }
} }
function postData(seed, data) { function postData(seed, data) {

View File

@ -120,8 +120,8 @@ func (ui *UiLib) Muted(content string) {
go func() { go func() {
path := "file://" + ui.AssetPath("muted/index.html") path := "file://" + ui.AssetPath("muted/index.html")
win.Set("url", path) win.Set("url", path)
debuggerPath := "file://" + ui.AssetPath("muted/debugger.html") //debuggerPath := "file://" + ui.AssetPath("muted/debugger.html")
win.Set("debugUrl", debuggerPath) //win.Set("debugUrl", debuggerPath)
win.Show() win.Show()
win.Wait() win.Wait()

View File

@ -12,6 +12,7 @@ import (
"github.com/ethereum/eth-go/ethutil" "github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethwire" "github.com/ethereum/eth-go/ethwire"
"github.com/ethereum/go-ethereum/utils" "github.com/ethereum/go-ethereum/utils"
"github.com/obscuren/mutan"
"os" "os"
"strings" "strings"
) )
@ -190,7 +191,7 @@ func (i *Console) ParseInput(input string) bool {
case "contract": case "contract":
fmt.Println("Contract editor (Ctrl-D = done)") fmt.Println("Contract editor (Ctrl-D = done)")
mainInput, initInput := ethutil.PreProcess(i.Editor()) mainInput, initInput := mutan.PreProcess(i.Editor())
mainScript, err := utils.Compile(mainInput) mainScript, err := utils.Compile(mainInput)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)