-
Notifications
You must be signed in to change notification settings - Fork 212
/
Printer.java
198 lines (191 loc) · 5.5 KB
/
Printer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
* Copyright (c) 2002-2021, the original author or authors.
*
* This software is distributable under the BSD license. See the terms of the
* BSD license in the documentation provided with this software.
*
* https://opensource.org/licenses/BSD-3-Clause
*/
package org.jline.console;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Print object to the console.
*
* @author <a href="mailto:matti.rintanikkola@gmail.com">Matti Rinta-Nikkola</a>
*/
public interface Printer {
enum TableRows {EVEN, ODD, ALL}
//
// option names
//
// 1) command options
//
/**
* Value: Boolean<br>
* Applies: TABLE<br>
* Ignore columnsOut configuration.
*/
String ALL = "all";
/**
* Value: {@code List<String>}<br>
* Applies: TABLE<br>
* Display given columns on table.
*/
String COLUMNS = "columns";
/**
* Value: {@code List<String>}<br>
* Applies: TABLE<br>
* Exclude given columns on table.
*/
String EXCLUDE = "exclude";
/**
* Value: {@code List<String>}<br>
* Applies: TABLE<br>
* Include given columns on table.
*/
String INCLUDE = "include";
/**
* Value: Integer<br>
* Applies: MAP<br>
* Indention size.
*/
String INDENTION = "indention";
/**
* Value: Integer<br>
* Applies: MAP and TABLE<br>
* Maximum column width.
*/
String MAX_COLUMN_WIDTH = "maxColumnWidth";
/**
* Value: Integer<br>
* Applies: MAP<br>
* Maximum depth objects are resolved.
*/
String MAX_DEPTH = "maxDepth";
/**
* Value: Integer<br>
* Applies: MAP and TABLE<br>
* Maximum number of lines to display.
*/
String MAXROWS = "maxrows";
/**
* Value: Boolean<br>
* Applies: TABLE<br>
* Display one row data on table.
*/
String ONE_ROW_TABLE = "oneRowTable";
/**
* Value: Boolean<br>
* Applies: TABLE<br>
* Display table row numbers.
*/
String ROWNUM = "rownum";
/**
* Value: Boolean<br>
* Applies: TABLE<br>
* Truncate table column names: property.field to field.
*/
String SHORT_NAMES = "shortNames";
/**
* Value: Boolean<br>
* Applies: MAP and TABLE<br>
* Ignore all options defined in PRNT_OPTIONS.
*/
String SKIP_DEFAULT_OPTIONS = "skipDefaultOptions";
/**
* Value: Boolean<br>
* Applies: TABLE<br>
* Display object structures and lists on table.
*/
String STRUCT_ON_TABLE = "structsOnTable";
/**
* Value: String<br>
* Use nanorc STYLE<br>
*/
String STYLE = "style";
/**
* Value: Boolean<br>
* Applies: MAP and TABLE<br>
* Use object's toString() method to get print value
* DEFAULT: object's fields are put to property map before printing
*/
String TO_STRING = "toString";
/**
* Value: String<br>
* Applies: MAP and TABLE<br>
* Nanorc syntax style used to highlight values.
*/
String VALUE_STYLE = "valueStyle";
/**
* Value: Integer<br>
* Applies: MAP and TABLE<br>
* Display width (default terminal width).
*/
String WIDTH = "width";
/**
* Value: String<br>
* Applies: TABLE<br>
* Table column delimiter.
*/
String DELIMITER = "delimiter";
/**
* Value: TableRows<br>
* Applies: TABLE<br>
* Highlight table rows.
*/
String ROW_HIGHLIGHT = "rowHighlight";
//
// 2) additional PRNT_OPTIONS
//
/**
* Value: {@code List<String>}<br>
* Applies: TABLE<br>
* These map values will be added to the table before all the other keys.
*/
String COLUMNS_IN = "columnsIn";
/**
* Value: {@code List<String>}<br>
* Applies: TABLE<br>
* These map values will not be inserted to the table.
*/
String COLUMNS_OUT = "columnsOut";
/**
* Value: {@code Map<regex, function>}.<br>
* Applies: TABLE<br>
* If command result map key matches with regex the highlight function is applied
* to the corresponding map value. The regex = * is processed after all the other regexes and the highlight
* function will be applied to all map values that have not been already highlighted.
*/
String HIGHLIGHT_VALUE = "highlightValue";
/**
* Value: Double<br>
* Applies: MAP and TABLE<br>
* default value 0.8 i.e. if at least of 4 of the 5 results map keys match with reference key set the
* result will be printed out as a table.
*/
String MAP_SIMILARITY = "mapSimilarity";
/**
* Value: {@code Map<class, function>}<br>
* Applies: MAP and TABLE<br>
* Overrides the ScriptEngine toMap() method.
*/
String OBJECT_TO_MAP = "objectToMap";
/**
* Value: {@code Map<class, function>}<br>
* Applies: MAP and TABLE<br>
* Overrides the ScriptEngine toString() method.
*/
String OBJECT_TO_STRING = "objectToString";
List<String> BOOLEAN_KEYS = Arrays.asList(ALL, ONE_ROW_TABLE, ROWNUM, SHORT_NAMES, SKIP_DEFAULT_OPTIONS
, STRUCT_ON_TABLE, TO_STRING);
default void println(Object object) {
println(new HashMap<>(), object);
}
void println(Map<String,Object> options, Object object);
default Exception prntCommand(CommandInput input) {
return null;
}
}