Ilya Zakharevich on Tue, 15 Oct 2002 22:05:32 -0700 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
[PATCH CVS] log and colors and prettyprint |
I suspect that most of the people do not want to see meaningless escapes and tex-formatting in the log file, right? The following patch disables escape sequences and the-line-noise-which- is-the-input-for-prettyprinter when writing to the log file. The "proper" solution may be to have two extra flags (or bits of default(log)) to enable/disable these "features"; but I hope that most people do not want to go back. Enjoy, Ilya --- ./src/gp/gp.c-pre Tue Oct 15 17:34:02 2002 +++ ./src/gp/gp.c Tue Oct 15 20:26:00 2002 @@ -2219,9 +2219,10 @@ brace_color(char *s, int c, int force) } static char * -do_prompt(int in_comment, char *p) +do_prompt(int in_comment, char *p, char **bare) { static char buf[MAX_PROMPT_LEN + 24]; /* + room for color codes */ + static char buf1[MAX_PROMPT_LEN]; char *s; if (GP_DATA->flags & TEST) return prompt; @@ -2231,8 +2232,12 @@ do_prompt(int in_comment, char *p) s += strlen(s); if (in_comment) strcpy(s, COMMENTPROMPT); - else - do_strftime(p,s, MAX_PROMPT_LEN-1); + else { + do_strftime(p,buf1, MAX_PROMPT_LEN-1); + strcpy(s, buf1); + } + if (bare) + *bare = buf1; s += strlen(s); brace_color(s, c_INPUT, 1); return buf; } @@ -2308,7 +2313,7 @@ input_loop(filtre_t *F, input_method *IM /* read continuation line */ s = F->end; - if (IM->prompt) IM->prompt = do_prompt(F->in_comment, prompt_cont); + if (IM->prompt) IM->prompt = do_prompt(F->in_comment, prompt_cont, NULL); to_read = IM->getline(b,&s, IM); if (!to_read) break; } @@ -2441,7 +2446,7 @@ is_interactive(void) #endif } -extern int get_line_from_readline(char *prompt, filtre_t *F); +extern int get_line_from_readline(char *prompt, char *bare_prompt, filtre_t *F); /* return 0 if no line could be read (EOF) */ static int @@ -2451,10 +2456,15 @@ read_line(filtre_t *F, char *PROMPT) if (compatible == OLDALL) F->downcase = 1; if (is_interactive()) { - if (!PROMPT) PROMPT = do_prompt(F->in_comment, prompt); + char *bare_prompt; + + if (PROMPT) + bare_prompt = PROMPT; + else + PROMPT = do_prompt(F->in_comment, prompt, &bare_prompt); #ifdef READLINE if (GP_DATA->flags & USE_READLINE) - res = get_line_from_readline(PROMPT, F); + res = get_line_from_readline(PROMPT, bare_prompt, F); else #endif res = get_line_from_user(PROMPT, F); --- ./src/gp/gp_rl.c-pre Tue Oct 15 17:34:02 2002 +++ ./src/gp/gp_rl.c Tue Oct 15 20:26:50 2002 @@ -798,7 +798,7 @@ unblock_SIGINT(void) * Return 0: EOF * 1: got one line from readline or infile */ int -get_line_from_readline(char *prompt, filtre_t *F) +get_line_from_readline(char *prompt, char *bare_prompt, filtre_t *F) { const int index = history_length; char *s; @@ -823,7 +823,7 @@ get_line_from_readline(char *prompt, fil } /* update logfile */ - if (logfile) fprintf(logfile, "%s%s\n",prompt,s); + if (logfile) fprintf(logfile, "%s%s\n",bare_prompt,s); } unblock_SIGINT(); /* bug in readline 2.0: need to unblock ^C */ return 1; --- ./src/language/es.c-pre Tue Oct 15 17:34:04 2002 +++ ./src/language/es.c Tue Oct 15 21:55:20 2002 @@ -318,7 +318,11 @@ pariputsf(char *format, ...) void term_color(int c) { + FILE *o_logfile = logfile; + + logfile = 0; /* Ugly hack... */ pariputs(term_get_color(c)); + logfile = o_logfile; } void @@ -1978,6 +1982,7 @@ tex2mail_output(GEN z, long n) { pariout_t T = *(GP_DATA->fmt); /* copy */ FILE *o_out; + FILE *o_logfile = logfile; if (!prettyp_init()) return 0; o_out = pari_outfile; /* save state */ @@ -1987,11 +1992,13 @@ tex2mail_output(GEN z, long n) pariflush(); pari_outfile = GP_DATA->pp->file->file; T.prettyp = f_TEX; + logfile = NULL; /* history number */ if (n) { char s[128]; + if (*term_get_color(c_HIST) || *term_get_color(c_OUTPUT)) { char col1[80]; @@ -2002,12 +2009,21 @@ tex2mail_output(GEN z, long n) else sprintf(s, "\\%%%ld = ", n); pariputs_opt(s); + if (o_logfile) + fprintf(o_logfile, "%%%ld = ", n); } /* output */ gen_output(z, &T); + /* flush and restore */ prettyp_wait(); + if (o_logfile) { + pari_outfile = o_logfile; + /* XXXX Maybe it is better to output in another format? */ + outbrute(z); pariputc('\n'); pariflush(); + } + logfile = o_logfile; pari_outfile = o_out; if (n) term_color(c_NONE); return 1;