| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
IHaskell.Display
Contents
Description
If you are interested in the IHaskell library for the purpose of augmenting the IHaskell notebook or writing your own display mechanisms and widgets, this module contains all functions you need.
In order to create a display mechanism for a particular data type, write a module named (for
example) IHaskell.Display.YourThing in a package named ihaskell-yourThing. (Note the
capitalization - it's important!) Then, in that module, add an instance of IHaskellDisplay for
your data type. Similarly, to create a widget, add an instance of IHaskellWidget.
An example of creating a display is provided in the demo notebook.
Synopsis
- class IHaskellDisplay a where
- data Display
- = Display [DisplayData]
- | ManyDisplay [Display]
- data DisplayData = DisplayData MimeType Text
- class IHaskellDisplay a => IHaskellWidget a where
- printDisplay :: IHaskellDisplay a => a -> IO ()
- plain :: String -> DisplayData
- html :: String -> DisplayData
- png :: Width -> Height -> Base64 -> DisplayData
- jpg :: Width -> Height -> Base64 -> DisplayData
- svg :: String -> DisplayData
- latex :: String -> DisplayData
- javascript :: String -> DisplayData
- many :: [Display] -> Display
- type Width = Int
- type Height = Int
- type Base64 = Text
- encode64 :: String -> Base64
- base64 :: ByteString -> Base64
- switchToTmpDir :: IO ()
- displayFromChanEncoded :: IO ByteString
- serializeDisplay :: Display -> ByteString
- data Widget = IHaskellWidget a => Widget a
Rich display and interactive display typeclasses and types
class IHaskellDisplay a where #
A class for displayable Haskell types.
IHaskell's displaying of results behaves as if these two overlapping/undecidable instances also existed:
instance (Show a) => IHaskellDisplay a instance Show a where shows _ = id
Minimal complete definition
Instances
| IHaskellDisplay DisplayData # | |
Defined in IHaskell.Display Methods display :: DisplayData -> IO Display # | |
| IHaskellDisplay Display # | |
| IHaskellDisplay Widget # | |
| IHaskellDisplay a => IHaskellDisplay [a] # | |
Defined in IHaskell.Display | |
| IHaskellDisplay a => IHaskellDisplay (IO a) # | these instances cause the image, html etc. which look like: Display [Display] IO [Display] IO (IO Display) be run the IO and get rendered (if the frontend allows it) in the pretty form. |
Wrapper for ipython-kernel's DisplayData which allows sending multiple results from the same expression.
Constructors
| Display [DisplayData] | |
| ManyDisplay [Display] |
Instances
| Show Display # | |
| Generic Display # | |
| Semigroup Display # | |
| Monoid Display # | |
| Serialize Display # | |
| IHaskellDisplay Display # | |
| type Rep Display # | |
Defined in IHaskell.Types type Rep Display = D1 (MetaData "Display" "IHaskell.Types" "ihaskell-0.9.0.3-kG6bDbQGIcK8UUxx08sXn" False) (C1 (MetaCons "Display" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [DisplayData])) :+: C1 (MetaCons "ManyDisplay" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Display]))) | |
data DisplayData #
Data for display: a string with associated MIME type.
Constructors
| DisplayData MimeType Text |
Instances
| Show DisplayData | |
Defined in IHaskell.IPython.Types Methods showsPrec :: Int -> DisplayData -> ShowS # show :: DisplayData -> String # showList :: [DisplayData] -> ShowS # | |
| Generic DisplayData | |
Defined in IHaskell.IPython.Types Associated Types type Rep DisplayData :: * -> * # | |
| Serialize DisplayData | |
Defined in IHaskell.IPython.Types | |
| IHaskellDisplay DisplayData # | |
Defined in IHaskell.Display Methods display :: DisplayData -> IO Display # | |
| type Rep DisplayData | |
Defined in IHaskell.IPython.Types type Rep DisplayData = D1 (MetaData "DisplayData" "IHaskell.IPython.Types" "ipython-kernel-0.9.0.2-JaeIZ9msj9jGFqD0IxNCb" False) (C1 (MetaCons "DisplayData" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 MimeType) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Text))) | |
class IHaskellDisplay a => IHaskellWidget a where #
Display as an interactive widget.
Minimal complete definition
Methods
targetName :: a -> String #
Target name for this widget. The actual input parameter should be ignored. By default evaluate to "jupyter.widget", which is used by IPython for its backbone widgets.
targetModule :: a -> String #
Target module for this widget. Evaluates to an empty string by default.
getCommUUID :: a -> UUID #
Get the uuid for comm associated with this widget. The widget is responsible for storing the UUID during initialization.
Arguments
| :: a | Widget to open a comm port with. |
| -> (Value -> IO ()) | A function for sending messages. |
| -> IO () |
Called when the comm is opened. Allows additional messages to be sent after comm open.
Arguments
| :: a | Widget which is being communicated with. |
| -> Value | Data recieved from the frontend. |
| -> (Value -> IO ()) | Way to respond to the message. |
| -> IO () |
Respond to a comm data message. Called when a message is recieved on the comm associated with the widget.
Called when a comm_close is recieved from the frontend.
Interactive use functions
printDisplay :: IHaskellDisplay a => a -> IO () #
Write to the display channel. The contents will be displayed in the notebook once the current execution call ends.
Constructors for displays
plain :: String -> DisplayData #
Generate a plain text display.
html :: String -> DisplayData #
Generate an HTML display.
png :: Width -> Height -> Base64 -> DisplayData #
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.
jpg :: Width -> Height -> Base64 -> DisplayData #
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.
svg :: String -> DisplayData #
Generate an SVG display.
latex :: String -> DisplayData #
Generate a LaTeX display.
javascript :: String -> DisplayData #
Generate a Javascript display.
Image and data encoding functions
base64 :: ByteString -> Base64 #
Convert from a ByteString into base 64 encoded data.
Utilities
switchToTmpDir :: IO () #
Convenience function for client libraries. Switch to a temporary directory so that any files we create aren't visible. On Unix, this is usually /tmp.
Internal only use
displayFromChanEncoded :: IO ByteString #
Take everything that was put into the displayChan at that point out, and make a Display out
of it.
serializeDisplay :: Display -> ByteString #
For internal use within IHaskell. Serialize displays to a ByteString.
Constructors
| IHaskellWidget a => Widget a |
Orphan instances
| IHaskellDisplay DisplayData # | |
Methods display :: DisplayData -> IO Display # | |
| IHaskellDisplay Display # | |
| IHaskellDisplay a => IHaskellDisplay [a] # | |
| IHaskellDisplay a => IHaskellDisplay (IO a) # | these instances cause the image, html etc. which look like: Display [Display] IO [Display] IO (IO Display) be run the IO and get rendered (if the frontend allows it) in the pretty form. |