#! /home/xed/xsrexx

/*
 * session_prompt:   call prompt "Message" {, type } {, mes_1 } {, mes2 }
 *
 *           result:    1 = "Continue"            0 = "Cancel"
 *
 *           Type:      'Continue'  <===>  Enter = Continue
 *                      'CAncel'    <===>  Enter = Cancel
 *
 *           call session_prompt "Message" , "c", mes_1, ""    --> One "mes_1" button
 *
 */

signal on novalue
option setenv mixed
address csh

session_prompt:procedure

   parse arg mes, type, mes1, mes2

   lower type
   select
     when type[1:2]  'ca' then
       type = 'cancel'
     when type[1]    'c'  then type = 'continue'
     otherwise                  type = 'continue'
   end

   mes1_0 = mes1
   if mes1 = '' then
    { if type = 'continue' then mes1 = 'Continue'
      else                      mes1 = 'Cancel'
    }
   if mes2 = '' & mes1_0 = '' then
    { if type = 'continue' then mes2 = 'Cancel'
      else                      mes2 = 'Continue'
    }

   call dy_start()
   la1 = max(length(mes), length(mes1)+length(mes2)+2)
   la = max(50, la1+12)
   pos = (la-length(mes))/2
   call dy_label pos, 2, mes
   if mes2 = '' then
    { pos = la/2
      $prompt_1 = dy_button(max(1,pos-length(mes1)/2-1), 4,  mes1)
      $prompt_2 = $prompt_1
    }
   else
    { pos = la/2
      $prompt_1 = dy_button(max(1,pos-12), 4,  mes1)
      $prompt_2 = dy_button(min(la-3, pos+8), 4,  mes2)
    }

   $ret_pr = 0
   $prompt = dy_end("proc_prompt", 0, 0, la, 6.5, "g")
   $prompt_type = type   /* When called by SEDIT as a macro */
   call dy_map $prompt
   call dy_destroy $prompt
return $ret_pr


proc_prompt:        /* Duplicated with proc_prompt.sedit */

parse arg handle reason
  if reason = 'B'$prompt_1 | reason = 'return' then
   { if type = 'continue' then $ret_pr = 1
     else                      $ret_pr = 0
   }

  else if reason = 'B'$prompt_2 then
   { if type = 'continue' then $ret_pr = 0
     else                      $ret_pr = 1
   }
return 0
