Did you know ... Search Documentation:
Pack webconsole -- prolog/webconsole.pl
PublicShow source

The library(webconsole) allows for writing classical query/reply programs that use a web-browser for I/O. In the typical user scenarion, the application calls wc_start/0 to open a browser. Next, it calls one of wc_format/2,3,4 or wc_html/1,2 to send output to the browser and or calls wc_ask/2,4 to request data from the user.

The home-page can be customized by defining a handler for wc_home. See wc_home/1 for the default page.

Here is an example run:

?- [library(webconsole)].
?- wc_start.				% opens browser
?- wc_format('Hello ~w', [world]).
?- wc_html(p(['Hello ', b(world)])).
?- wc_ask([age(Age)], [p('How old are you'), input([name(age)])]).
Age = 24.				% type 24 <enter>
 wc_start is det
 wc_start(+Options) is det
Start the webconsole. This opens your browser using www_open_url/1. Options processed:
Title for window and h1 header
Only allow connections whose peer unify to IP. IP is a term IP(A,B,C,D), where A,B,C,D are integers in the range 0..255.

The user can customize the output page by defining an HTTP handler with the id wc_home (see http_handler/3). The predicate wc_home/1 provides the simple default page.

 wc_output_area(+Options)// is det
Creates a webconsole div element. Multiple output areas can be created, each with their own id. The default id is wc_output.
 wc_format(+Format, +Args) is det
 wc_format(+WCId, +Format, +Args) is det
 wc_format(+WCId, +Format, +Args, +Options) is det
Formats a string (like format/3) to the web console. For example:
?- wc_format('Hello ~w', [world]).


If true, clear the output area before adding the new content.
WCId- is the identifier of the output area. Default is wc_output.
Format- and Args are passed to format/3.
 wc_html(+HTML) is det
 wc_html(+WCId, +HTML) is det
 wc_html(+WCId, +HTML, +Options) is det
Adds an HTML element to the output area. HTML must be valid input for html//1 from library(http/html_write). For example:
?- wc_write([p(['Hello ', b(world)])]).


If true, clear the output area before adding the new content.
Create an output area for errors and warnings. This is a normal output area, using the identifier ic_error.
Create a form-area. This is a div holding a form with ID wc_form. A form-area is used with wc_ask/3 and wc_ask/4.
 wc_ask(-Result, +Specification) is det
 wc_ask(+InputId, -Result, +Specification, +Options) is det
Ask a question. Result is a list Name(Value). Specification is an HTML specification (as wc_html/1, see also html//1) which is used as the content for a form element. Each Name in the Result list must be covered by an equally named input element in the form.
?- wc_ask([ age(Age)
          [ p('How old are you?'),
Age = 24.
Options- is currently ignored
See also
- We need a form that doesn't submit. Generic code I found sofar is http://www.9lessons.info/2011/09/submit-form-without-refreshing-page.html

Undocumented predicates

The following predicates are exported, but not or incorrectly documented.

 wc_format(Arg1, Arg2, Arg3)
 wc_format(Arg1, Arg2, Arg3, Arg4)
 wc_html(Arg1, Arg2)
 wc_html(Arg1, Arg2, Arg3)
 wc_ask(Arg1, Arg2, Arg3, Arg4)