;************************************************************************
;**                  for   B R I E F   ver. 2.1                         *
;**                                                                     *
;**                clrset - Quick color selection                       *
;**                                                                     *
;**         By Tom Bentley     November 1988     Ver. 1.1               *
;**                                                                     *
;**                 (C) Copyright - All rights reserved                 *
;**                                                                     *
;************************************************************************


(extern    clr_buf_mnu clr_buf_ids clr_flag  clr_last_mnu window_color_flag)

(macro clrset
   (
      (int      curr_buff clr_line key_char work_char)
      (string  cmd buf_strg)       

      (if (== clr_buf_mnu 0)
         (return 0)
      )
      (= clr_line 1)
      (= clr_line (set_clr clr_line))
      (message "CLRSET : Use UP/DOWN arrows - ESC quits")
      (= key_char 0)
      (while (&& (!= 27 key_char) (!= 13 key_char))
         (
            (while (! (inq_kbd_char)))
            (= work_char (read_char))
            (= key_char (& work_char 0xff))
            (if (== work_char 18432)
               (
                  (-- clr_line)
                  (= clr_line (set_clr clr_line))
               )
            )
            (if (== work_char 20480)
               (
                  (++ clr_line)
                  (= clr_line (set_clr clr_line))
               )
            )
         )
      )
      (= curr_buff (inq_buffer))
      (set_buffer clr_buf_mnu)
      (goto_line clr_line)
      (= cmd (trim (read)))
      (set_buffer clr_buf_ids)
      (goto_line 1)
      (sprintf buf_strg "<%d" curr_buff)
      (if (search_fwd buf_strg)
         (
            (delete_line)
         )
      )
      (goto_line 1)
      (execute_macro "open_line")
      (sprintf buf_strg "%d" curr_buff)
      (insert buf_strg)
      (insert (substr cmd (index cmd ";")))
      (set_buffer curr_buff)
      (message "Color Set")
   )
)

(macro set_clr
   (
      (int     clr_line curr_buff cmd_start cmd_length)
      (string  cmd)

      (get_parm 0 clr_line)
      (= curr_buff (inq_buffer))
      (set_buffer clr_buf_mnu)
      (if (== clr_line 0)
         (
            (= clr_line clr_last_mnu)
            (-- clr_line)
         )
      )
      (goto_line clr_line)
      (if (inq_position clr_line)
         (= clr_line 1)
      )
      (goto_line clr_line)
      (= cmd (trim (read)))
      (set_buffer curr_buff)
      (if (inq_borders)
         (
            (= cmd_start (+ (index cmd ";") 1))
            (= cmd_length (- (rindex cmd ";") cmd_start))
            (execute_macro (substr cmd cmd_start cmd_length))
         )
      ;else
         (
            (switch window_color_flag
              1
               (
                  (inq_window_color)
                  (window_color (atoi (substr cmd (+ (rindex cmd ";") 1))))
               )
              2
               (
                  (inq_window_color)
                  (window_color)
               )
            )
         )
      )
      (message "Color set to: %d %s" clr_line
         (substr cmd 1 (- (index cmd ";" ) 1)))
      (returns clr_line)
   )
)
