Custom display printers
Custom display printers can be added during runtime based off of type.
Example for providing a custom display printer for float
to display a pink div:
1: 2: 3: 4: 5: 6: |
App.AddDisplayPrinter(fun (x:float) -> { ContentType = "text/html" Data = "<div style=\"background-color: pink\">" + x.ToString() + "</div>" } ) |
To invoke the printer:
1:
|
1.0 |> Display |
Will render
1
Custom fsi printers
Similarly, FSI printers can be added which can provide display a string for a type.
However, a more complex implementation could send display data directly to the client
as a side-effect, which will skip the need for calling the Display
function directly
from the notebook. Example:
1: 2: 3: 4: |
App.AddFsiPrinter(fun (x:float) -> App.Kernel.Value.SendDisplayData("text/html", "<div style=\"background-color: pink\">" + x.ToString() + "</div>") x.ToString() ) |
Now, executing a cell with the following code:
1:
|
1.0
|
Will render as:
1
However, executing a cell with the following code:
1:
|
[1.0; 2.0; 3.0;] |
Will render as:
1
2
3
module App
from IfSharp.Kernel
from IfSharp.Kernel
val AddDisplayPrinter : (('a -> BinaryOutput) -> unit)
Full name: IfSharp.Kernel.App.AddDisplayPrinter
Full name: IfSharp.Kernel.App.AddDisplayPrinter
val x : float
Multiple items
val float : value:'T -> float (requires member op_Explicit)
Full name: Microsoft.FSharp.Core.Operators.float
--------------------
type float = System.Double
Full name: Microsoft.FSharp.Core.float
--------------------
type float<'Measure> = float
Full name: Microsoft.FSharp.Core.float<_>
val float : value:'T -> float (requires member op_Explicit)
Full name: Microsoft.FSharp.Core.Operators.float
--------------------
type float = System.Double
Full name: Microsoft.FSharp.Core.float
--------------------
type float<'Measure> = float
Full name: Microsoft.FSharp.Core.float<_>
namespace Microsoft.FSharp.Data
System.Double.ToString() : string
System.Double.ToString(provider: System.IFormatProvider) : string
System.Double.ToString(format: string) : string
System.Double.ToString(format: string, provider: System.IFormatProvider) : string
System.Double.ToString(provider: System.IFormatProvider) : string
System.Double.ToString(format: string) : string
System.Double.ToString(format: string, provider: System.IFormatProvider) : string
val Display : ('a -> unit)
Full name: IfSharp.Kernel.Globals.Globals.Display
Full name: IfSharp.Kernel.Globals.Globals.Display
val AddFsiPrinter : (('a -> string) -> unit)
Full name: IfSharp.Kernel.App.AddFsiPrinter
Full name: IfSharp.Kernel.App.AddFsiPrinter
val mutable Kernel : Option<IfSharpKernel>
Full name: IfSharp.Kernel.App.Kernel
Full name: IfSharp.Kernel.App.Kernel