diff --git a/CHANGELOG.md b/CHANGELOG.md index d6e93311..b2836855 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ All notable changes to this project will be documented in this file. ## Unreleased +- Add `buffer/format` and `string/format` format flags `Q` and `q` to print colored and + non-colored single-line values. +- Change default repl to print long sequences on one line. - Add `backmatch` pattern for PEGs. - jpm detects if not in a Developer Command prompt on windows for a better error message. - jpm install git submodules in dependencies diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 570dd057..21ad384e 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -1129,7 +1129,7 @@ (defn pp "Pretty print to stdout." [x] - (print (buffer/format @"" (dyn :pretty-format "%p") x))) + (print (buffer/format @"" (dyn :pretty-format "%q") x))) ### diff --git a/src/core/pp.c b/src/core/pp.c index e36986ac..76f147d3 100644 --- a/src/core/pp.c +++ b/src/core/pp.c @@ -310,7 +310,7 @@ struct pretty { static void print_newline(struct pretty *S, int just_a_space) { int i; - if (just_a_space) { + if (just_a_space || (S->flags & JANET_PRETTY_ONELINE)) { janet_buffer_push_u8(S->buffer, ' '); return; } @@ -725,12 +725,20 @@ void janet_buffer_format( janet_description_b(b, argv[arg]); break; } + case 'Q': + case 'q': case 'P': case 'p': { /* janet pretty , precision = depth */ int depth = atoi(precision); if (depth < 1) depth = 4; - janet_pretty_(b, depth, (strfrmt[-1] == 'P') ? JANET_PRETTY_COLOR : 0, argv[arg], startlen); + char c = strfrmt[-1]; + int has_color = (c == 'P') || (c == 'Q'); + int has_oneline = (c == 'Q') || (c == 'q'); + int flags = 0; + flags |= has_color ? JANET_PRETTY_COLOR : 0; + flags |= has_oneline ? JANET_PRETTY_ONELINE : 0; + janet_pretty_(b, depth, flags, argv[arg], startlen); break; } default: { diff --git a/src/include/janet.h b/src/include/janet.h index 1d597ae9..0b50c8c5 100644 --- a/src/include/janet.h +++ b/src/include/janet.h @@ -1262,6 +1262,7 @@ JANET_API int janet_verify(JanetFuncDef *def); /* Pretty printing */ #define JANET_PRETTY_COLOR 1 +#define JANET_PRETTY_ONELINE 2 JANET_API JanetBuffer *janet_pretty(JanetBuffer *buffer, int depth, int flags, Janet x); /* Misc */ diff --git a/src/mainclient/init.janet b/src/mainclient/init.janet index c6b6fbaf..9b34bc60 100644 --- a/src/mainclient/init.janet +++ b/src/mainclient/init.janet @@ -91,6 +91,6 @@ (defn getchunk [buf p] (getter (prompter p) buf)) (def onsig (if *quiet* (fn [x &] x) nil)) - (setdyn :pretty-format (if *colorize* "%.20P" "%.20p")) + (setdyn :pretty-format (if *colorize* "%.20Q" "%.20q")) (setdyn :err-color (if *colorize* true)) (repl getchunk onsig)))