Skip to content

Commit e108cfc

Browse files
committed
FEAT: optionally truncate output of probe function
1 parent 2ee6c0a commit e108cfc

File tree

5 files changed

+41
-18
lines changed

5 files changed

+41
-18
lines changed

src/boot/sysobj.reb

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ options: object [ ; Options supplied to REBOL during startup
149149

150150
binary-base: 16 ; Default base for FORMed binary values (64, 16, 2)
151151
decimal-digits: 15 ; Max number of decimal digits to print.
152+
probe-limit: 16000 ; Max probed output size, 0 means no limit
152153
module-paths: [%./]
153154
default-suffix: %.reb ; Used by IMPORT if no suffix is provided
154155
file-types: []

src/core/n-io.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,15 @@ static REBSER *Read_All_File(char *fname)
131131
{
132132
REBVAL *val = D_ARG(1);
133133
REB_MOLD mo = {0};
134-
REBINT len = -1; // no limit
134+
REBINT len = NO_LIMIT;
135135

136136
if (D_REF(3)) SET_FLAG(mo.opts, MOPT_MOLD_ALL);
137137
if (D_REF(4)) SET_FLAG(mo.opts, MOPT_INDENT);
138138
if (D_REF(5)) {
139139
if (VAL_INT64(D_ARG(6)) > (i64)MAX_I32)
140140
len = MAX_I32;
141-
else if (VAL_INT64(D_ARG(6)) < 0)
142-
len = 0;
141+
else if (VAL_INT64(D_ARG(6)) <= 0)
142+
len = NO_LIMIT;
143143
else
144144
len = VAL_INT32(D_ARG(6));
145145
}

src/mezz/base-debug.reb

+11-5
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@ REBOL [
1919
probe: func [
2020
{Debug print a molded value and returns that same value.}
2121
value [any-type!]
22+
/local len
2223
][
23-
print mold :value
24+
len: system/options/probe-limit
25+
print either 0 < len [
26+
ellipsize (mold/part :value len + 1) len
27+
][
28+
mold :value
29+
]
2430
:value
2531
]
2632

@@ -33,7 +39,7 @@ probe: func [
3339
word? :name
3440
path? :name
3541
][
36-
prin ajoin ["^[[1;32;49m" mold :name "^[[0m: ^[[32m"]
42+
prin ajoin ["^[[1;32m" mold :name "^[[0m: ^[[32m"]
3743
prin either value? :name [mold/all get/any :name] ["#[unset!]"]
3844
print "^[[0m"
3945
]
@@ -43,15 +49,15 @@ probe: func [
4349
word? :word
4450
path? :word
4551
][
46-
prin ajoin ["^[[1;32;49m" mold :word "^[[0m: ^[[32m"]
52+
prin ajoin ["^[[1;32m" mold :word "^[[0m: ^[[32m"]
4753
prin either value? :word [mold/all get/any :word]["#[unset!]"]
4854
print "^[[0m"
4955
][
50-
print ajoin ["^[[1;32;49m" mold/all word "^[[0m"]
56+
print ajoin ["^[[1;32m" mold/all word "^[[0m"]
5157
]
5258
]
5359
]
54-
true [print ajoin ["^[[1;32;49m" mold/all :name "^[[0m"]]
60+
true [print ajoin ["^[[1;32m" mold/all :name "^[[0m"]]
5561
]
5662
exit
5763
]

src/mezz/base-series.reb

+24
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,27 @@ reform: func [
4444
][
4545
form reduce :value
4646
]
47+
48+
ellipsize: func [
49+
"Truncate and add ellipsis if str is longer than len"
50+
str [string!] "(modified)"
51+
len [integer!] "Max length"
52+
/one-line "Escape line breaks"
53+
/local chars
54+
][
55+
if one-line [
56+
chars: #[bitset! [not bits #{0024}]]
57+
parse str [
58+
any [
59+
some chars
60+
| change #"^/" "^^/"
61+
| change #"^M" "^^M"
62+
]
63+
]
64+
]
65+
if len < length? str [
66+
append clear skip str (len - 3) "..."
67+
]
68+
69+
str
70+
]

src/mezz/mezz-help.reb

+2-10
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,6 @@ import module [
7171
buffer: insert buffer form reduce value
7272
]
7373

74-
clip-str: func [str] [
75-
; Keep string to one line.
76-
unless string? str [str: mold/part/flat str max-desc-width]
77-
replace/all str LF "^^/"
78-
replace/all str CR "^^M"
79-
if (length? str) > (max-desc-width - 1) [str: append copy/part str max-desc-width "..."]
80-
str
81-
]
82-
8374
interpunction: charset ";.?!"
8475
dot: func[value [string!]][
8576
unless find interpunction last value [append value #"."]
@@ -116,7 +107,8 @@ import module [
116107
;none? :val [ mold/all val]
117108
true [:val]
118109
]
119-
clip-str val
110+
unless string? val [val: mold/part/flat val max-desc-width]
111+
ellipsize/one-line val max-desc-width - 1
120112
]
121113

122114
form-pad: func [val size] [

0 commit comments

Comments
 (0)