[elinks-dev] Re: Descriptions

Witold Filipczyk witekfl at poczta.gazeta.pl
Fri Oct 24 02:50:22 PDT 2003


On Thu, Oct 23, 2003 at 04:52:42PM +0200, Petr Baudis wrote:
> Dear diary, on Thu, Oct 23, 2003 at 04:19:56AM CEST, I got a letter,
> where Witold Filipczyk <witekfl at poczta.gazeta.pl> told me, that...
> > Descriptions often have '\n' at the end of line, but this is unnecessary,
> > because dialogs automagically wrap text. Now descriptions are prepared for
> > 80-wide terminals. For wider terminals not whole screen is used.
> 
> This is a long standing "silent TODO" :-).
> 
> > Descriptions without '\n' will make problems when saving configuration file,
> > but the same logic should be used as for dialogs with additional parameter
> > config.width
> 
> Will anyone ever want different width than 80 columns?
> 
> > I hope that you agree with me and someone code it and not forget about
> > config.indentation.
> 
> What's config.indentation supposed to be?
> 
> You're welcome to code it :-).

OK. Here is patch. config.width will come later.

-- 
Witold Filipczyk tohu-bohu
<witekfl at poczta.gazeta.pl>
-------------- next part --------------
--- elinks/src/config/conf.c	Tue Oct 21 00:25:07 2003
+++ elinks.2/src/config/conf.c	Fri Oct 24 13:44:03 2003
@@ -481,7 +481,6 @@
 		       int action, int i18n)
 {
 	unsigned char *desc_i18n;
-	int i, l;
 
 	/* When we're OPT_TREE, we won't get called with action 2 anyway and
 	 * we want to pop out a comment. */
@@ -517,22 +516,46 @@
 				break;
 
 			desc_i18n = conf_i18n(option->desc, i18n);
-			l = strlen(desc_i18n);
 
 			if (depth)
 				add_xchar_to_string(string, ' ', depth * indentation);
 			add_to_string(string, "# ");
-
-			for (i = 0; i < l; i++) {
-				add_char_to_string(string, desc_i18n[i]);
-				if (desc_i18n[i] == '\n') {
-					if (depth)
-						add_xchar_to_string(string, ' ',
-								    depth * indentation);
-					add_to_string(string, "# ");
+			{
+				unsigned char *i = desc_i18n;
+				unsigned char *j = i;
+				unsigned char *last_space = NULL;
+				int config_width = 80;
+				int n = depth * indentation + 2;
+				int was_space = 0;
+				
+				for (;*i; i++, n++) {
+					if (*i == '\n') {
+						add_bytes_to_string(string, j, i - j + 1);
+						if (depth)
+							add_xchar_to_string(string, ' ', depth * indentation);
+						add_to_string(string, "# ");
+						j = i + 1;
+						n = depth * indentation + 1;
+						was_space = 0;
+						continue;
+					}
+					if (*i == ' ') {
+						was_space = 1;
+						last_space = i;
+					}
+					if (n >= config_width && was_space) {
+						add_bytes_to_string(string, j, last_space - j);
+						add_char_to_string(string, '\n');
+						if (depth)
+							add_xchar_to_string(string, ' ', depth * indentation);
+						add_to_string(string, "# ");
+						j = last_space + 1;
+						n = depth * indentation + 1 + i - last_space;
+						was_space = 0;
+					}
 				}
+				add_to_string(string, j);
 			}
-
 			add_char_to_string(string, '\n');
 			break;
 


More information about the elinks-dev mailing list