dbcat 0.0.13 → 0.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/table.ts +12 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dbcat",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "description": "A simple CLI to view database tables. Supports PostgreSQL, MySQL, and SQLite.",
5
5
  "author": "RiskyMH",
6
6
  "license": "MIT",
package/src/table.ts CHANGED
@@ -119,6 +119,10 @@ function wrapLines(str: string, maxWidth: number): string[] {
119
119
  return lines;
120
120
  }
121
121
 
122
+ function wrapMultilineCell(str: string, maxWidth: number): string[] {
123
+ return String(str).split('\n').flatMap(line => wrapLines(line, maxWidth));
124
+ }
125
+
122
126
  export function printTable(
123
127
  rows: Record<string, unknown>[],
124
128
  options: TableOptions = {},
@@ -151,8 +155,7 @@ export function printTable(
151
155
  )} ${dim}${BOX.vertical}${reset}`,
152
156
  );
153
157
  console.log(
154
- `${dim}${BOX.bottomLeft}${BOX.horizontal.repeat(innerWidth)}${
155
- BOX.bottomRight
158
+ `${dim}${BOX.bottomLeft}${BOX.horizontal.repeat(innerWidth)}${BOX.bottomRight
156
159
  }${reset}`,
157
160
  );
158
161
  } else {
@@ -181,7 +184,7 @@ export function printTable(
181
184
  const colWidths: number[] = allColumns.map((col) => Bun.stringWidth(col));
182
185
  const formattedRows: string[][] = displayRows.map((row) =>
183
186
  allColumns.map((col, i) => {
184
- const formatted = formatValue(row[col]).replace(/\n/g, "\\n");
187
+ const formatted = options.fullContent ? formatValue(row[col]) : formatValue(row[col]).replace(/\n/g, `${dim}\\n${reset}`);
185
188
  colWidths[i] = Math.max(colWidths[i]!, Bun.stringWidth(formatted));
186
189
  return formatted;
187
190
  }),
@@ -307,7 +310,8 @@ export function printTable(
307
310
  if (options.fullContent) {
308
311
  for (let rowIdx = 0; rowIdx < visibleFormattedRows.length; rowIdx++) {
309
312
  const row = visibleFormattedRows[rowIdx] ?? [];
310
- const wrapped = row.map((val, i) => wrapLines(val, visibleColWidths[i]!));
313
+ const wrapped = row.map((val, i) => wrapMultilineCell(val, visibleColWidths[i]!));
314
+
311
315
  const rowHeight = Math.max(...wrapped.map(x => x.length));
312
316
  for (let lineIdx = 0; lineIdx < rowHeight; lineIdx++) {
313
317
  const pieces = wrapped.map((cellLines, i) => {
@@ -316,10 +320,10 @@ export function printTable(
316
320
  ? padLeft(truncate(part, visibleColWidths[i]!), visibleColWidths[i]!)
317
321
  : padRight(truncate(part, visibleColWidths[i]!), visibleColWidths[i]!);
318
322
  });
319
- const line = pieces.join(` ${dim}${BOX.vertical}${reset} `);
320
- console.log(`${dim}${BOX.vertical}${reset} ${line} ${dim}${BOX.vertical}${reset}`);
323
+ const line = pieces.join(` ${reset}${dim}${BOX.vertical}${reset} `);
324
+ console.log(`${reset}${dim}${BOX.vertical}${reset} ${line} ${reset}${dim}${BOX.vertical}${reset}`);
321
325
  }
322
- if (rowIdx < visibleFormattedRows.length - 1) {
326
+ if (rowIdx < visibleFormattedRows.length - 1 || (rowIdx === visibleFormattedRows.length - 1 && infoText)) {
323
327
  const rowSep = visibleColWidths
324
328
  .map((w) => BOX.horizontal.repeat(w))
325
329
  .join(`${BOX.horizontal}${BOX.headerCross}${BOX.horizontal}`);
@@ -348,8 +352,7 @@ export function printTable(
348
352
  console.log(`${dim}${BOX.vertical} ${infoLine} ${BOX.vertical}${reset}`);
349
353
 
350
354
  console.log(
351
- `${dim}${BOX.bottomLeft}${BOX.horizontal.repeat(totalInnerWidth)}${
352
- BOX.bottomRight
355
+ `${dim}${BOX.bottomLeft}${BOX.horizontal.repeat(totalInnerWidth)}${BOX.bottomRight
353
356
  }${reset}`,
354
357
  );
355
358
  } else {