Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
gargantext-ihaskell
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
gargantext-ihaskell
Commits
721c5d1d
Commit
721c5d1d
authored
Mar 17, 2014
by
Andrew Gibiansky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
comms work now
parent
631bebe1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
169 additions
and
89 deletions
+169
-89
Parsec.hs
ihaskell-display/ihaskell-parsec/IHaskell/Display/Parsec.hs
+42
-24
Test.ipynb
notebooks/Test.ipynb
+120
-63
Evaluate.hs
src/IHaskell/Eval/Evaluate.hs
+1
-1
Main.hs
src/Main.hs
+6
-1
No files found.
ihaskell-display/ihaskell-parsec/IHaskell/Display/Parsec.hs
View file @
721c5d1d
...
...
@@ -8,7 +8,6 @@ import Data.String.Here
import
Text.Parsec.String
import
IHaskell.Display
import
IHaskell.Display
(
IHaskellWidget
)
instance
IHaskellDisplay
(
Parser
a
)
where
display
renderable
=
do
...
...
@@ -18,33 +17,52 @@ instance IHaskellDisplay (Parser a) where
dom
key
=
let
divId
=
"text"
++
show
key
++
""
in
[
i
|
<form><textarea id="${divId}">Hello!</textarea></form>
<form><textarea id="parsec-editor">Hello!</textarea></form>
<!--
<script>
// Start the Comm.
var CommManager = IPython.notebook.kernel.comm_manager;
var comm = CommManager.new_comm("parsec", {}, {
iopub : {
output : function () {
console.log("Iopub output init:");
console.log(arguments);
}
}
});
// Create the editor.
var textarea = document.getElementById("${divId}");
var editor = CodeMirror.fromTextArea(textarea);
editor.on("change", function() {
var text = editor.getDoc().getValue();
console.log("New text: " + text);
comm.send({"text": text}, function () {
console.log("Got response!", arguments);
});
});
// Register the comm target.
var ParsecWidget = function (comm) {
this.comm = comm;
this.comm.on_msg($.proxy(this.handler, this));
// get the cell that was probably executed
// msg_id:cell mapping will make this possible without guessing
this.cell = IPython.notebook.get_cell(IPython.notebook.get_selected_index()-1);
this.callbacks = {
iopub : {
output : function () {
console.log("Iopub output", arguments);
}
}
};
// Create the editor.
console.log("Editoring");
var out = this.cell.output_area.element;
var textarea = output_area.find("#parsec-editor")[0];
var editor = CodeMirror.fromTextArea(textarea);
editor.on("change", function() {
var text = editor.getDoc().getValue();
console.log("New text: " + text);
comm.send({"text": text}, function () {
console.log("Got response!", arguments);
});
});
};
ParsecWidget.prototype.handler = function(msg) {
console.log('handle', this, msg, this.cell.output_area);
};
IPython.notebook.kernel.comm_manager.register_target('parsec', IPython.utils.always_new(ParsecWidget));
</script>
-->
|]
instance
IHaskellWidget
(
Parser
a
)
where
targetName
_
=
"parsec"
open
widget
value
publisher
=
return
()
comm
widget
value
publisher
=
return
()
comm
widget
value
publisher
=
do
DEAL
WITH
ACTUAL
PARSECS
publisher
value
close
widget
value
=
return
()
notebooks/Test.ipynb
View file @
721c5d1d
...
...
@@ -21,52 +21,64 @@
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"oneOf \"Hello\" :: Parser Char"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"x <- display (oneOf \"Hello\" :: Parser Char)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"case x of \n",
" Display [DisplayData MimeHtml dat] -> putStrLn $ unpack dat\n",
" _ -> error \"no\""
"oneOf \"Hello\" :: Parser Char"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<span class='err-msg'>Not in scope: data constructor `MimeHtml'<br/><br/><br/>Not in scope: `unpack'</span>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"Not in scope: data constructor `MimeHtml'\n",
"\n",
" <form><textarea id=\"parsec-editor\">Hello!</textarea></form>\n",
" <!--\n",
" <script>\n",
" // Register the comm target.\n",
" var ParsecWidget = function (comm) {\n",
" this.comm = comm;\n",
" this.comm.on_msg($.proxy(this.handler, this));\n",
"\n",
" // get the cell that was probably executed\n",
" // msg_id:cell mapping will make this possible without guessing\n",
" this.cell = IPython.notebook.get_cell(IPython.notebook.get_selected_index()-1);\n",
" this.callbacks = {\n",
" iopub : {\n",
" output : function () {\n",
" console.log(\"Iopub output\", arguments);\n",
" }\n",
" }\n",
" };\n",
"\n",
"Not in scope: `unpack'"
]
" // Create the editor.\n",
" console.log(\"Editoring\");\n",
" var out = this.cell.output_area.element;\n",
" var textarea = output_area.find(\"#parsec-editor\")[0];\n",
" var editor = CodeMirror.fromTextArea(textarea);\n",
" editor.on(\"change\", function() {\n",
" var text = editor.getDoc().getValue();\n",
" console.log(\"New text: \" + text);\n",
" comm.send({\"text\": text}, function () {\n",
" console.log(\"Got response!\", arguments);\n",
" });\n",
" });\n",
" };\n",
"\n",
" ParsecWidget.prototype.handler = function(msg) {\n",
" console.log('handle', this, msg, this.cell.output_area);\n",
" };\n",
"\n",
" IPython.notebook.kernel.comm_manager.register_target('parsec', IPython.utils.always_new(ParsecWidget));\n",
" </script>\n",
" -->\n",
" "
],
"metadata": {},
"output_type": "display_data"
}
],
"prompt_number": 3
...
...
@@ -75,45 +87,90 @@
"cell_type": "code",
"collapsed": false,
"input": [
"import IHaskell.Types"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import ClassyPrelude (unpack)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 5
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"oneOf \"Hello\" :: Parser Char"
"import IHaskell.Display\n",
"import Data.String.Here\n",
":set -XQuasiQuotes\n",
"\n",
"html [i|\n",
" <script>\n",
" // Register the comm target.\n",
" var ParsecWidget = function (comm) {\n",
" this.comm = comm;\n",
" this.comm.on_msg($.proxy(this.handler, this));\n",
"\n",
" // Get the cell that was probably executed.\n",
" // The msg_id:cell mapping will make this possible without guessing.\n",
" this.cell = IPython.notebook.get_cell(IPython.notebook.get_selected_index()-1);\n",
"\n",
" // Create the editor.\n",
" var out = this.cell.output_area.element;\n",
" var textarea = out.find(\"#parsec-editor\")[0];\n",
" var editor = CodeMirror.fromTextArea(textarea);\n",
" editor.on(\"change\", function() {\n",
" var text = editor.getDoc().getValue();\n",
" comm.send({\"text\": text});\n",
" });\n",
" this.editor = editor;\n",
" };\n",
"\n",
" ParsecWidget.prototype.handler = function(msg) {\n",
" var data = msg.content.data;\n",
" if (data[\"status\"] == \"error\") {\n",
" editor.getDoc().setValue(\"ERROR!!!\");\n",
" }\n",
" };\n",
"\n",
" IPython.notebook.kernel.comm_manager.register_target('parsec', IPython.utils.always_new(ParsecWidget));\n",
" </script>\n",
" |]"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<span class='err-msg'>Not in scope: type constructor or class `Parser'<br/><br/><br/>Not in scope: `oneOf'</span>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"Not in scope: type constructor or class `Parser'\n",
"\n",
" <script>\n",
" // Register the comm target.\n",
" var ParsecWidget = function (comm) {\n",
" this.comm = comm;\n",
" this.comm.on_msg($.proxy(this.handler, this));\n",
"\n",
" // get the cell that was probably executed\n",
" // msg_id:cell mapping will make this possible without guessing\n",
" this.cell = IPython.notebook.get_cell(IPython.notebook.get_selected_index()-1);\n",
" this.callbacks = {\n",
" iopub : {\n",
" output : function () {\n",
" console.log(\"Iopub output\", arguments);\n",
" }\n",
" }\n",
" };\n",
"\n",
" // Create the editor.\n",
" console.log(\"Editoring\");\n",
" var out = this.cell.output_area.element;\n",
" var textarea = out.find(\"#parsec-editor\")[0];\n",
" var editor = CodeMirror.fromTextArea(textarea);\n",
" editor.on(\"change\", function() {\n",
" var text = editor.getDoc().getValue();\n",
" console.log(\"New text: \" + text);\n",
" comm.send({\"text\": text}, function () {\n",
" console.log(\"Got response!\", arguments);\n",
" });\n",
" });\n",
" };\n",
"\n",
"Not in scope: `oneOf'"
]
" ParsecWidget.prototype.handler = function(msg) {\n",
" console.log('handle', this, msg, this.cell.output_area);\n",
" };\n",
"\n",
" IPython.notebook.kernel.comm_manager.register_target('parsec', IPython.utils.always_new(ParsecWidget));\n",
" </script>\n",
" "
],
"metadata": {},
"output_type": "display_data"
}
],
"prompt_number": 1
...
...
src/IHaskell/Eval/Evaluate.hs
View file @
721c5d1d
...
...
@@ -696,7 +696,7 @@ evalCommand output (Expression expr) state = do
-- Check if this is a widget.
let
widgetExpr
=
printf
"(IHaskell.Display.Widget (%s))"
expr
::
String
isWidget
<-
attempt
$
exprType
display
Expr
isWidget
<-
attempt
$
exprType
widget
Expr
if
canRunDisplay
then
do
...
...
src/Main.hs
View file @
721c5d1d
...
...
@@ -186,7 +186,7 @@ runKernel profileSrc initInfo = do
if
isCommMessage
request
then
liftIO
$
do
oldState
<-
takeMVar
state
let
replier
=
writeChan
(
shellReply
Channel
interface
)
let
replier
=
writeChan
(
iopub
Channel
interface
)
newState
<-
handleComm
replier
oldState
request
replyHeader
putMVar
state
newState
else
do
...
...
@@ -373,11 +373,15 @@ replyTo _ ObjectInfoRequest{objectName = oname} replyHeader state = do
handleComm
::
(
Message
->
IO
()
)
->
KernelState
->
Message
->
MessageHeader
->
IO
KernelState
handleComm
replier
kernelState
req
replyHeader
=
do
putStrLn
"Handle comm"
print
req
let
widgets
=
openComms
kernelState
uuid
=
commUuid
req
dat
=
commData
req
communicate
value
=
do
head
<-
dupHeader
replyHeader
CommDataMessage
putStrLn
"Sending back data:"
print
value
replier
$
CommData
head
uuid
value
case
lookup
uuid
widgets
of
Nothing
->
fail
$
"no widget with uuid "
++
show
uuid
...
...
@@ -387,6 +391,7 @@ handleComm replier kernelState req replyHeader = do
open
widget
dat
communicate
return
kernelState
CommDataMessage
->
do
putStrLn
"comm data"
comm
widget
dat
communicate
return
kernelState
CommCloseMessage
->
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment