From 1946b8aee30fa7e16d49d72215849c9255dfc81b Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 9 Aug 2020 20:57:22 +0200 Subject: Implemented naive open-in-window It actually removed support for new window opening. --- viewhtml | 44 ++++++++++++++++++++++++++++---------------- 1 file 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 "$w config -cursor hand2" $w tag bind a "$w config -cursor {}" $w tag bind a "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] -- cgit v1.1