dbcat 0.0.18 → 0.0.20

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 +10 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dbcat",
3
- "version": "0.0.18",
3
+ "version": "0.0.20",
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
@@ -29,10 +29,14 @@ function formatValue(value: unknown, compact = false): string {
29
29
  if (typeof value === "string") {
30
30
  return value;
31
31
  }
32
- return Bun.inspect(value, { colors: Bun.enableANSIColors, depth: 2, compact, });
32
+ return Bun.inspect(value, { colors: Bun.enableANSIColors, depth: 2, compact });
33
33
  }
34
34
 
35
35
  function truncate(str: string, maxWidth: number): string {
36
+ if (typeof Bun.sliceAnsi === "function") {
37
+ return Bun.sliceAnsi(str, 0, maxWidth, "…");
38
+ }
39
+
36
40
  const width = Bun.stringWidth(str);
37
41
  if (width <= maxWidth) {
38
42
  return str;
@@ -190,7 +194,11 @@ export function printTable(
190
194
  const colWidths: number[] = allColumns.map((col) => Bun.stringWidth(col));
191
195
  const formattedRows: string[][] = displayRows.map((row) =>
192
196
  allColumns.map((col, i) => {
193
- const formatted = options.fullContent ? formatValue(row[col], true) : formatValue(row[col], false).replace(/\n/g, `${dim}\\n${reset}`);
197
+ const formatted = options.fullContent
198
+ ? formatValue(row[col], false)
199
+ : formatValue(row[col], true)
200
+ .replace(/\n/g, `${dim}\\n${reset}`)
201
+ .replace(/\r/g, `${dim}\\r${reset}`);
194
202
  colWidths[i] = Math.max(colWidths[i]!, Bun.stringWidth(formatted));
195
203
  return formatted;
196
204
  }),