mirror of
https://github.com/janet-lang/janet
synced 2024-11-24 17:27:18 +00:00
Add Q and q formatters to buffer/format.
These are similar to P and p, but print values on a single line for a much more compact version.
This commit is contained in:
parent
77870508de
commit
060d11e4c2
@ -2,6 +2,9 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
## Unreleased
|
## 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.
|
- Add `backmatch` pattern for PEGs.
|
||||||
- jpm detects if not in a Developer Command prompt on windows for a better error message.
|
- jpm detects if not in a Developer Command prompt on windows for a better error message.
|
||||||
- jpm install git submodules in dependencies
|
- jpm install git submodules in dependencies
|
||||||
|
@ -1129,7 +1129,7 @@
|
|||||||
(defn pp
|
(defn pp
|
||||||
"Pretty print to stdout."
|
"Pretty print to stdout."
|
||||||
[x]
|
[x]
|
||||||
(print (buffer/format @"" (dyn :pretty-format "%p") x)))
|
(print (buffer/format @"" (dyn :pretty-format "%q") x)))
|
||||||
|
|
||||||
|
|
||||||
###
|
###
|
||||||
|
@ -310,7 +310,7 @@ struct pretty {
|
|||||||
|
|
||||||
static void print_newline(struct pretty *S, int just_a_space) {
|
static void print_newline(struct pretty *S, int just_a_space) {
|
||||||
int i;
|
int i;
|
||||||
if (just_a_space) {
|
if (just_a_space || (S->flags & JANET_PRETTY_ONELINE)) {
|
||||||
janet_buffer_push_u8(S->buffer, ' ');
|
janet_buffer_push_u8(S->buffer, ' ');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -725,12 +725,20 @@ void janet_buffer_format(
|
|||||||
janet_description_b(b, argv[arg]);
|
janet_description_b(b, argv[arg]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 'Q':
|
||||||
|
case 'q':
|
||||||
case 'P':
|
case 'P':
|
||||||
case 'p': { /* janet pretty , precision = depth */
|
case 'p': { /* janet pretty , precision = depth */
|
||||||
int depth = atoi(precision);
|
int depth = atoi(precision);
|
||||||
if (depth < 1)
|
if (depth < 1)
|
||||||
depth = 4;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
@ -1262,6 +1262,7 @@ JANET_API int janet_verify(JanetFuncDef *def);
|
|||||||
|
|
||||||
/* Pretty printing */
|
/* Pretty printing */
|
||||||
#define JANET_PRETTY_COLOR 1
|
#define JANET_PRETTY_COLOR 1
|
||||||
|
#define JANET_PRETTY_ONELINE 2
|
||||||
JANET_API JanetBuffer *janet_pretty(JanetBuffer *buffer, int depth, int flags, Janet x);
|
JANET_API JanetBuffer *janet_pretty(JanetBuffer *buffer, int depth, int flags, Janet x);
|
||||||
|
|
||||||
/* Misc */
|
/* Misc */
|
||||||
|
@ -91,6 +91,6 @@
|
|||||||
(defn getchunk [buf p]
|
(defn getchunk [buf p]
|
||||||
(getter (prompter p) buf))
|
(getter (prompter p) buf))
|
||||||
(def onsig (if *quiet* (fn [x &] x) nil))
|
(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))
|
(setdyn :err-color (if *colorize* true))
|
||||||
(repl getchunk onsig)))
|
(repl getchunk onsig)))
|
||||||
|
Loading…
Reference in New Issue
Block a user