Skip to content

Commit aedc258

Browse files
authored
feat: add colorized output for infer command (#222)
1 parent 92c0b53 commit aedc258

3 files changed

Lines changed: 168 additions & 48 deletions

File tree

crates/plotnik-cli/src/commands/infer.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::fs;
22
use std::io::{self, Write};
33
use std::path::PathBuf;
44

5+
use plotnik_lib::Colors;
56
use plotnik_lib::QueryBuilder;
67
use plotnik_lib::bytecode::Module;
78
use plotnik_lib::typegen::typescript;
@@ -101,11 +102,14 @@ pub fn run(args: InferArgs) {
101102
Some("null") => typescript::VoidType::Null,
102103
_ => typescript::VoidType::Undefined,
103104
};
105+
// Only use colors when outputting to stdout (not to file)
106+
let use_colors = args.color && args.output.is_none();
104107
let config = typescript::Config {
105108
export: args.export,
106109
emit_node_type: !args.no_node_type,
107110
verbose_nodes: args.verbose_nodes,
108111
void_type,
112+
colors: Colors::new(use_colors),
109113
};
110114
let output = typescript::emit_with_config(&module, config);
111115

crates/plotnik-lib/src/analyze/type_check/tests.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ fn multiple_definitions_all_emitted() {
1616
export interface Node {
1717
kind: string;
1818
text: string;
19+
span: [number, number];
1920
}
2021
2122
export interface Id {
@@ -43,6 +44,7 @@ fn multiple_definitions_distinct_types() {
4344
export interface Node {
4445
kind: string;
4546
text: string;
47+
span: [number, number];
4648
}
4749
4850
export interface Both {
@@ -70,6 +72,7 @@ fn capture_single_node() {
7072
export interface Node {
7173
kind: string;
7274
text: string;
75+
span: [number, number];
7376
}
7477
7578
export interface Q {
@@ -101,6 +104,7 @@ fn capture_with_custom_type() {
101104
export interface Node {
102105
kind: string;
103106
text: string;
107+
span: [number, number];
104108
}
105109
106110
export type Identifier = Node;
@@ -121,6 +125,7 @@ fn named_node_with_field_capture() {
121125
export interface Node {
122126
kind: string;
123127
text: string;
128+
span: [number, number];
124129
}
125130
126131
export interface Q {
@@ -144,6 +149,7 @@ fn named_node_multiple_field_captures() {
144149
export interface Node {
145150
kind: string;
146151
text: string;
152+
span: [number, number];
147153
}
148154
149155
export interface Q {
@@ -170,6 +176,7 @@ fn named_node_captured_with_internal_captures() {
170176
export interface Node {
171177
kind: string;
172178
text: string;
179+
span: [number, number];
173180
}
174181
175182
export type FunctionInfo = Node;
@@ -196,6 +203,7 @@ fn nested_named_node_captures() {
196203
export interface Node {
197204
kind: string;
198205
text: string;
206+
span: [number, number];
199207
}
200208
201209
export interface Q {
@@ -214,6 +222,7 @@ fn scalar_list_zero_or_more() {
214222
export interface Node {
215223
kind: string;
216224
text: string;
225+
span: [number, number];
217226
}
218227
219228
export interface Q {
@@ -232,6 +241,7 @@ fn scalar_list_one_or_more() {
232241
export interface Node {
233242
kind: string;
234243
text: string;
244+
span: [number, number];
235245
}
236246
237247
export interface Q {
@@ -252,6 +262,7 @@ fn row_list_basic() {
252262
export interface Node {
253263
kind: string;
254264
text: string;
265+
span: [number, number];
255266
}
256267
257268
export interface QRows {
@@ -277,6 +288,7 @@ fn row_list_non_empty() {
277288
export interface Node {
278289
kind: string;
279290
text: string;
291+
span: [number, number];
280292
}
281293
282294
export interface QRows {
@@ -300,6 +312,7 @@ fn optional_single_capture() {
300312
export interface Node {
301313
kind: string;
302314
text: string;
315+
span: [number, number];
303316
}
304317
305318
export interface Q {
@@ -319,6 +332,7 @@ fn optional_group_bubbles_fields() {
319332
export interface Node {
320333
kind: string;
321334
text: string;
335+
span: [number, number];
322336
}
323337
324338
export interface Q {
@@ -340,6 +354,7 @@ fn sequence_merges_fields() {
340354
export interface Node {
341355
kind: string;
342356
text: string;
357+
span: [number, number];
343358
}
344359
345360
export interface Q {
@@ -361,6 +376,7 @@ fn captured_sequence_creates_struct() {
361376
export interface Node {
362377
kind: string;
363378
text: string;
379+
span: [number, number];
364380
}
365381
366382
export interface QRow {
@@ -384,6 +400,7 @@ fn untagged_alt_same_capture_all_branches() {
384400
export interface Node {
385401
kind: string;
386402
text: string;
403+
span: [number, number];
387404
}
388405
389406
export interface Q {
@@ -402,6 +419,7 @@ fn untagged_alt_different_captures() {
402419
export interface Node {
403420
kind: string;
404421
text: string;
422+
span: [number, number];
405423
}
406424
407425
export interface Q {
@@ -426,6 +444,7 @@ fn untagged_alt_partial_overlap() {
426444
export interface Node {
427445
kind: string;
428446
text: string;
447+
span: [number, number];
429448
}
430449
431450
export interface Q {
@@ -450,6 +469,7 @@ fn tagged_alt_basic() {
450469
export interface Node {
451470
kind: string;
452471
text: string;
472+
span: [number, number];
453473
}
454474
455475
export interface QStr {
@@ -481,6 +501,7 @@ fn tagged_alt_with_type_annotation() {
481501
export interface Node {
482502
kind: string;
483503
text: string;
504+
span: [number, number];
484505
}
485506
486507
export interface QStr {
@@ -512,6 +533,7 @@ fn tagged_alt_captured() {
512533
export interface Node {
513534
kind: string;
514535
text: string;
536+
span: [number, number];
515537
}
516538
517539
export interface QResultStr {
@@ -547,6 +569,7 @@ fn nested_captured_group() {
547569
export interface Node {
548570
kind: string;
549571
text: string;
572+
span: [number, number];
550573
}
551574
552575
export interface QPair {
@@ -660,6 +683,7 @@ fn recursive_type_optional_self_ref() {
660683
export interface Node {
661684
kind: string;
662685
text: string;
686+
span: [number, number];
663687
}
664688
665689
export interface NestedCall {

0 commit comments

Comments
 (0)