diffwatch 2.0.6 → 2.0.7

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "diffwatch",
3
- "version": "2.0.6",
3
+ "version": "2.0.7",
4
4
  "description": "A TUI app for watching git repository file changes with diffs.",
5
5
  "keywords": [
6
6
  "git",
@@ -1,5 +1,5 @@
1
1
  import React, { useEffect, useState, useMemo, useRef } from 'react';
2
- import { useKeyboard } from '@opentui/react';
2
+ import { useKeyboard, useRenderer } from '@opentui/react';
3
3
  import { getRawDiff } from '../utils/git';
4
4
  import * as Diff2Html from 'diff2html';
5
5
  import * as fsPromises from 'fs/promises';
@@ -22,6 +22,7 @@ export function DiffViewer({ filename, focused, searchQuery, status, repoPath }:
22
22
  const [isBinary, setIsBinary] = useState(false);
23
23
  const scrollRef = useRef<any>(null);
24
24
  const pollingIntervalRef = useRef<NodeJS.Timeout | null>(null);
25
+ const renderer = useRenderer();
25
26
 
26
27
  const loadContent = async (showLoading = true) => {
27
28
  if (!filename) {
@@ -115,9 +116,19 @@ const diffData = useMemo(() => {
115
116
  return fileContent.split('\n');
116
117
  }, [fileContent]);
117
118
 
118
- // Soft wrap lines at approximately 80 characters
119
- const MAX_LINE_WIDTH = 80;
119
+ // Calculate the max line width based on available width in the diff viewer
120
+ // The diff viewer takes up 67% of the total width, and we need to account for:
121
+ // - Line numbers (6 chars: " 1234: ")
122
+ // - Prefix (+/-/space) (1 char)
123
+ // - Borders (2 chars: left and right)
124
+ // - Some padding (1 char)
125
+ // Total overhead: 6 (line numbers) + 1 (prefix) + 2 (borders) = 9 chars
126
+ const calculateMaxLineWidth = (): number => {
127
+ const estimatedWidth = Math.floor((renderer.width * 0.67) - 9); // 9 chars for line numbers, prefix, and borders
128
+ return Math.max(20, estimatedWidth); // minimum width of 20
129
+ };
120
130
 
131
+ // Soft wrap lines based on available width
121
132
  const wrapLine = (text: string, maxLength: number): string[] => {
122
133
  if (text.length <= maxLength) return [text];
123
134
 
@@ -145,6 +156,8 @@ const diffData = useMemo(() => {
145
156
  return lines;
146
157
  };
147
158
 
159
+ const maxLineWidth = calculateMaxLineWidth();
160
+
148
161
  return (
149
162
  <box
150
163
  border
@@ -162,7 +175,7 @@ const diffData = useMemo(() => {
162
175
  ) : isNewFile ? (
163
176
  <scrollbox flexGrow={1} ref={scrollRef}>
164
177
  {contentLines.flatMap((line, i) => {
165
- const wrappedLines = wrapLine(line, MAX_LINE_WIDTH);
178
+ const wrappedLines = wrapLine(line, maxLineWidth);
166
179
 
167
180
  return wrappedLines.map((wrappedLine, wrapIdx) => {
168
181
  const isFirstLine = wrapIdx === 0;
@@ -214,7 +227,7 @@ const diffData = useMemo(() => {
214
227
  const lnText = ln ? `${String(ln).padStart(4)}: ` : ' ';
215
228
 
216
229
  // Wrap content if it's too long
217
- const wrappedContent = wrapLine(content, MAX_LINE_WIDTH);
230
+ const wrappedContent = wrapLine(content, maxLineWidth);
218
231
 
219
232
  return (
220
233
  <>
@@ -34,9 +34,10 @@ export function FileList({ files, selectedIndex, focused, searchQuery, onSelect,
34
34
  // Get the width of the container (33% of total width)
35
35
  // Since we can't directly measure the rendered width, we'll estimate based on a percentage
36
36
  // considering that the container is 33% of the total width
37
- // and we need to account for the symbol (1 char) + space (1 char) = 2 chars
38
- // Also account for potential borders and padding (approximately 2-3 chars)
39
- const estimatedWidth = Math.floor((renderer.width * 0.33) - 5); // 5 chars for symbol + spaces + borders/padding
37
+ // and we need to account for the symbol (1 char) + space (1 char) before the filename
38
+ // Also account for borders (left and right = 2 chars total)
39
+ // Total overhead: 1 (symbol) + 1 (space after symbol) + 2 (borders) = 4 chars
40
+ const estimatedWidth = Math.floor((renderer.width * 0.33) - 4); // 4 chars for symbol + space + borders
40
41
  return Math.max(10, estimatedWidth); // minimum length of 10
41
42
  };
42
43
 
@@ -47,6 +48,7 @@ export function FileList({ files, selectedIndex, focused, searchQuery, onSelect,
47
48
  if (maxLength <= 3) {
48
49
  return '.'.repeat(maxLength);
49
50
  }
51
+ // Truncate the path and add ellipsis (...) at the end
50
52
  return path.substring(0, maxLength - 3) + '...';
51
53
  };
52
54
 
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const BUILD_VERSION = "2.0.6";
1
+ export const BUILD_VERSION = "2.0.7";