Ilya Zakharevich on Fri, 22 Sep 2000 20:15:42 -0400 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
PATCH: prettyprinter and colors |
This a) introduces two new options to default(color) command: "lightbg" and "darkbg", and removes the "yes" option (does not make a lot of sense if you do not know the background). default(colors,l) The only tune up I did was for the contrast of the most significant parts of the output. Also: darkbg is not tuned up for contrast yet. b) Makes colors work with the prettyprinter. Enjoy, Ilya --- ./misc/tex2mail~ Fri Sep 22 16:25:46 2000 +++ ./misc/tex2mail Fri Sep 22 20:09:39 2000 @@ -101,8 +101,11 @@ sub join { warn "`$str1', need $h1 rows\n"; warn "`$str2', need $h2 rows\n"; } + # This is may be wrong if a zero-length record with escape sequences + # is appended to with something not on the same row... But + # apparently, it should be OK for PARI... for (0..$h2-1) { - $str[$b-$b2+$_] = substr($str[$b-$b2+$_] . " " x $l1,0,$l1) . $str2[$_]; + $str[$b-$b2+$_] .= " " x ($l1 - length ($str[$b-$b2+$_])) . $str2[$_]; } return "$h,$l,$b,$sp," . join("\n",@str); } @@ -535,7 +538,14 @@ sub string2record { $sp || ($sp=0); # Sometimes it is undef? } return "$h," . length($_[0]) . ",0,$sp,$_[0]"; -} +} + +# The second argument forces the block length no matter what is the +# length the string (for strings with screen escapes). + +sub record_forcelength { + $_[0] =~ s/^(\d+),(\d+)/$1,$_[1]/; +} sub finishBuffer { while ($#level>0) {&finish("");} @@ -670,6 +680,16 @@ sub f_end { } else {&puts("\\end{$arg}");} } + +sub f_literal_no_length { + warn "Entering f_literal_with_length...\n" if $debug & $debug_flow; + # &trim(1); + &collapse(1); + &assertHave(1) || &finish("",1); + record_forcelength($out[$#out], 0); + &finish(1,1); +} + sub f_discard { warn "Entering f_discard...\n" if $debug & $debug_flow; &finish_ignore($wait[$#level]); @@ -1785,6 +1805,9 @@ $contents{"\\buildrel"}="buildrel"; $type{"\\frac"}="sub2"; $contents{"\\frac"}="fraction"; +$type{"\\LITERALnoLENGTH"}="sub1"; +$contents{"\\LITERALnoLENGTH"}="literal_no_length"; + for ("text","operatorname","operatornamewithlimits","relax","-", "notag","!","/","protect","mathcal","Bbb","bf","it","em","boldsymbol", "cal","Cal","goth","ref","maketitle","expandafter","csname","endcsname", @@ -2173,3 +2196,5 @@ __END__ # Apr 00: Finishing a level 1 would not merge things into one chunk. # May 00: Additional argument to finish() to distinguish finishing things which cannot be broken between lines. +# Sep 00: Add support for new macro for strings with screen escapes sequences: + \LITERALnoLENGTH{escapeseq}. --- ./src/gp/gp.c-pre Fri Sep 22 17:11:24 2000 +++ ./src/gp/gp.c Fri Sep 22 19:59:36 2000 @@ -526,8 +526,10 @@ sd_colors(char *v, int flag) l = strlen(v); if (l <= 2 && strncmp(v, "no", l) == 0) v = ""; - if (l <= 3 && strncmp(v, "yes", l) == 0) + if (l <= 6 && strncmp(v, "darkbg", l) == 0) v = "1, 5, 3, 7, 6, 2, 3"; /* Assume recent ReadLine. */ + if (l <= 7 && strncmp(v, "lightbg", l) == 0) + v = "1, 6, 3, 4, 5, 2, 3"; /* Assume recent ReadLine. */ tmp = v = pari_strdup(v); filtre(v, f_INIT|f_REG); for (c=c_ERR; c < c_LAST; c++) gp_colors[c] = gp_get_color(&v); @@ -2260,17 +2262,33 @@ gp_main_loop(int ismain) FILE *o_out = pari_outfile; int prettyprint, o_prettyp = prettyp; + /* Emit before the switch to prettyprinter */ + if (prettyprinter && prettyp == f_PRETTY) + term_color(c_OUTPUT); /* There may be lines before the prompt */ + else + term_color(c_HIST); prettyprint = (prettyprinter && prettyp == f_PRETTY && prettyp_init()); if (DEBUGLEVEL > 4) fprintferr("prec = [%ld, %ld]\n", prec,precdl); /* history number */ if (prettyprint) - sprintf(thestring, "\\%%%ld = ", tglobal); - else { - term_color(c_HIST); - sprintf(thestring, "%%%ld = ", tglobal); + int l; + + if (*term_get_color(c_HIST) || *term_get_color(c_OUTPUT)) + { + char col1[80]; /* Expect that it would not overflow */ + + strcpy(col1,term_get_color(c_HIST)); + sprintf(thestring, + "\\LITERALnoLENGTH{%s}\\%%%ld = \\LITERALnoLENGTH{%s}", + col1, tglobal, term_get_color(c_OUTPUT)); + } + else + sprintf(thestring, "\\%%%ld = ", tglobal); } + else + sprintf(thestring, "%%%ld = ", tglobal); pariputs_opt(thestring); /* output */