Starting a web browser: Difference between revisions

m
m (→‎{{header|Phix}}: syntax coloured, marked p2js incompatible)
m (→‎{{header|Wren}}: Minor tidy)
 
(6 intermediate revisions by 5 users not shown)
Line 8:
=={{header|EchoLisp}}==
Since we are already in a browser window, the browser is started. '''print-hatml''' sends an html string to the standard output area. The table is styled with the "htable" css class, which is included in EchoLisp.
<langsyntaxhighlight lang="scheme">
;; table from "Separate_the_house_number_from_the_street_name"
;;
(print-html (table->html adresses))
</syntaxhighlight>
</lang>
{{out}}
 
Line 122:
=={{header|Go}}==
This uses the same format and color scheme for the table as the Raku entry.
<langsyntaxhighlight lang="go">package main
 
import (
Line 249:
err = os.Remove(fileName)
check(err)
}</langsyntaxhighlight>
 
{{out}}
Line 255:
Similar to the Raku entry.
</pre>
 
=={{header|J}}==
 
Here, we assume that <code>browser</code> refers to a browser in a format which is usable by a command shell, and <code>din5008</code> and <code>sampledata</code> have been defined according to the [[Separate_the_house_number_from_the_street_name#J|J house number street name]] task entry:
 
<syntaxhighlight lang="j"> wrap=: {{'<',m,'>',y,'</',(;{.;:m),'>' }}(L:0)("1)
'table.htm'fwrite~'<style>tr:nth-child(even){color:blue}</style>','table' wrap ,'tr' wrap ;"1 'td' wrap din5008"1 sampledata
1660
launch browser,' table.htm'</syntaxhighlight>
 
(Here, 1660 was the length of the generated file.)
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">using Tables, BrowseTables
 
function testbrowsertable(addresstext)
Line 324 ⟶ 335:
 
testbrowsertable(adressen)
</syntaxhighlight>
</lang>
 
=={{header|Nim}}==
Based on Phix solution. Using same colors as Scala program.
 
<langsyntaxhighlight Nimlang="nim">import os, strutils
 
func separateHouseNumber(address: string): tuple[street, house: string] =
Line 415 ⟶ 426:
discard execShellCmd("firefox test.html")
os.sleep(5000)
removeFile("test.html")</langsyntaxhighlight>
 
{{out}}
Line 423 ⟶ 434:
Borrowing code from the [[Separate_the_house_number_from_the_street_name|Separate the house number from the street name]] task.
{{trans|Raku}}
<langsyntaxhighlight lang="perl">use File::Temp qw(tempfile);
 
my @addresses = (
Line 498 ⟶ 509:
# wait for a bit to give browser time to load before destroying temp file
sleep 5;
</syntaxhighlight>
</lang>
{{out}}
<table border="2"> <tr bgcolor="#02ccfe"><th>Address</th><th>Street</th><th>House Number</th>
Line 536 ⟶ 547:
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(notonline)-->
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (file i/o, system)</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">addresses</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"Plataanstraat 5"</span><span style="color: #0000FF;">,</span>
Line 641 ⟶ 652:
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</langsyntaxhighlight>-->
output as perl
 
=={{header|Racket}}==
 
<langsyntaxhighlight lang="racket">
#lang at-exp racket
 
Line 665 ⟶ 676:
@table{@render-table}}}
}
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
Line 672 ⟶ 683:
Uses the code from the [[Separate_the_house_number_from_the_street_name|Separate the house number from the street name]] task almost verbatim. Included here to make a complete, runnable example.
 
<syntaxhighlight lang="raku" perl6line>use File::Temp;
 
my $addresses = qq :to /END/;
Line 770 ⟶ 781:
# wait for a bit to give browser time to load before destroying temp file
sleep 5;
</syntaxhighlight>
</lang>
{{out}} Will start the default browser (or open a new tab/window in a running one) and display this table.
<table border="2"> <tr bgcolor="#02ccfe"><th>Address</th><th>Street</th><th>House Number</th>
Line 811 ⟶ 822:
<!-- ==={{libheader|Scala}}=== -->
Uses nothing but the Standard Library:
<langsyntaxhighlight lang="scala">import java.awt.Desktop
import java.io.{IOException, PrintWriter}
import java.net.{URI, ServerSocket}
Line 945 ⟶ 956:
do print("Do you want to shutdown this server? <Y(es)/N>: ") while (!scala.io.StdIn.readBoolean)
sys.exit()
}</langsyntaxhighlight>
{{out}}
<font face="Arial, sans-serif" size="5">Split the house number from the street name</font>
Line 952 ⟶ 963:
=={{header|Tcl}}==
{{works with|Tcl|8.6}}<!--required for [file tempfile]-->
<langsyntaxhighlight lang="tcl">package require Tcl 8.6
 
# This is identical to the address task. Skip forward to the next section...
Line 1,030 ⟶ 1,041:
} else {
exec xdg_open $filename
}</langsyntaxhighlight>
{{out}}
<!-- Strictly, this is just the contents of the <body> inside a <div>… --><div style="margin-left: 50px">
Line 1,039 ⟶ 1,050:
{{libheader|Wren-pattern}}
{{libheader|Wren-fmt}}
{{libheader|Wren-traititerate}}
An embedded program so we can ask the C host to open the browser for us after we've created the html file.
 
The Wren code is based in part on the Nim example and uses the same color scheme.
<langsyntaxhighlight ecmascriptlang="wren">/* starting_web_browserStarting_a_web_browser.wren */
 
import "./pattern" for Pattern
import "./fmt" for Fmt
import "./traititerate" for Indexed
 
foreign class File {
Line 1,165 ⟶ 1,176:
File.flushAll() // flush all streams
C.sleep(5) // wait five seconds
File.remove("test.html") // remove the file</langsyntaxhighlight>
<br>
We now embed this in the following C program, compile and run it.
<langsyntaxhighlight lang="c">/* gcc starting_web_browserStarting_a_web_browser.c -o starting_web_browserStarting_a_web_browser -lwren -lm */
 
#include <stdio.h>
Line 1,303 ⟶ 1,314:
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "starting_web_browserStarting_a_web_browser.wren";
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
Line 1,319 ⟶ 1,330:
free(script);
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 1,325 ⟶ 1,336:
Same as Nim.
</pre>
 
{{omit from|EasyLang}}
9,476

edits