🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.readers
1 messages
1 total messages Started by da... John E. Davis Wed, 22 Apr 1998 00:00
slrn color editing macro
#40315
Author: da... John E. Davis
Date: Wed, 22 Apr 1998 00:00
186 lines
4570 bytes

Hi,

   Here is an slrn macro (actually a set of functions) that may be
used to facilite designing an slrn color scheme.  It also provides a
simple illustration of the use linked lists in the S-Lang language.
The main function is called `edit_colors', which you can bind to a
key.  Actually, I use the function:

   define execute_slang ()
   {
      variable str = read_mini ("S-Lang",  "", "");
      if (strlen (str)) eval (str);
   }

and bind it to keys (Ctrl-K d) via:

   definekey ("execute_slang", "^Kd", "group");
   definekey ("execute_slang", "^Kd", "article");

This permits me to run slang commands from a command line via Ctrl-K d.
In other words, at this prompt, I type `edit_colors' to run the macro.

A version of this macro will be included in the macro directory of
next release of slrn.  For now, save it to "color.sl" and add the line

   interpret "color.sl"

to your personal .slrnrc file.  Feel free to improve on this.

--------- color.sl -------------------------------------------

variable Color_List_Root = NULL;

define color_save_colors_to_file ()
{
   variable file;
   variable fp;
   variable x;

   if (Color_List_Root == NULL)
     return;

#ifdef UNIX
   file = ".slrnrc";
#else
   file = "slrn.rc";
#endif

   if (1 != get_yes_no_cancel ("Save colors"))
     return;
   
   file = make_home_filename (file);
   file = read_mini ("Save colors to", "", file);
   !if (strlen (file))
     return;
   
   fp = fopen (file, "a");
   if (fp == NULL)
     verror ("Unable to open %s", file);

   x = Color_List_Root;
   while (x != NULL)
     {
	if ((x.fg != NULL) and (x.bg != NULL))
	  () = fputs (sprintf ("color\t%s\t%s\t%s\n", x.obj, x.fg, x.bg), fp);
	x = x.next;
     }
   
   () = fclose (fp);
}

define color_store_color (obj, fg, bg)
{
   variable x;
   
   x = Color_List_Root;
   while (x != NULL)
     {
	if (x.obj == obj)
	  break;
	
	x = x.next;
     }
   if (x == NULL) 
     {
	x = struct { obj, fg, bg, next };
	x.next = Color_List_Root;
	Color_List_Root = x;
	x.obj = obj;
     }
   
   x.fg = fg;
   x.bg = bg;
}



define color_get_color_for_object (title)
{
   variable n;
   
   n = _stkdepth ();
   return select_list_box (title,
			   "black",
			   "red",
			   "green",
			   "brown",
			   "blue",
			   "magenta",
			   "cyan",
			   "lightgray",
			   "gray",
			   "brightred",
			   "brightgreen",
			   "yellow",
			   "brightblue",
			   "brightmagenta",
			   "brightcyan",
			   "white",
			   "default",
			   _stkdepth () - n - 1,
			   0);
}

define edit_colors ()
{
   variable n, fg, bg;
   variable obj;
   
   forever 
     {
	n = _stkdepth ();
	obj = select_list_box ("Object",    %  title
			       "EXIT",
			       "normal",
			       "status",
			       "menu",
			       "menu_press",
			       "headers",
			       "group",
			       "subject",
			       "author",
			       "error",
			       "cursor",
			       "article",
			       "tree",
			       "quotes",
			       "signature",
			       "thread_number",
			       "header_number",
			       "high_score",
			       "description",
			       "grouplens_display",
			       "tilde",
			       "header_name",
			       "response_char",
			       "box",
			       "frame",
			       "selection",
			       _stkdepth () - n - 1,
			       0);

	if ((obj == "EXIT") or (obj == ""))
	  break;
	
	fg = color_get_color_for_object ("Foreground color for " + obj);
	if (fg == "") break;

	bg = color_get_color_for_object ("Background color for " + obj);
	if (bg == "") break;
	
	set_color (obj, fg, bg);
	color_store_color (obj, fg, bg);
	call ("redraw");
     }
   
   color_save_colors_to_file ();
}

-- 
John E. Davis                   Center for Space Research/AXAF Science Center
617-258-8119                    One Hampshire St., Building NE80-6019
http://space.mit.edu/~davis     Cambridge, MA  02139-4307
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads