Version 6 of A little NNTP reader

Updated 2005-04-08 15:38:11 by escargo

if 0 {Richard Suchenwirth 2005-02-14 - After AOL told me they were'nt supporting their bad NNTP news reader any more, I couldn't help but look around, read the nntp man page, and hack together this ultra- simple news reader, only for the comp.lang.tcl newsgroup.

In the listbox on top, you see the last 64 messages (descending, by number). Click on one to have it rendered in the text below. This is very minimal, but feel free to add your own bells and whistles :D }

 package require Tk
 package require nntp

 proc main argv {
    global n
    set host

    pack [panedwindow .p -ori vert] -fill both -expand 1
    .p add [frame .x]
    pack [scrollbar .x.y -command ".x.l yview"] -fill y -side right
    pack [listbox .x.l -yscrollc ".x.y set"] -fill both -expand 1 -side right
    set n [nntp::nntp $host]
    #$n authinfo $user $password ;#-- not needed for
    foreach {num from to group} [$n group comp.lang.tcl] break
    for {set i $to} {$i>$to-64} {incr i -1} {
        set head [$n head $i]
        .x.l insert end [list $i [get Subject: $head] [get From: $head]]
    bind .x.l <ButtonRelease-1> {fetch .f.t [selection get]}

    .p add [frame .f]
    pack [scrollbar .f.y -command ".f.t yview"] -fill y -side right
    pack [text .f.t -wrap word -yscrollc ".f.y set"\
        -padx 5 -pady 3 -height 12 -font {Helvetica 9}] \
        -fill both -expand 1 -side right
    foreach color {red blue} {.f.t tag configure $color -foreground $color}
    display .f.t [$n article $to]
 proc fetch {w what} {
    display $w [$::n article [lindex $what 0]]

#-- Extract a field from an article

 proc get {what where} {
    foreach line $where {
        if [string match $what* $line] {
            return [string map [list $what ""] $line]
 proc display {w article} {
    $w delete 1.0 end
    $w insert end [get Subject: $article]\n red
    $w insert end [get From: $article]\n blue
    set inbody 0
    foreach line $article {
        if $inbody {$w insert end $line\n}
        if {$line eq ""} {set inbody 1}

 main $argv
 bind . <Escape> {exec wish $argv0 &; exit}
 bind . <F1> {console show}

if 0 { 2005-04-01: RS, updated to use a free server that provides comp.lang.tcl - thanks miguel for the hint!

if 0 { rdt I like this little thing. I made a couple of minor changes in two lines (in my copy):

 if 0 {
 # in main:
 # foreach color {red blue} {.f.t tag configure $color -foreground $color   ;# becomes:
 foreach color {red blue brown4} {.f.t tag configure $color -foreground $color

  # in display:
  # if $inbody {$w insert end $line\n}   ;# becomes:
    if $inbody {$w insert end $line\n [expr {([regexp {^>+} $line]) ? "brown4" : ""}]}

escargo I like this too. One of my modifications is small, but useful. I added a line to the fetch proc to mark the articles that I've read (red implies read).

 proc fetch {w what} {
     .x.l itemconfigure [.x.l curselection] -foreground red
     display $w [$::n article [lindex $what 0]]


Category Application | Category Internet | Arts and crafts of Tcl-Tk programming }