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
51b8ea24
Commit
51b8ea24
authored
Jan 09, 2014
by
Andrew Gibiansky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changing DisplayData -> Display in IHaskell
parent
6b5fb53d
Changes
13
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
99 additions
and
76 deletions
+99
-76
Aeson.hs
ihaskell-display/ihaskell-aeson/IHaskell/Display/Aeson.hs
+1
-1
Display.hs
ihaskell-display/ihaskell-basic/IHaskell/Display/Display.hs
+1
-1
Blaze.hs
ihaskell-display/ihaskell-blaze/IHaskell/Display/Blaze.hs
+1
-1
Charts.hs
ihaskell-display/ihaskell-charts/IHaskell/Display/Charts.hs
+1
-1
Diagrams.hs
...ll-display/ihaskell-diagrams/IHaskell/Display/Diagrams.hs
+1
-1
Magic.hs
ihaskell-display/ihaskell-magic/IHaskell/Display/Magic.hs
+1
-1
Writer.hs
ipython-kernel/src/IPython/Message/Writer.hs
+1
-1
Types.hs
ipython-kernel/src/IPython/Types.hs
+4
-4
Display.hs
src/IHaskell/Display.hs
+26
-18
Evaluate.hs
src/IHaskell/Eval/Evaluate.hs
+46
-41
Lint.hs
src/IHaskell/Eval/Lint.hs
+3
-3
Types.hs
src/IHaskell/Types.hs
+11
-2
Main.hs
src/Main.hs
+2
-1
No files found.
ihaskell-display/ihaskell-aeson/IHaskell/Display/Aeson.hs
View file @
51b8ea24
...
...
@@ -10,7 +10,7 @@ import Data.String.Here
import
IHaskell.Display
instance
IHaskellDisplay
Value
where
display
renderable
=
return
[
plain
json
,
html
dom
]
display
renderable
=
return
$
Display
[
plain
json
,
html
dom
]
where
json
=
unpack
$
decodeUtf8
$
encodePretty
renderable
dom
=
[
i
|
<div class="highlight-code" id="javascript">${json}</div>
|]
ihaskell-display/ihaskell-basic/IHaskell/Display/Display.hs
View file @
51b8ea24
...
...
@@ -6,7 +6,7 @@ import IHaskell.Display
import
Text.Printf
instance
Show
a
=>
IHaskellDisplay
(
Maybe
a
)
where
display
just
=
return
[
stringDisplay
,
htmlDisplay
]
display
just
=
return
$
Display
[
stringDisplay
,
htmlDisplay
]
where
stringDisplay
=
plain
(
show
just
)
htmlDisplay
=
html
str
...
...
ihaskell-display/ihaskell-blaze/IHaskell/Display/Blaze.hs
View file @
51b8ea24
...
...
@@ -10,7 +10,7 @@ import Text.Blaze.Internal
import
Control.Monad
instance
IHaskellDisplay
(
MarkupM
a
)
where
display
val
=
return
[
stringDisplay
,
htmlDisplay
]
display
val
=
return
$
Display
[
stringDisplay
,
htmlDisplay
]
where
str
=
renderMarkup
(
void
val
)
stringDisplay
=
plain
str
...
...
ihaskell-display/ihaskell-charts/IHaskell/Display/Charts.hs
View file @
51b8ea24
...
...
@@ -26,7 +26,7 @@ instance IHaskellDisplay (Renderable a) where
-- but SVGs are not resizable in the IPython notebook.
svgDisp
<-
chartData
renderable
SVG
return
[
pngDisp
,
svgDisp
]
return
$
Display
[
pngDisp
,
svgDisp
]
chartData
::
Renderable
a
->
FileFormat
->
IO
DisplayData
chartData
renderable
format
=
do
...
...
ihaskell-display/ihaskell-diagrams/IHaskell/Display/Diagrams.hs
View file @
51b8ea24
...
...
@@ -16,7 +16,7 @@ instance IHaskellDisplay (Diagram Cairo R2) where
display
renderable
=
do
png
<-
diagramData
renderable
PNG
svg
<-
diagramData
renderable
SVG
return
[
png
,
svg
]
return
$
Display
[
png
,
svg
]
diagramData
::
Diagram
Cairo
R2
->
OutputType
->
IO
DisplayData
diagramData
renderable
format
=
do
...
...
ihaskell-display/ihaskell-magic/IHaskell/Display/Magic.hs
View file @
51b8ea24
...
...
@@ -24,7 +24,7 @@ instance IHaskellDisplay B.ByteString where
m
<-
magicOpen
[]
magicLoadDefault
m
f
<-
B
.
unsafeUseAsCStringLen
x
(
magicCString
m
)
return
[
withClass
(
parseMagic
f
)
x
]
return
$
Display
[
withClass
(
parseMagic
f
)
x
]
b64
::
B
.
ByteString
->
String
b64
=
Char
.
unpack
.
Base64
.
encode
...
...
ipython-kernel/src/IPython/Message/Writer.hs
View file @
51b8ea24
...
...
@@ -101,7 +101,7 @@ instance ToJSON StreamType where
-- | Convert a MIME type and value into a JSON dictionary pair.
displayDataToJson
::
DisplayData
->
(
Text
,
Value
)
displayDataToJson
(
Display
mimeType
dataStr
)
=
pack
(
show
mimeType
)
.=
dataStr
displayDataToJson
(
Display
Data
mimeType
dataStr
)
=
pack
(
show
mimeType
)
.=
dataStr
----- Constants -----
...
...
ipython-kernel/src/IPython/Types.hs
View file @
51b8ea24
...
...
@@ -341,13 +341,13 @@ replyType ShutdownRequestMessage = Just ShutdownReplyMessage
replyType
_
=
Nothing
-- | Data for display: a string with associated MIME type.
data
DisplayData
=
Display
MimeType
ByteString
deriving
(
Typeable
,
Generic
)
data
DisplayData
=
Display
Data
MimeType
ByteString
deriving
(
Typeable
,
Generic
)
-- We can't print the actual data, otherwise this will be printed every
-- time it gets computed because of the way the evaluator is structured.
-- See how `displayExpr` is computed.
instance
Show
DisplayData
where
show
_
=
"Display"
show
_
=
"Display
Data
"
-- Allow DisplayData serialization
instance
Serialize
DisplayData
...
...
@@ -369,9 +369,9 @@ extractPlain :: [DisplayData] -> String
extractPlain
disps
=
case
find
isPlain
disps
of
Nothing
->
""
Just
(
Display
PlainText
bytestr
)
->
Char
.
unpack
bytestr
Just
(
Display
Data
PlainText
bytestr
)
->
Char
.
unpack
bytestr
where
isPlain
(
Display
mime
_
)
=
mime
==
PlainText
isPlain
(
Display
Data
mime
_
)
=
mime
==
PlainText
instance
Show
MimeType
where
show
PlainText
=
"text/plain"
...
...
src/IHaskell/Display.hs
View file @
51b8ea24
...
...
@@ -5,12 +5,13 @@ module IHaskell.Display (
serializeDisplay
,
Width
,
Height
,
Base64
,
encode64
,
base64
,
DisplayData
Display
(
..
),
DisplayData
(
..
),
)
where
import
ClassyPrelude
import
Data.Serialize
as
Serialize
import
Data.ByteString
import
Data.ByteString
hiding
(
map
)
import
Data.String.Utils
(
rstrip
)
import
qualified
Data.ByteString.Base64
as
Base64
import
qualified
Data.ByteString.Char8
as
Char
...
...
@@ -27,52 +28,59 @@ type Base64 = ByteString
-- > instance (Show a) => IHaskellDisplay a
-- > instance Show a where shows _ = id
class
IHaskellDisplay
a
where
display
::
a
->
IO
[
DisplayData
]
display
::
a
->
IO
Display
-- | these instances cause the image, html etc. which look like:
--
-- > Display
Data
-- > [Display
Data
]
-- > IO [Display
Data
]
-- > IO (IO Display
Data
)
-- > Display
-- > [Display]
-- > IO [Display]
-- > IO (IO Display)
--
-- be run the IO and get rendered (if the frontend allows it) in the pretty
-- form.
instance
IHaskellDisplay
a
=>
IHaskellDisplay
(
IO
a
)
where
display
=
(
display
=<<
)
instance
IHaskellDisplay
DisplayData
where
display
disp
=
return
[
disp
]
instance
IHaskellDisplay
[
DisplayData
]
where
instance
IHaskellDisplay
Display
where
display
=
return
instance
IHaskellDisplay
a
=>
IHaskellDisplay
[
a
]
where
display
disps
=
do
displays
<-
mapM
display
disps
return
$
ManyDisplay
displays
-- | Encode many displays into a single one. All will be output.
many
::
[
Display
]
->
Display
many
=
ManyDisplay
-- | Generate a plain text display.
plain
::
String
->
DisplayData
plain
=
Display
PlainText
.
Char
.
pack
.
rstrip
plain
=
Display
Data
PlainText
.
Char
.
pack
.
rstrip
-- | Generate an HTML display.
html
::
String
->
DisplayData
html
=
Display
MimeHtml
.
Char
.
pack
html
=
Display
Data
MimeHtml
.
Char
.
pack
-- | Genreate an SVG display.
svg
::
String
->
DisplayData
svg
=
Display
MimeSvg
.
Char
.
pack
svg
=
Display
Data
MimeSvg
.
Char
.
pack
-- | Genreate a LaTeX display.
latex
::
String
->
DisplayData
latex
=
Display
MimeLatex
.
Char
.
pack
latex
=
Display
Data
MimeLatex
.
Char
.
pack
-- | Generate a PNG display of the given width and height. Data must be
-- provided in a Base64 encoded manner, suitable for embedding into HTML.
-- The @base64@ function may be used to encode data into this format.
png
::
Width
->
Height
->
Base64
->
DisplayData
png
width
height
=
Display
(
MimePng
width
height
)
png
width
height
=
Display
Data
(
MimePng
width
height
)
-- | Generate a JPG display of the given width and height. Data must be
-- provided in a Base64 encoded manner, suitable for embedding into HTML.
-- The @base64@ function may be used to encode data into this format.
jpg
::
Width
->
Height
->
Base64
->
DisplayData
jpg
width
height
=
Display
(
MimeJpg
width
height
)
jpg
width
height
=
Display
Data
(
MimeJpg
width
height
)
-- | Convert from a string into base 64 encoded data.
encode64
::
String
->
Base64
...
...
@@ -84,5 +92,5 @@ base64 = Base64.encode
-- | For internal use within IHaskell.
-- Serialize displays to a ByteString.
serializeDisplay
::
[
DisplayData
]
->
ByteString
serializeDisplay
::
Display
->
ByteString
serializeDisplay
=
Serialize
.
encode
src/IHaskell/Eval/Evaluate.hs
View file @
51b8ea24
This diff is collapsed.
Click to expand it.
src/IHaskell/Eval/Lint.hs
View file @
51b8ea24
...
...
@@ -38,7 +38,7 @@ lintIdent = "lintIdentAEjlkQeh"
-- | Given parsed code chunks, perform linting and output a displayable
-- report on linting warnings and errors.
lint
::
[
Located
CodeBlock
]
->
IO
[
DisplayData
]
lint
::
[
Located
CodeBlock
]
->
IO
Display
lint
blocks
=
do
let
validBlocks
=
map
makeValid
blocks
fileContents
=
joinBlocks
validBlocks
...
...
@@ -50,8 +50,8 @@ lint blocks = do
suggestions
<-
catMaybes
<$>
map
parseSuggestion
<$>
hlint
[
filename
,
"--quiet"
]
return
$
if
null
suggestions
then
[]
else
then
Display
[]
else
Display
[
plain
$
concatMap
plainSuggestion
suggestions
,
html
$
htmlSuggestions
suggestions
]
where
-- Join together multiple valid file blocks into a single file.
...
...
src/IHaskell/Types.hs
View file @
51b8ea24
...
...
@@ -20,12 +20,15 @@ module IHaskell.Types (
Width
,
Height
,
FrontendType
(
..
),
ViewFormat
(
..
),
Display
(
..
),
defaultKernelState
,
extractPlain
)
where
import
ClassyPrelude
import
qualified
Data.ByteString.Char8
as
Char
import
Data.Serialize
import
GHC.Generics
import
Text.Read
as
Read
hiding
(
pfail
,
String
)
import
Text.ParserCombinators.ReadP
...
...
@@ -60,6 +63,12 @@ instance Read ViewFormat where
"md"
->
return
Markdown
_
->
pfail
-- | Wrapper for ipython-kernel's DisplayData which allows sending multiple
-- results from the same expression.
data
Display
=
Display
[
DisplayData
]
|
ManyDisplay
[
Display
]
deriving
(
Show
,
Typeable
,
Generic
)
instance
Serialize
Display
-- | All state stored in the kernel between executions.
data
KernelState
=
KernelState
...
...
@@ -108,9 +117,9 @@ data EvaluationResult =
-- | An intermediate result which communicates what has been printed thus
-- far.
IntermediateResult
{
outputs
::
[
DisplayData
]
-- ^ Display outputs.
outputs
::
Display
-- ^ Display outputs.
}
|
FinalResult
{
outputs
::
[
DisplayData
]
,
-- ^ Display outputs.
outputs
::
Display
,
-- ^ Display outputs.
pagerOut
::
String
-- ^ Text to display in the IPython pager.
}
src/Main.hs
View file @
51b8ea24
...
...
@@ -252,7 +252,8 @@ replyTo interface req@ExecuteRequest{ getCode = code } replyHeader state = do
header
<-
dupHeader
replyHeader
ClearOutputMessage
send
$
ClearOutput
header
True
sendOutput
outs
=
do
sendOutput
(
ManyDisplay
manyOuts
)
=
mapM_
sendOutput
manyOuts
sendOutput
(
Display
outs
)
=
do
header
<-
dupHeader
replyHeader
DisplayDataMessage
send
$
PublishDisplayData
header
"haskell"
outs
...
...
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