diff options
author | Aki <please@ignore.pl> | 2020-08-09 20:57:22 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2020-08-09 20:57:22 +0200 |
commit | 1946b8aee30fa7e16d49d72215849c9255dfc81b (patch) | |
tree | 5516f2f7d3790a8a2168873f24a966a8a22a78c9 /viewhtml | |
parent | a2f3fcc24c71b70f22bd078fab3264a9a9d75e94 (diff) | |
download | browse-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-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] |