
           [42m                                [40m
           [42m      Paragraphs of Text,       [40m
           [42m                                [40m
           [42m      with Style and Colour,    [40m [33;3mby John Collett[0m
           [42m                                [40m
           [42m      on an ARexx screen        [40m
           [42m                                [40m

    
       [1m:) [0m [33m6x9=[0m[32m42 [0m [1m:) [0m [33m6x9=[0m[32m42 [0m [1m:) [0m [33m6x9=[0m[32m42 [0m [1m:) [0m [33m6x9=[0m[32m42 [0m [1m:) [0m [33m6x9=[0m[32m42 [0m [1m:)[0m

    
       Make the most of this ARexx contribution.  It could be my last.
       In search of a new life style, I've got stuck into Modula-2, 
       where the initial learning curve approaches vertical.  If I ever 
       emerge, it may be as a gibbering wreck, unable to communicate.
    
       To my regular readers, if neither of you hears from me for a
       year or so, send out a search party.
    
    [32m----------------------------------------------------------------[31m
    
    [42m Styles and Colours [40m
        
    First, let's investigate the numbers. If you have, say, eight colours
    available, then plain text can appear in seven different colours - the
    other one is your general background.  But you can also have any of the
    colours as local background to a character, word, line, etc.  So you
    can have 56 (8 * 7 or 7 * 8) different methods of displaying plain
    text.  There are seven other possible style settings, so your 56 colour
    arrangements can each appear in eight different styles. I make that 448
    different ways of displaying text - the number of dots in the following
    table multiplied by the number of items in the 'Styles' column.

                     Text colour
                0  1  2  3  4  5  6  7      [4mStyles[0m
            0 [42m    .  .  .  .  .  .  . [40m     Plain                       
            1 [42m .     .  .  .  .  .  . [40m     Underlined                  
     Back-  2 [42m .  .     .  .  .  .  . [40m     Bold                        
     ground 3 [42m .  .  .     .  .  .  . [40m     Italics                     
     colour 4 [42m .  .  .  .     .  .  . [40m     Bold underlined             
            5 [42m .  .  .  .  .     .  . [40m     Italics underlined          
            6 [42m .  .  .  .  .  .     . [40m     Bold Italics                
            7 [42m .  .  .  .  .  .  .    [40m     Bold italics underlined 
                                           
    Now we'll explore ways of implementing some of these. To begin with, we
    can make a selection of colours and styles appear here :

       [1mBold             [3mItalic[0m           [4mUnderlined[0m
       [31mColour 1         [32mColour 2         [33mColour 3[0m
       [30;41mBackground 1[40m     [42mBackground 2[40m     [43mBackground 3[40m

    Various combinations can be made by combining the ANSI codes which
    I have inserted into this text to produce those effects.
    
    It is hardly any more difficult to produce similar results on a CLI
    screen, or in a plain console window opened by an ARexx instruction
    such as : [32mop = open(con,'CON:20/20/400/100/Title/CLOSE','w')[0m
    
    Here's a silly little program which produces 512 different text
    settings, but counts only those in which the background and foreground
    colours differ.  Each line displays its style and colour settings, and
    the answer to Life and Everything. 
    
    Lift it out (including the opening comment line), give it a name, and
    run it with an 'rx' command.  It confirms my arithmetic. The total is
    448.  Press Return in its window or click on its Close gadget to remove
    it.  If you find it painful to watch, put your pointer over its window
    and press Ctrl/C.

    [32m---------------------------------------------------------------[31m
    /* Count the ways */
  
    op = open(con,'CON:180/10/220/200/Counting them.../CLOSE','w')
    csi = '9B'x                      /* Control sequence introducer */
    bo = csi || '1m' ; it = csi || '3m'
    ul = csi || '4m' ; off = csi || '0m'
    n = 0 ; i = 0 ; st.= '' ; lab. = '' ; lab.0 = 'Plain'
    st.1 = bo ; lab.1 = 'Bold'
    st.2 = it ; lab.2 = 'Italics'
    st.3 = ul ; lab.3 = 'Underlined'
    st.4 = bo || it ; lab.4 = 'Bold Italics'
    st.5 = it || ul ; lab.5 = 'Underlined Italics'
    st.6 = bo || ul ; lab.6 = 'Underlined Bold'
    st.7 = bo || ul || it ; lab.7 = 'Underlined Bold Italics'
    do st = 0 to 7                                    /* Style       */
      w = writeln(con,'0A'x || st.st || lab.st || off)    /* Label   */
      do bg = 40 to 47                                /* Background  */
        do co = 30 to 37                              /* Colour      */
          i = i + 1 ; pad = copies(' ',i)
          if bg - co ~= 10 then n = n + 1             /* Increment n */
          str = st.st || csi || bg || ';' || co || 'm'
          str = '   ' || str ||  st bg-40 co-30 pad 42 off
          w = writeln(con,str)                        /*   Display   */
          if i = 8 then i = 0
          end
        end 
      end
    str = 'different forms'
    w = writeln(con,csi || '0;32;40m  ' n str)    /* 448 expected!  */
    r = readch(con)                               /* Wait for close */
    cl = close(con)
    /* End */

   [32m---------------------------------------------------------------[31m    
       
    Similar settings can also be carried out in the more sophisticated
    environment of a window opened via a 'rexxarplib.library' function. 
    Something like :

        [32maddress AREXX '"call CreateHost(HO, PORT)"'[0m    
        [32m.    (other settings as required)[0m
        [32m.[0m
        [32mcall OpenWindow(HO,0,0,640,200, idcmp, flags)[0m 
    
    In the window which this would open, styles can be set by a function
    call such as :

         [32mcall SetFont(HO,"topaz.font",8,style)[31m
    
    Foreground and background colours can be set by :
    
         [32mcall APen(HO,foreground_number)[31m 
    and  [32mcall BPen(HO,background_number)[31m  

    The placement of the text is determined by :
    
         [32mcall Move(HO,x,y)[31m
    
    Its content by : 
    
         [32mcall Text(HO,text)[31m
    
    There are so many details to deal with that if you want to set
    particular style and colour combinations more than just once or twice
    in a program, it is worth your while to set up your own functions to do
    the donkey work for you.  I explored the idea, and in the process
    produced the accompanying ARexx program called 'Style'.  The rest of
    this text is a description of what to expect if you run it, other
    helpful hints, and the complete code of the program itself.

    [42m The Text [40m
    
    A file-requester asks you to select a short file of plain text to work
    on.  You can provide anything you like,  but later on I shall be
    showing a sample set of lines which you might like to borrow to start
    with.  The text must be short, no more than 26 lines.  You will then
    see the selected text, centre screen in a box, and a column of 14
    rectangular gadgets on the right.

    [42m The Gadgets [40m
    
    The top four gadgets contain the characters P, U, B, I.  They stand
    for 'Plain', 'Underline', 'Bold' and 'Italics', and a small
    marker (in colour 3) next to the 'P' shows that 'Plain' is the current
    style.
    
    The next eight gadgets contain the numbers 0 to 7, one for each of the
    colours.  Each number is shown in its own colour, which is why the 0 is
    invisible.  A small marker (in colour 3) next to the '2' shows that
    colour 2 is the current colour.

    [42m Style and colour selection [40m
    
    These 12 gadgets are selected by clicking on them.  While the colour
    gadgets are mutually exclusive (only one selected at a time, with a
    marker next to it), you can choose 1, 2, or even 3 of the style
    settings to operate together.  A click on 'Plain' unsets all others.

    [42m Applying that choice to text [40m
    
    When you have chosen the style and/or colour you want to apply, turn
    your attention to the text.  Which word or phrase do you want to apply
    it to?  Select that text by dragging the mouse through it - just as if
    you were putting a line through it with a pencil to cross it out. Click
    on the first character, drag to the right, and release the mouse over
    the last character. Left to right is intended, but it also seems to
    work if you draw the invisible crossing-out line from right to left. Be
    sure to include the first and last characters, but if you go too far
    beyond them in, for example, underlining, the results may not be quite
    as you intended.  The current setting of style and colour will appear
    on the text you have 'crossed out'.

    [42m The Thirteenth Gadget [40m
    
    If it is like this [[33m·[0m| ], you can set a foreground colour.
    If it is like this [ |[33m·[0m], you can set a background colour.
    You change from one to the other by clicking in the unmarked half.
    If you want black text on a yellow background:
      Click on the right half of gadget 13.
      Click on the colour yellow. 
      Click on the left half of gadget 13.
      Click on the colour black.
    
    [42m A preview of effects [40m
    
    When you have selected the settings you want, before risking them on a
    piece of the text, just click with the mouse anywhere outside the text
    box.  A little message showing the current pointer position will appear
    in the title bar.  It will appear with your current choice(s) in
    action.

    [42m To the rescue : Gadget number 14 [40m
    
    If you make a mistake or change your mind about a line, you can undo
    the whole line - reset it all to 'Plain' and no special colour.
    The last gadget in the column is maked 'R' for 'Reset'.  Click on it
    and then on any line of the text.  The line will reappear as it was
    before you started.

    But when you've done all this - when you've made the text look really
    pretty, dramatic, or subtle, what can you do with it?  Bear in mind
    that, whatever enhancements to the text you can see on the screen, the
    plain text is still there, as you can check at any time by using the 'R'
    gadget as explained above.  Now it's time to be thinking about how to
    create a new version of the text which contains the enhancements
    permanently, able to be reproduced at any time.  It's time to talk
    about ...

    [42m Four simple menu choices [40m

             1  Load plain text
             2  Save with style
             3  View results
             4  Quit
   
    [32m 1 [31m
    Produces a file requester to let you load another short text to work on.
    Check that you have set your style gadgets to 'Plain' before loading in
    the new text - or you might like to see what happens if you don't.

    [32m 2 [31m
    Another file requester, to save the processed text to a temporary file,
    ready for the next stage.  
    
    [32m 3 [31m
    Creates a new window, about the same size as the original text box, and
    displays in that window the new format of the text.  It obtains its
    data from the temporary file which was created in step 2.  (By the way,
    if you want to look at it, that text will be in a readable form, and
    could even be edited by hand if you wished.)

    You may be wondering why a file need be used at all at this stage. 
    Surely the program can just hold the processed stuff in a string array
    before moving on to the next stage?  It could.  But the grand plan is
    that everything under Menu Item 3 is arranged in such a way that it can
    be extracted for use, either on its own (though I don't know why you
    would want to do that) or for insertion into any other program, where
    it can do the text enhancement jobs for which it was designed (assuming
    the availability of a text file as produced by Menu Item 2).

        
    [42m A sample text [40m
    
    The following lines could be lifted out and used with the program if
    you want a readily available sample to work on.

        
            Sample Lines for Work with Style
    
        Some of this text will be underlined.
        This sample will contain something bold.            
        I'll insert some italics here.
        And here I'll merge the above styles in various ways.
        This line and the next will use some of the options
        for setting the colour in which the text appears.
        This whole line will be in colour.
        Here I'll explore some different background settings.
        This whole line will have a background colour.    
        

    When you've played around with it, you might produce something like :
    
      ----------------------------------------------------------
     |           Sample Lines for Work with Style               |
     |                                                          |
     |   Some of this text will be [4munderlined[0m.                  |
     |   This sample will contain something [1mbold[0m.               |
     |   I'll insert some [3mitalics[0m here.                         |
     |   And [1mhere[0m I'll [1;3mmerge[0m the [3;4mabove[0m styles in various ways.  |
     |   This [32mline[31m and the next will use some of the options    |
     |   for setting the [33mcolour[31m in which the text appears.      |
     |   [33mThis whole line will be in colour.[31m                     |
     |   Here I'll [43mexplore[40m some different [41;32mbackground[40;31m settings.  |
     |   [43mThis whole line will have a background colour.[40m         |
     |                                                          |
      ----------------------------------------------------------
    
    [42m A wrinkly one [40m
    
    How about [4moverlapping [3;4mone feature[0;4m and another[0m like this,
    where part of the underlined text is in italics?
    This is possible in the 'Style' program if you go about it like this.
    
    Apply the longest feature first :
    
        How about [4moverlapping one feature and another[0m like this?
    
    Then deal with the second feature inside it (here shown on its own) :
    
        How about overlapping [3mone feature[0m and another like this?
    
    If you try to put the longer feature [4mover[0m the shorter one, you'll have
    problems.
    
    This was the trickiest part of the whole program, but the method I
    worked out seems to handle it as required.  For more details on this or
    other aspects of the program, see the comments which are included in
    the code below.
    
        The 'Style' program is everything below the next line.
      [32m---- End of discussion.  Beginning of program. ----[31m    
    /*                                                     */
    /*           Style and Colours in ARexx texts          */
    /*                                                     */
    /*                   by John Collett                   */
    
    signal on syntax ; signal on error
    
    /* In an emergency, rerun the program with ANY extra argument */
    if arg() ~= 0 then signal "Finish"
    
    /* Load required libraries */
    if ~show('l','rexxarplib.library') then do
     check = addlib('rexxsupport.library',0,-30,0) 
     check = addlib('rexxarplib.library',0,-30,0) 
     end                         
    
    /* Create a port  */                 
    address AREXX '"call CreateHost(HO, PORT)"'    
    if ~show('Ports',HO) then address command 'WaitForPort HO' 
    
    /* Initialisations */
    flags = 'BORDERLESS + WINDOWCLOSE + WINDOWDEPTH'
    idcmp = 'GADGETUP + MOUSEBUTTONS + CLOSEWINDOW + MENUPICK'
    call SetReqColor(HO,BLOCKPEN,6)   /* Affects menu appearance */    
    style = 0 ; fg = 2 ; bg = 0       /* Default settings        */
    foreground = 1                    /* Boolean */
    hite = 230                        /* Peter Bagnato and other U.S.A. 
      users, set hite to 200.  You may also have to make corresponding
      adjustments elsewhere in the program.  I'll let you work it out. */
    
    st.1 = 0 ; st.2 = 1 ; st.3 = 2 ; st.4 = 4        /* Style values */
    
    /* Open the window */
    call OpenWindow(HO,0,0,640,hite,idcmp, flags) 
    call openport(PORT)
    call ActivateWindow(HO)                   
    call ModifyHost(HO,'MOUSEBUTTONS','%l %b %x %y')
    call TitleBar()
    call PlaceGads()
    call SetMenu()

    /* You have an easy option here.  If your source file is always called
    by a given name such as 'Specimen', then uncomment the next line ...  */
    
     /*   fil = 'Specimen' */
    
    /* ... and suppress the next three lines */
    fil = GetFile(150,50,,,"Select a short text file")
    if fil = '' then signal "Finish"
    call TitleBar()                            /* Keeps things tidy */
 
    call PlaceText()
    
    /* Here the program enters the driving loop. It waits for user actions
    and acts on them as it receives them, until the user either quits
    voluntarily or does something unexpected. */
   
    do forever                               
      call waitpkt(PORT)                     
      p = getpkt(PORT)                       
      if p ~== NULL() then do                
        i = getarg(p) ; t = reply(p, 0)                      
        parse var i class gadno rest
        select
          when class = 'CLOSEWINDOW' then signal 'Finish'
          when class = 'GADGETUP' then call Gadget()
          when class = 'MOUSEBUTTONS' then call GetXY()
          when class = 'MENUPICK' then call MenuHandler(gadno)
          otherwise
          end  /* of 'select'         */
        end    /* of 'if ... then do' */
      end      /* of 'do forever'     */
  
    Finish:
      call CloseWindow(HO) ; exit
      syntax: say 'Syntax : ' errortext(rc) '. Line 'sigl ; signal 'Finish'
      error: say "Error " rc sigl ; signal 'Finish'
    
    /* ---------  and all the rest is user-defined functions ---------  */
    
    /* Gadgets : if a gadget is selected, which one is it :
            1  Set style to plain
       2 -  4  Set other styles
       5 - 12  Set a colour
           13  Background or foreground, depending on where clicked.
           14  Reset a line   */
    Gadget:
    if gadno = 1 then do
      call setFont(HO,"topaz.font",8) ; style = 0
      call Rect(0,615,14,619,56)                  /* Styles off */
      call Rect(3,615,14,619,18)                  /* Plain on   */
      end
    else if gadno < 5 then do
      call Rect(0,615,14,619,18)                  /* Plain off  */
      call Rect(3,615,2+gadno*12,619,6+gadno*12)  /* Style on   */
      style = style + st.gadno
      call SetFont(HO,"topaz.font",8,style) ; end
    else if gadno = 13 then do
      parse var rest x y
      foreground = (x < 630)
      on1 = foreground * 3 ; on2 = (~foreground) * 3
      call Rect(on1,625,2+gadno*12,628,6+gadno*12)
      call Rect(on2,632,2+gadno*12,635,6+gadno*12)
      end  
    else if gadno = 14 then call ResetLine()
    else do
     if foreground then fg = gadno - 5 ; else bg = gadno - 5
     call Rect(0,615,62,619,150)                  /* Colours off  */
     call Rect(3,615,2+gadno*12,619,6+gadno*12)   /* Colour on    */
     end
    return
    /* ----------------- */
    
    pat:                                 /* 'print at' for single lines */
      if arg() > 3 then call Pens(arg(4),arg(5))
      call Move(HO,arg(1),arg(2)) ; call Text(HO,arg(3))
     return
    /* ----------------- */    
    
    patset: procedure expose a.          /* 'print at' for a set of lines */
      if arg() > 3 then call Pens(arg(4),0)
      n = arg(3)
      do i = 1 to n
        call Move(HO,arg(1),arg(2)+ (i-1)*8) ; call Text(HO,a.i)
      end
     return
    /* ----------------- */
    
    Pens: call SetAPen(HO,arg(1)) ; call SetBPen(HO,arg(2)) ; return
    /* ----------------- */
    
    GetXY:
     parse var i class gadno x y
    
    /* If outside the text box, just show xy position */
     if x < left | x > right | y < top | y > bottom then do
     call pat(400,8,x y) ; return ; end
    
    /* Handle click-drag-release of mouse on a piece of text */
     x1 = x
     piece = '' ; call waitpkt(PORT) ; p = getpkt(PORT)
     if p ~== NULL() then do
      i = getarg(p) ; t = reply(p, 0) ; parse var i class state x y
      end
      top = starty-6 ; row = ((y-2)%8)-(top%8) ; y1 = top + row * 8 
      row = row + 1 ; x1 = (x1%8) * 8 ; x2 = (x%8) * 8 + 8
      if x2 < x1 then do ; x3 = x2 - 8 ; x2 = x1 + 8 ; x1 = x3 ; end
      c1 = (x1-startx)%8 + 2 ; c2 = (x2-startx)%8
      piece = substr(a.row,c1,c2-c1+1) ; if piece = '' then return
      call pat(x1+4,y1+6,piece,fg,bg)
    
    /* Updating contents of the line : original held in 'a.' */
     ccode = style || fg || bg
     aa = '{' || ccode ; zz = '}'
     b1 = index(copy.row,strip(piece),c1)
     if b1 = 0 then do ; call ReportProblem() ; return ; end
     b2 = b1 + length(piece)
     one = substr(copy.row,1,b1-1)
     two = substr(copy.row,b2)
    
     /* This is where I deal with the problem of an insertion within
    an existing insertion.  My preliminary notes-as-comments are still 
    here in the code.  Make what you will of them.

     Normally :             tttt {123TTTTTTTTTTTT} tttttt
     Problem  :         {   tttt {123TTTTTTTTTTTT} tttttt
     A second '{' occurs before the '}' to close the first.
    
    I sorted it out in the next few nasty lines. */
    
     p1 = lastpos('{',one)
     if pi ~= 0 then do
      p2 = lastpos('}',one)
      if p2 < p1 then do ; one = one || '}'
                           tab = substr(one,p1+1,3)
                           zz = zz || '{' || tab
                           end
      end
    
     copy.row = one || aa || piece || zz || two
     return
    /* ----------------- */

    PlaceGads:
    
    /* Builds the column of 14 gadgets */
     call AddGadget(HO,624,12,1,'P','%l %d')
     call AddGadget(HO,624,24,2,' ','%l %d')
     call SetFont(HO,"topaz.font",8,1) ; call pat(626,31,'U',1,0)   
     call AddGadget(HO,624,36,3,' ','%l %d')
     call SetFont(HO,"topaz.font",8,2) ; call pat(626,43,'B')
     call AddGadget(HO,624,48,4,' ','%l %d')
     call SetFont(HO,"topaz.font",8,4) ; call pat(624,55,'I')
     call SetFont(HO,"topaz.font",8)
     call Rect(3,615,14,619,18)
     do i = 0 to 7
      call AddGadget(HO,624,60+i*12,5+i,i,'%l %d') 
      call pat(626,67+i*12,i,i,0)
     end
     call Rect(3,615,86,619,90)                   /* Default Colour on */
     call Rect(3,624,158,628,162)                 /* Foreground on      */
     call AddGadget(HO,624,156,13,'|','%l %d %x %y') 
     call AddGadget(HO,624,168,14,'R','%l %d')    /* Reset a line */
     call pat(612,67,' ')
     return
    /* ----------------- */

    PlaceText:
    
    /* Two arrays, 'a.' and 'copy.', hold the set of strings, one in their
    plain format, the other with all the style-setting insertions.  */
     call Rect(0,1,13,610,hite)
     op = open(fl,fil,'r')
    do lin = 1 to 28
     a.lin = readln(fl) ; if eof(fl) then leave
    end
    cl = close(fl)
     nlines = lin ; longest = 0
     do i = 1 to nlines 
      a.i = ' ' || a.i || ' ' ; copy.i = a.i 
      longest = max(longest,length(a.i))
      end 
    
    /* The lines are stored. Now patset puts them in place on the screen. */
     startx = 304-longest*4 ; starty = 32
     call patset(startx,starty,nlines,2,bg)
     left = startx-12; top = starty-12 
     right = startx+longest*8 +12 ; bot = starty + nlines * 8
    
    /* A frame round the text. */ 
     call Pens(1,0) ; call Move(HO,left,top) ; call Draw(HO,right,top)
     call Draw(HO,right,bot) ; call Draw(HO,left,bot) 
     call Draw(HO,left,top) ; call Pens(2,0)
     return
    /* ----------------- */

    TitleBar:
     /* Initial top line display. Also needs updating after call to
     Menu or GetFile, to keep it tidy. */
     call Pens(0,0) ; call RectFill(HO,20,1,616,14)
     call pat(100,8,' Adding Style and Colour to Text ',1,2)
     d = date() ; d = left(d,length(d)-5)     
     t = time('c') ; t = left(t,length(t)-2) ; call pat(500,8,d'   't,2,1) 
     return 
    /* ----------------- */
     
    Rect:       /* Used in several places for general screen management */
     call Pens(arg(1),0) ; call RectFill(HO,arg(2),arg(3),arg(4),arg(5))
     call Pens(fg,bg)
     return
    /* ----------------- */

    SetMenu:
     call AddMenu(HO,'Do it with Style   ')
      call AddItem(HO,'Load plain text ','%l %i','L')
      call AddItem(HO,'Save with style ','%l %i','S')    
      call AddItem(HO,'View results    ','%l %i','V')
      call AddItem(HO,'Quit            ','%l %i','Q') 
     return   
    /* ----------------- */
    
    MenuHandler:
     call TitleBar()
     item = arg(1)
     select 
      when item = 0 then do
       fil = GetFile(150,50,,,"Select a short text file")
       if exists(fil) then call PlaceText()
       else r = Request(150,50,"File not found",,"Ok")
       end
      when item = 1 then do
       outfil = GetFile(150,50,,,"Name of output file") ; ok = 1
       if exists(outfil) then do
        str = 'File already exists.  Okay to overwrite?'
        r = Request(150,50,str,,"Yes","No") ; ok = (r = 'OKAY') 
        end
        if ok then call SaveFile()
        end 
    
     /* The action for item 2 is a call to View(), here used as an
    included function, but designed to be easy to lift out for use in
    another program.  Any calls to functions made from within View are to
    its own separately defined port, window, 'pat2' function, etc. so that
    the whole lot can be pulled out as an integrated package. */

      when item = 2 then call View(outfil,left,top,right-left,bot-top)
      when item = 3 then do
       r = Request(150,50,"Really quit?",,"Yes","No")
       if r = "OKAY" then do ; signal "Finish" ; end
       end
      otherwise
      end
      call TitleBar()
    return
    /* ----------------- */
    
    SaveFile:              
      /*This will create a stand-alone file intended to be used by View */
     op = open(out,outfil,'w')
     do i = 1 to nlines
      tx = copy.i ; start = 1 ; zz = 0
      w = writeln(out,a.i)
      do forever
       aa = index(tx,'{',start) 
       if aa ~= 0 then zz = index(tx,'}',aa)
       if aa = 0 then leave
       else w = writeln(out,substr(tx,aa,zz-aa))
       start = zz+1
       end
      end
     cl = close(out)
     return
    /* ----------------- */
    
    ReportProblem:           /* ... a vain attempt to cover ... */
     str = 'Problem found.',
           '\Your selection may have included something already done.',
           '\Remedy : do the longer patch first.',
           '\\Shall I reset the line to its plain form,',
           '\or ignore your last attempt?'
     r = Request(30,50,str,,"Reset it","Ignore")
     call TitleBar()
     if r = 'OKAY' then do
      copy.row = a.row
      call setFont(HO,"topaz.font",8)
      call pat(startx,starty - 8 + row*8,a.row,2,0)
      call setFont(HO,"topaz.font",8,style)
      end
     return
    /* ----------------- */
   
     ResetLine:           
      /* Used by gadget 14.   It waits for a click on a line.
         If you click elsewhere at this point, expect problems. */
      state = ''
      do until state = 'SELECTUP'
      call waitpkt(PORT) ; p = getpkt(PORT)
      if p ~== NULL() then do
       i = getarg(p) ; t = reply(p, 0) ; parse var i class state x y
       end
      end
       row = ((y-2)%8)-(top%8) + 1
       copy.row = a.row
       call setFont(HO,"topaz.font",8)
       call pat(startx,starty - 8 + row*8,a.row,2,0)
       call setFont(HO,"topaz.font",8,style)
     return
        
    /* ----------------------------------------------------------- */
    /* You should be able to cut here, and with a few modifications
       use what follows in another program. */
    /*   */
    View:
    parse arg textfile,left,top,width,height     /* 5 args expected */
    
    /* The host and port names used here MUST be different from those used
    in the parent program.  */
    
    address AREXX '"call CreateHost(HOST, PORT2)"'
    if ~show('Ports',HOST) then address command 'WaitForPort HOST' 
    flags2 = 'WINDOWCLOSE+WINDOWDRAG'
    
    /* These flag settings mean than you can drag the new window around
    and close it when you wish. Our 'height' needs to be incremented to
    allow for the drag bar. */
    
    call OpenWindow(HOST,left,top,width,height+20,'CLOSEWINDOW',flags2) 
    call openport(PORT2) ; call ActivateWindow(HOST)
    fg = 2 ; bg = 0 ; st = 0
    op = open(inf,textfile,'r')
    do i = 1 until eof(inf)
     a.i = readln(inf)
     end
    cl = close(inf)
    /* Your eof character may be at the end of the last line of print, or
    alone on the final line. If the latter, then ... */
    if a.i = '' then i = i - 1    
    
    op = open(ol,'outlist','w')
    x = 8 ; y = 16
    do a = 1 to i
     b = a.a
     if left(b,1) ~= '{' then do
      st = 0 ; call SetFont(HOST,'topaz.font',8)
      current = b ; y = y + 8 ; call pat2(x,y,b,2,0)
      end
     else do 
      st = substr(b,2,1) ; fg = substr(b,3,1) ; bg = substr(b,4,1)
      cuta = right(b,length(b)-4)
      thisx = x + index(current,cuta) * 8 - 8
      call SetFont(HOST,'topaz.font',8,st)
      call pat2(thisx,y,cuta,fg,bg)
      end
     end
    cl = close(ol)
    
    /* A loop to wait for the window to be closed */
    do forever                               
      call waitpkt(PORT2) ; p = getpkt(PORT2)                       
      if p ~== NULL() then do                
        i = getarg(p) ; t = reply(p, 0) ; call CloseWindow(HOST) ; return
        end
      end
    return
    /* ----------------- */
        
    pat2: 
      call SetFont(HOST,'topaz.font',8,st)
      call SetAPen(HOST,arg(4)) ; call SetBPen(HOST,arg(5))
      call Move(HOST,arg(1),arg(2)) ; call Text(HOST,arg(3))
     return
    
              /* ------- End of 'View' ------- */

    /* -----------  Hamilton, New Zealand   November 1995  ------------ */


       [1m:) [0m [33m6x9=[0m[32m42 [0m [1m:) [0m [33m6x9=[0m[32m42 [0m [1m:) [0m [33m6x9=[0m[32m42 [0m [1m:) [0m [33m6x9=[0m[32m42 [0m [1m:) [0m [33m6x9=[0m[32m42 [0m [1m:)[0m


    