<jupyter_start><jupyter_text>The `OutputWidget` The output widget can be used to display rich output. `IHaskell.Display` provides functions to create such rich displays from raw data.<jupyter_code>{-# LANGUAGE OverloadedStrings #-}
import IHaskell.Display.Widgets
import IHaskell.Display
:t plain
:t html
:t jpg
:t svg
:t latex
:t javascript
:t many
o <- mkOutput
o<jupyter_output><empty_output><jupyter_text>We can append plaintext either to the stdout or the stderr with `appendStdout` and `appendStderr`. We can also clear the output widget with `clearOutput`.<jupyter_code>clearOutput o
appendStdout o "Hello World!"
appendStderr o "Goodbye World!"<jupyter_output><empty_output><jupyter_text>If you want to display anything other than text you'll have to use the `appendDisplay` function, which allows you to display anything displayable (i.e. anything of the `IHaskellDisplay` class)<jupyter_code>:t appendDisplay
imgurl <- mkImage
setField imgurl ImageFormat IURL
setField imgurl BSValue "https://imgs.xkcd.com/comics/functional.png"
appendDisplay o imgurl<jupyter_output><empty_output><jupyter_text>We can append rich text using the `html` function, that transforms a `String` string to `DisplayData`. Pretty cool, isn't it?<jupyter_code>import Text.Printf
o <- mkOutput -- Make output widget
o -- Display output widget

fmt = "<font color=\"%s\"><marquee direction=\"%s\" style=\"background:%s\">%s</marquee></font>"
add fg bg dir txt = appendDisplay o $ html $ printf fmt fg dir bg txt

add "WHITE" "RED" "left" "The <b>OUTPUT</b> Widget"
add "WHITE" "BLUE" "right" "Is really <b>SIMPLE</b>"
add "WHITE" "GREEN" "left" "Use it as an <b>UPDATABLE</b> display</b>"<jupyter_output><empty_output><jupyter_text>The output widget is able to display *anything*, even **widgets**!<jupyter_code>-- Creating the output widget
o <- mkOutput
o

-- Making a button
button <- mkButton
setField button Description "Hi!"

-- Appending the button to the display
appendDisplay o button<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11016949152542373, 'fraction_numerical': 0.0, 'mean_word_length': 5.873287671232877, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 32, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '49035', 'license': 'MIT', 'n_tokens_mistral': 664, 'n_tokens_neox': 642, 'n_words': 226, 'path': 'ihaskell-display/ihaskell-widgets/Examples/Output Widget.ipynb', 'repo_name': 'brandon-leapyear/IHaskell', 'size': '2006'}