diff options
-rwxr-xr-x | viewhtml | 44 |
1 files changed, 28 insertions, 16 deletions
@@ -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] |