[comp.lang.icon] snapshot; readability

goer@ellis.uchicago.edu (Richard L. Goerwitz) (03/23/91)

I'm not claiming that this is particularly elegant, or even correct.
I just hacked it together this morning because I have a doc in which
90% of the strings don't fit on my terminal, and which snapshot(),
as it is in the IPL, produces an unreadable display.

Does anyone, in principle, have any objection to snapshot having a
notion of display length?

-Richard


----------

procedure snapshot(title,len)

   local bar1, bar2, bar3, is, is0, prefix, titlel, placement, POS

   /title := ""
   prefix := "&subject = "
   is := image(&subject)
   is0 := *image(&subject[1:&pos]) | fail # quick exit if bogus

   #
   # Set up top and bottom bars (not exceeding len width, if
   # len is nonnull).  Fit title into top bar (bar1).
   #
   bar1 := bar3 := repl("-", *is + *prefix + 4)[1:\len-4|0]
   # in *is + *prefix + 4, the 4 is for two vbars/two spaces
   titlel := (*title > *bar3-4) | *title[1:\len-4|0]
   bar1[3+:titlel] := title[1+:titlel]


   #
   # Write bar1, then a spacer (bar2).  Then write out len-size chunks
   # of &subject, with the | pointer-line, where appropriate. Finally,
   # write out bar3.
   #
   write(bar1)
   write(bar2 := ("|" || repl(" ", *bar1 - 2) || "|"),"\n",bar2)
   placement := *prefix + is0
   (prefix || is) ? {
       until pos(0) do {
	   POS := &pos - 1
	   write("| ", move(*bar3-4) | left(tab(0), *bar3-4), " |")
	   if POS < placement <= &pos then {
	       writes("| ")
	       writes(left(repl(" ", placement - POS) || "|", *bar3-4))
	       write(" |\n",bar2)
	   }
	   else write(bar2,"\n",bar2)
       }
   }
   write(bar3)
   return			# nothing to return

end