MCPcopy Create free account
hub / github.com/SmartThingsCommunity/smartthings-cli / setupTable

Function setupTable

src/lib/table-generator.ts:147–189  ·  view source on GitHub ↗
(options: Partial<TableOptions>)

Source from the content-addressed store, hash-verified

145}
146
147const setupTable = (options: Partial<TableOptions>): Table => {
148 const data: string[][] = []
149
150 const push = (row: TableCellData[]): number => data.push(row.map(cell => cell?.toString() ?? ''))
151
152 if (options.head) {
153 data.push(options.head)
154 }
155
156 const toString = (): string => {
157 const border = {
158 topBody: '─',
159 topJoin: '',
160 topLeft: '',
161 topRight: '',
162
163 bottomBody: '─',
164 bottomJoin: '',
165 bottomLeft: '',
166 bottomRight: '',
167
168 bodyLeft: '',
169 bodyRight: '',
170 bodyJoin: '',
171
172 joinBody: '─',
173 joinLeft: '',
174 joinRight: '',
175 joinJoin: '',
176 }
177
178 const listDrawHorizontalLine = options.groupRows
179 ? (index: number) => index === 0 || index === data.length || (index - 1) % 5 === 0
180 : (index: number) => index === 0 || index === data.length || index === 1
181 const drawHorizontalLine = options.isList
182 ? listDrawHorizontalLine
183 : (index: number) => index === 0 || index === data.length
184 const config = { drawHorizontalLine, border }
185 return table(data, config)
186 }
187
188 return { push, toString }
189}
190
191export const defaultTableGenerator = (tableOptions: Pick<TableOptions, 'groupRows'>): TableGenerator => {
192 const logger = log4js.getLogger('table-manager')

Callers 1

newOutputTableFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected