Starting a web browser: Difference between revisions
Content added Content deleted
(J) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 8: | Line 8: | ||
=={{header|EchoLisp}}== |
=={{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. |
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. |
||
< |
<syntaxhighlight lang="scheme"> |
||
;; table from "Separate_the_house_number_from_the_street_name" |
;; table from "Separate_the_house_number_from_the_street_name" |
||
;; |
;; |
||
(print-html (table->html adresses)) |
(print-html (table->html adresses)) |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
Line 122: | Line 122: | ||
=={{header|Go}}== |
=={{header|Go}}== |
||
This uses the same format and color scheme for the table as the Raku entry. |
This uses the same format and color scheme for the table as the Raku entry. |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 249: | Line 249: | ||
err = os.Remove(fileName) |
err = os.Remove(fileName) |
||
check(err) |
check(err) |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 260: | Line 260: | ||
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: |
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 |
'table.htm'fwrite~'<style>tr:nth-child(even){color:blue}</style>','table' wrap ,'tr' wrap ;"1 'td' wrap din5008"1 sampledata |
||
1660 |
1660 |
||
launch browser,' table.htm'</ |
launch browser,' table.htm'</syntaxhighlight> |
||
(Here, 1660 was the length of the generated file.) |
(Here, 1660 was the length of the generated file.) |
||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
< |
<syntaxhighlight lang="julia">using Tables, BrowseTables |
||
function testbrowsertable(addresstext) |
function testbrowsertable(addresstext) |
||
Line 335: | Line 335: | ||
testbrowsertable(adressen) |
testbrowsertable(adressen) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
Based on Phix solution. Using same colors as Scala program. |
Based on Phix solution. Using same colors as Scala program. |
||
< |
<syntaxhighlight lang="nim">import os, strutils |
||
func separateHouseNumber(address: string): tuple[street, house: string] = |
func separateHouseNumber(address: string): tuple[street, house: string] = |
||
Line 426: | Line 426: | ||
discard execShellCmd("firefox test.html") |
discard execShellCmd("firefox test.html") |
||
os.sleep(5000) |
os.sleep(5000) |
||
removeFile("test.html")</ |
removeFile("test.html")</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 434: | Line 434: | ||
Borrowing code from the [[Separate_the_house_number_from_the_street_name|Separate the house number from the street name]] task. |
Borrowing code from the [[Separate_the_house_number_from_the_street_name|Separate the house number from the street name]] task. |
||
{{trans|Raku}} |
{{trans|Raku}} |
||
< |
<syntaxhighlight lang="perl">use File::Temp qw(tempfile); |
||
my @addresses = ( |
my @addresses = ( |
||
Line 509: | Line 509: | ||
# wait for a bit to give browser time to load before destroying temp file |
# wait for a bit to give browser time to load before destroying temp file |
||
sleep 5; |
sleep 5; |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<table border="2"> <tr bgcolor="#02ccfe"><th>Address</th><th>Street</th><th>House Number</th> |
<table border="2"> <tr bgcolor="#02ccfe"><th>Address</th><th>Street</th><th>House Number</th> |
||
Line 547: | Line 547: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
<!--< |
<!--<syntaxhighlight lang="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;">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> |
<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 652: | Line 652: | ||
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span> |
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span> |
||
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span> |
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
output as perl |
output as perl |
||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
< |
<syntaxhighlight lang="racket"> |
||
#lang at-exp racket |
#lang at-exp racket |
||
Line 676: | Line 676: | ||
@table{@render-table}}} |
@table{@render-table}}} |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
Line 683: | Line 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. |
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. |
||
<lang |
<syntaxhighlight lang="raku" line>use File::Temp; |
||
my $addresses = qq :to /END/; |
my $addresses = qq :to /END/; |
||
Line 781: | Line 781: | ||
# wait for a bit to give browser time to load before destroying temp file |
# wait for a bit to give browser time to load before destroying temp file |
||
sleep 5; |
sleep 5; |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} Will start the default browser (or open a new tab/window in a running one) and display this table. |
{{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> |
<table border="2"> <tr bgcolor="#02ccfe"><th>Address</th><th>Street</th><th>House Number</th> |
||
Line 822: | Line 822: | ||
<!-- ==={{libheader|Scala}}=== --> |
<!-- ==={{libheader|Scala}}=== --> |
||
Uses nothing but the Standard Library: |
Uses nothing but the Standard Library: |
||
< |
<syntaxhighlight lang="scala">import java.awt.Desktop |
||
import java.io.{IOException, PrintWriter} |
import java.io.{IOException, PrintWriter} |
||
import java.net.{URI, ServerSocket} |
import java.net.{URI, ServerSocket} |
||
Line 956: | Line 956: | ||
do print("Do you want to shutdown this server? <Y(es)/N>: ") while (!scala.io.StdIn.readBoolean) |
do print("Do you want to shutdown this server? <Y(es)/N>: ") while (!scala.io.StdIn.readBoolean) |
||
sys.exit() |
sys.exit() |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<font face="Arial, sans-serif" size="5">Split the house number from the street name</font> |
<font face="Arial, sans-serif" size="5">Split the house number from the street name</font> |
||
Line 963: | Line 963: | ||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
||
{{works with|Tcl|8.6}}<!--required for [file tempfile]--> |
{{works with|Tcl|8.6}}<!--required for [file tempfile]--> |
||
< |
<syntaxhighlight lang="tcl">package require Tcl 8.6 |
||
# This is identical to the address task. Skip forward to the next section... |
# This is identical to the address task. Skip forward to the next section... |
||
Line 1,041: | Line 1,041: | ||
} else { |
} else { |
||
exec xdg_open $filename |
exec xdg_open $filename |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<!-- Strictly, this is just the contents of the <body> inside a <div>… --><div style="margin-left: 50px"> |
<!-- Strictly, this is just the contents of the <body> inside a <div>… --><div style="margin-left: 50px"> |
||
Line 1,054: | Line 1,054: | ||
The Wren code is based in part on the Nim example and uses the same color scheme. |
The Wren code is based in part on the Nim example and uses the same color scheme. |
||
< |
<syntaxhighlight lang="ecmascript">/* starting_web_browser.wren */ |
||
import "./pattern" for Pattern |
import "./pattern" for Pattern |
||
Line 1,176: | Line 1,176: | ||
File.flushAll() // flush all streams |
File.flushAll() // flush all streams |
||
C.sleep(5) // wait five seconds |
C.sleep(5) // wait five seconds |
||
File.remove("test.html") // remove the file</ |
File.remove("test.html") // remove the file</syntaxhighlight> |
||
<br> |
<br> |
||
We now embed this in the following C program, compile and run it. |
We now embed this in the following C program, compile and run it. |
||
< |
<syntaxhighlight lang="c">/* gcc starting_web_browser.c -o starting_web_browser -lwren -lm */ |
||
#include <stdio.h> |
#include <stdio.h> |
||
Line 1,330: | Line 1,330: | ||
free(script); |
free(script); |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |