The Juno.jl Front-End

Juno provides some functionality using Atom's UI, which will usually have a fallback for use in other environments.

The isactive() function will provide an interface for figuring out whether the current session is running within Juno:

Juno.isactiveFunction.
isactive()

Will return true when the current Julia process is connected to a running Juno frontend.

source

Enhanced Display

Juno.jl includes features which allow package developers to created enhanced displays in Juno.

For example, we can print info to the console in a nicer way:

info("foo")

info

Juno.infoFunction.
info(msg)

Show the given message in Juno's console using blue styling, or fall back to Base.info.

In a package, you can use import Juno: info to replace the default version with this one.

source

or provide structured display for arbitrary objects (similar to Base.dump)

structure

Juno.structureFunction.
structure(x)

Display x's underlying representation, rather than using its normal display method. For example, structure(:(2x+1)) displays the Expr object with its head and args fields instead of printing the expression.

source

Display system

For a types that have no custom rendering defined (see below), Juno's display system will fall back to

To change how Juno displays a type

type CustomType
  field_a
  field_b
end

it's necessary to add a new Juno.render method for that type:

function Juno.render(i::Juno.Inline, x::CustomType)
  Juno.render(i, Juno.Tree(Text(x.field_a), [Text(field_b)]))
end

or, using the more convenient Juno.@render macro, which calls Juno.render on it's first argument (Juno.Inline in this case) and whatever it's body evaluates into:

Juno.@render Juno.Inline x::CustomType begin
  Juno.Tree(Text(x.field_a), [Text(x.field_b)])
end
Juno.render
Juno.@render

custom rendering

Juno.Inline is one of the predefined rendering contexts defined in Juno:

Juno.Inline
Juno.Clipboard
Juno.PlotPane

There are render methods for all the HTML primitives defined in Hiccup.jl as well as for certain higher-level elements from Juno.jl or even Base

Juno.Tree
Juno.LazyTree
Juno.SubTree
Juno.Link
Juno.Table
Juno.Row
Base.Text

Should you wish to render something in the PlotPane, you can get it's dimensions via

Juno.plotsizeFunction.
plotsize()

Get the size of Juno's plot pane in px. Does not yet have a fallback for other environments.

source

Progress Meters

Juno.jl allows package developers to use the progressbar which is provided in the Atom window. For example, you can easily show a progress meter for a for loop via the command:

@progress for ...

progress

The following functions provide this interface:

Juno.@progressMacro.
@progress [name] for i = ...

Show a progress metre for the given loop if possible.

source
Juno.progressFunction.
progress(p::ProgressBar, prog::Number)

Update p's progress to prog.

source
progress(p::ProgressBar)

Set p to an indeterminate progress bar.

source
progress(f::Function; name = "", msg = "")

Evaluates f with p = ProgressBar(name = name, msg = msg) as the argument and calls done(p) afterwards. This is guaranteed to clean up the progress bar, even if f errors.

source
ProgressBar(;name = "", msg = "")

Create a new progress bar and register it with Juno, if possible.

Take care to unregister the progress bar by calling done on it, or use the progress(f::Function) syntax, which will handle that automatically.

source
Juno.nameFunction.
name(p::ProgressBar, m)

Update ps name.

source
Juno.msgFunction.
msg(p::ProgressBar, m)

Update the message that will be displayed in the frontend when hovering over the corrseponding progress bar.

source
Juno.right_textFunction.
right_text(p::ProgressBar, m)

Update the string that will be displayed to the right of the progress bar.

Defaults to the linearly extrpolated remaining time based upon the time difference between registering a progress bar and the latest update.

source
Base.doneFunction.
done(p::ProgressBar)

Remove p from the frontend.

source

It is recommended to either use the @progress macro or the

progress(name = "Foo") do p

end

notation to ensure that the progress bars are properly unregistered in the frontend.

Interaction

Juno.jl lets package developers interact with users via the Atom frontend. For example, you can allow the user to select from a list of options:

Juno.selectorFunction.
selector([xs...]) -> x

Allow the user to select one of the xs.

xs should be an iterator of strings. Currently there is no fallback in other environments.

source

selector

or get input in the console:

Juno.inputFunction.
input() -> "..."

Prompt the user to input some text, and return it.

source

input