summaryrefslogtreecommitdiff
path: root/viewhtml
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2020-08-09 20:57:22 +0200
committerAki <please@ignore.pl>2020-08-09 20:57:22 +0200
commit1946b8aee30fa7e16d49d72215849c9255dfc81b (patch)
tree5516f2f7d3790a8a2168873f24a966a8a22a78c9 /viewhtml
parenta2f3fcc24c71b70f22bd078fab3264a9a9d75e94 (diff)
downloadbrowse-1946b8aee30fa7e16d49d72215849c9255dfc81b.zip
browse-1946b8aee30fa7e16d49d72215849c9255dfc81b.tar.gz
browse-1946b8aee30fa7e16d49d72215849c9255dfc81b.tar.bz2
Implemented naive open-in-window
It actually removed support for new window opening.
Diffstat (limited to 'viewhtml')
-rwxr-xr-xviewhtml44
1 files changed, 28 insertions, 16 deletions
diff --git a/viewhtml b/viewhtml
index 2b6d1fd..82dcac1 100755
--- a/viewhtml
+++ b/viewhtml
@@ -2,7 +2,7 @@
package require tclgumbo
package require Tk
-# TODO: General notes enclose the script into functions, this is ugly right now.
+# TODO: This is still ugly, refactor into functions and namespaces?
# TODO: Scripts now expects all secondary files to be already present. It should request them from protocol daemon
# instead.
# TODO: Actually, both browse and this script are now unaware of each other. This should be priority for now.
@@ -34,12 +34,8 @@ $w tag bind a <Enter> "$w config -cursor hand2"
$w tag bind a <Leave> "$w config -cursor {}"
$w tag bind a <ButtonRelease-1> "click $w %x %y"
-# TODO: Extend argument parsing and handling
-set baseAddress [lindex $argv 1]
-set file [open [lindex $argv 0]]
-set html [read $file]
-close $file
-set output [gumbo::parse $html]
+# TODO: Avoid globals
+variable baseAddress
proc makeAddress {address} {
global baseAddress
@@ -55,15 +51,15 @@ proc makeAddress {address} {
}
proc click {w x y} {
+ global baseAddress
set range [$w tag prevrange href [$w index @$x,$y]]
set address [eval $w get $range]
- exec "./browse" [makeAddress $address]
+ set presult [exec "./phttp" [makeAddress $address]]
+ displayPage $w [lindex $presult 1] [lindex $presult 2]
+ # TODO: In the end it must go through browse and opener anyway, to resolve the protocol and mime.
}
-proc displayNode {node tagList} {
- # TODO: Avoid using global variables.
- global w
-
+proc displayNode {w node tagList} {
set type [gumbo::node_get_type $node]
if {$type == $gumbo::GUMBO_NODE_ELEMENT} {
set tag [gumbo::element_get_tag_name $node]
@@ -83,7 +79,7 @@ proc displayNode {node tagList} {
}
foreach child_node [gumbo::element_get_children $node] {
- displayNode $child_node [concat $tag $tagList]
+ displayNode $w $child_node [concat $tag $tagList]
}
# TODO: Handle margins and blocks better than this.
@@ -102,7 +98,23 @@ proc displayNode {node tagList} {
}
}
-displayNode [gumbo::output_get_root $output] [list]
-$w config -state disabled
-gumbo::destroy_output $output
+proc displayPage {w newBaseAddress filePath} {
+ global baseAddress
+ set baseAddress $newBaseAddress
+
+ set file [open $filePath]
+ set html [read $file]
+ set output [gumbo::parse $html]
+ close $file
+
+ $w config -state normal
+ $w delete 1.0 end
+
+ displayNode $w [gumbo::output_get_root $output] [list]
+
+ $w config -state disabled
+ gumbo::destroy_output $output
+}
+
+displayPage $w [lindex $argv 1] [lindex $argv 0]