table-viewer 0.0.1 → 0.0.2

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/index.js +18 -10
  2. package/package.json +10 -2
package/index.js CHANGED
@@ -23,6 +23,13 @@ const consoleTableStartChars = {
23
23
  2: '├',
24
24
  }
25
25
 
26
+ const scrollbarEndChars = {
27
+ up: '·',
28
+ down: '·',
29
+ left: '·',
30
+ right: '·',
31
+ }
32
+
26
33
  const consoleTableOutput = captureConsoleTableOutput(tableData)
27
34
 
28
35
  const consoleTableOutputSplit = consoleTableOutput.split('\n')
@@ -37,12 +44,12 @@ if (!consoleTableOutputSplit.length) process.exit(0)
37
44
  const consoleTableOutputWidth = consoleTableOutputSplit[0].length
38
45
  const consoleTableOutputHeight = consoleTableOutputSplit.length
39
46
 
40
- // Hide cursor
41
- process.stdout.write('\x1B[?25l')
47
+ // Enter alternate screen buffer and hide cursor
48
+ process.stdout.write('\x1B[?1049h\x1B[?25l')
42
49
 
43
- // Restore cursor on exit
50
+ // Restore cursor and leave alternate screen buffer on exit
44
51
  process.on('exit', () => {
45
- process.stdout.write('\x1B[?25h')
52
+ process.stdout.write('\x1B[?25h\x1B[?1049l')
46
53
  })
47
54
 
48
55
  process.stdout.on('resize', () => {
@@ -236,7 +243,7 @@ function renderScrollbarX(needsScrollbarX, needsScrollbarY) {
236
243
  if (!needsScrollbarX) return ''
237
244
 
238
245
  const visibleWidth = consoleWidth - (needsScrollbarY ? 1 : 0)
239
- const trackLength = visibleWidth - (needsScrollbarY ? 1 : 2)
246
+ const trackLength = visibleWidth - 2
240
247
 
241
248
  const thumbSize = Math.max(
242
249
  1,
@@ -251,11 +258,12 @@ function renderScrollbarX(needsScrollbarX, needsScrollbarY) {
251
258
  ) || 0
252
259
 
253
260
  return (
254
- ' ' +
261
+ scrollbarEndChars.left +
255
262
  '-'.repeat(thumbPos) +
256
263
  '═'.repeat(thumbSize) +
257
264
  '-'.repeat(trackLength - thumbPos - thumbSize) +
258
- ' '
265
+ scrollbarEndChars.right +
266
+ (needsScrollbarY ? ' ' : '')
259
267
  )
260
268
  }
261
269
 
@@ -268,7 +276,7 @@ function renderScrollbarY(needsScrollbarX, needsScrollbarY) {
268
276
  if (!needsScrollbarY) return ''
269
277
 
270
278
  const visibleHeight = consoleHeight - (needsScrollbarX ? 1 : 0)
271
- const trackLength = visibleHeight - (needsScrollbarX ? 1 : 2)
279
+ const trackLength = visibleHeight - 2
272
280
 
273
281
  const thumbSize = Math.max(
274
282
  1,
@@ -283,11 +291,11 @@ function renderScrollbarY(needsScrollbarX, needsScrollbarY) {
283
291
  ) || 0
284
292
 
285
293
  return (
286
- ' ' +
294
+ scrollbarEndChars.up +
287
295
  '╎'.repeat(thumbPos) +
288
296
  '║'.repeat(thumbSize) +
289
297
  '╎'.repeat(trackLength - thumbPos - thumbSize) +
290
- (needsScrollbarX ? '' : ' ')
298
+ scrollbarEndChars.down
291
299
  )
292
300
  }
293
301
 
package/package.json CHANGED
@@ -1,8 +1,16 @@
1
1
  {
2
2
  "name": "table-viewer",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "A keyboard-navigable terminal table viewer",
5
5
  "type": "module",
6
6
  "main": "./index.js",
7
- "bin": "./index.js"
7
+ "bin": "./index.js",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/aaronccasanova/table-viewer.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/aaronccasanova/table-viewer/issues"
14
+ },
15
+ "homepage": "https://github.com/aaronccasanova/table-viewer"
8
16
  }