Skip to content

Commit 96ef5ee

Browse files
devr0306jacob314
andauthored
feat(ux): added text wrapping capabilities to markdown tables (google-gemini#18240)
Co-authored-by: jacob314 <jacob314@gmail.com>
1 parent b664391 commit 96ef5ee

File tree

6 files changed

+619
-91
lines changed

6 files changed

+619
-91
lines changed

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"pre-commit": "node scripts/pre-commit.js"
6565
},
6666
"overrides": {
67-
"ink": "npm:@jrichman/ink@6.4.8",
67+
"ink": "npm:@jrichman/ink@6.4.10",
6868
"wrap-ansi": "9.0.2",
6969
"cliui": {
7070
"wrap-ansi": "7.0.0"
@@ -126,7 +126,7 @@
126126
"yargs": "^17.7.2"
127127
},
128128
"dependencies": {
129-
"ink": "npm:@jrichman/ink@6.4.8",
129+
"ink": "npm:@jrichman/ink@6.4.10",
130130
"latest-version": "^9.0.0",
131131
"proper-lockfile": "^4.1.2",
132132
"simple-git": "^3.28.0"

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"fzf": "^0.5.2",
4848
"glob": "^12.0.0",
4949
"highlight.js": "^11.11.1",
50-
"ink": "npm:@jrichman/ink@6.4.8",
50+
"ink": "npm:@jrichman/ink@6.4.10",
5151
"ink-gradient": "^3.0.0",
5252
"ink-spinner": "^5.0.0",
5353
"latest-version": "^9.0.0",

packages/cli/src/ui/utils/TableRenderer.test.tsx

Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,257 @@ describe('TableRenderer', () => {
6161
expect(output).toContain('Data 3.4');
6262
expect(output).toMatchSnapshot();
6363
});
64+
65+
it('wraps long cell content correctly', () => {
66+
const headers = ['Col 1', 'Col 2', 'Col 3'];
67+
const rows = [
68+
[
69+
'Short',
70+
'This is a very long cell content that should wrap to multiple lines',
71+
'Short',
72+
],
73+
];
74+
const terminalWidth = 50;
75+
76+
const { lastFrame } = renderWithProviders(
77+
<TableRenderer
78+
headers={headers}
79+
rows={rows}
80+
terminalWidth={terminalWidth}
81+
/>,
82+
);
83+
84+
const output = lastFrame();
85+
expect(output).toContain('This is a very');
86+
expect(output).toContain('long cell');
87+
expect(output).toMatchSnapshot();
88+
});
89+
90+
it('wraps all long columns correctly', () => {
91+
const headers = ['Col 1', 'Col 2', 'Col 3'];
92+
const rows = [
93+
[
94+
'This is a very long text that needs wrapping in column 1',
95+
'This is also a very long text that needs wrapping in column 2',
96+
'And this is the third long text that needs wrapping in column 3',
97+
],
98+
];
99+
const terminalWidth = 60;
100+
101+
const { lastFrame } = renderWithProviders(
102+
<TableRenderer
103+
headers={headers}
104+
rows={rows}
105+
terminalWidth={terminalWidth}
106+
/>,
107+
);
108+
109+
const output = lastFrame();
110+
expect(output).toContain('wrapping in');
111+
expect(output).toMatchSnapshot();
112+
});
113+
114+
it('wraps mixed long and short columns correctly', () => {
115+
const headers = ['Short', 'Long', 'Medium'];
116+
const rows = [
117+
[
118+
'Tiny',
119+
'This is a very long text that definitely needs to wrap to the next line',
120+
'Not so long',
121+
],
122+
];
123+
const terminalWidth = 50;
124+
125+
const { lastFrame } = renderWithProviders(
126+
<TableRenderer
127+
headers={headers}
128+
rows={rows}
129+
terminalWidth={terminalWidth}
130+
/>,
131+
);
132+
133+
const output = lastFrame();
134+
expect(output).toContain('Tiny');
135+
expect(output).toContain('definitely needs');
136+
expect(output).toMatchSnapshot();
137+
});
138+
139+
// The snapshot looks weird but checked on VS Code terminal and it looks fine
140+
it('wraps columns with punctuation correctly', () => {
141+
const headers = ['Punctuation 1', 'Punctuation 2', 'Punctuation 3'];
142+
const rows = [
143+
[
144+
'Start. Stop. Comma, separated. Exclamation! Question? hyphen-ated',
145+
'Semi; colon: Pipe| Slash/ Backslash\\',
146+
'At@ Hash# Dollar$ Percent% Caret^ Ampersand& Asterisk*',
147+
],
148+
];
149+
const terminalWidth = 60;
150+
151+
const { lastFrame } = renderWithProviders(
152+
<TableRenderer
153+
headers={headers}
154+
rows={rows}
155+
terminalWidth={terminalWidth}
156+
/>,
157+
);
158+
159+
const output = lastFrame();
160+
expect(output).toContain('Start. Stop.');
161+
expect(output).toMatchSnapshot();
162+
});
163+
164+
it('strips bold markers from headers and renders them correctly', () => {
165+
const headers = ['**Bold Header**', 'Normal Header', '**Another Bold**'];
166+
const rows = [['Data 1', 'Data 2', 'Data 3']];
167+
const terminalWidth = 50;
168+
169+
const { lastFrame } = renderWithProviders(
170+
<TableRenderer
171+
headers={headers}
172+
rows={rows}
173+
terminalWidth={terminalWidth}
174+
/>,
175+
);
176+
177+
const output = lastFrame();
178+
// The output should NOT contain the literal '**'
179+
expect(output).not.toContain('**Bold Header**');
180+
expect(output).toContain('Bold Header');
181+
expect(output).toMatchSnapshot();
182+
});
183+
184+
it('handles wrapped bold headers without showing markers', () => {
185+
const headers = [
186+
'**Very Long Bold Header That Will Wrap**',
187+
'Short',
188+
'**Another Long Header**',
189+
];
190+
const rows = [['Data 1', 'Data 2', 'Data 3']];
191+
const terminalWidth = 40;
192+
193+
const { lastFrame } = renderWithProviders(
194+
<TableRenderer
195+
headers={headers}
196+
rows={rows}
197+
terminalWidth={terminalWidth}
198+
/>,
199+
);
200+
201+
const output = lastFrame();
202+
// Markers should be gone
203+
expect(output).not.toContain('**');
204+
expect(output).toContain('Very Long');
205+
expect(output).toMatchSnapshot();
206+
});
207+
208+
it('renders a complex table with mixed content lengths correctly', () => {
209+
const headers = [
210+
'Comprehensive Architectural Specification for the Distributed Infrastructure Layer',
211+
'Implementation Details for the High-Throughput Asynchronous Message Processing Pipeline with Extended Scalability Features and Redundancy Protocols',
212+
'Longitudinal Performance Analysis Across Multi-Regional Cloud Deployment Clusters',
213+
'Strategic Security Framework for Mitigating Sophisticated Cross-Site Scripting Vulnerabilities',
214+
'Key',
215+
'Status',
216+
'Version',
217+
'Owner',
218+
];
219+
const rows = [
220+
[
221+
'The primary architecture utilizes a decoupled microservices approach, leveraging container orchestration for scalability and fault tolerance in high-load scenarios.\n\nThis layer provides the fundamental building blocks for service discovery, load balancing, and inter-service communication via highly efficient protocol buffers.\n\nAdvanced telemetry and logging integrations allow for real-time monitoring of system health and rapid identification of bottlenecks within the service mesh.',
222+
'Each message is processed through a series of specialized workers that handle data transformation, validation, and persistent storage using a persistent queue.\n\nThe pipeline features built-in retry mechanisms with exponential backoff to ensure message delivery integrity even during transient network or service failures.\n\nHorizontal autoscaling is triggered automatically based on the depth of the processing queue, ensuring consistent performance during unexpected traffic spikes.',
223+
'Historical data indicates a significant reduction in tail latency when utilizing edge computing nodes closer to the geographic location of the end-user base.\n\nMonitoring tools have captured a steady increase in throughput efficiency since the introduction of the vectorized query engine in the primary data warehouse.\n\nResource utilization metrics demonstrate that the transition to serverless compute for intermittent tasks has resulted in a thirty percent cost optimization.',
224+
'A multi-layered defense strategy incorporates content security policies, input sanitization libraries, and regular automated penetration testing routines.\n\nDevelopers are required to undergo mandatory security training focusing on the OWASP Top Ten to ensure that security is integrated into the initial design phase.\n\nThe implementation of a robust Identity and Access Management system ensures that the principle of least privilege is strictly enforced across all environments.',
225+
'INF',
226+
'Active',
227+
'v2.4',
228+
'J. Doe',
229+
],
230+
];
231+
232+
const terminalWidth = 160;
233+
234+
const { lastFrame } = renderWithProviders(
235+
<TableRenderer
236+
headers={headers}
237+
rows={rows}
238+
terminalWidth={terminalWidth}
239+
/>,
240+
{ width: terminalWidth },
241+
);
242+
243+
const output = lastFrame();
244+
245+
expect(output).toContain('Comprehensive Architectural');
246+
expect(output).toContain('protocol buffers');
247+
expect(output).toContain('exponential backoff');
248+
expect(output).toContain('vectorized query engine');
249+
expect(output).toContain('OWASP Top Ten');
250+
expect(output).toContain('INF');
251+
expect(output).toContain('Active');
252+
expect(output).toContain('v2.4');
253+
// "J. Doe" might wrap due to column width constraints
254+
expect(output).toContain('J.');
255+
expect(output).toContain('Doe');
256+
257+
expect(output).toMatchSnapshot();
258+
});
259+
260+
it.each([
261+
{
262+
name: 'handles non-ASCII characters (emojis and Asian scripts) correctly',
263+
headers: ['Emoji 😃', 'Asian 汉字', 'Mixed 🚀 Text'],
264+
rows: [
265+
['Start 🌟 End', '你好世界', 'Rocket 🚀 Man'],
266+
['Thumbs 👍 Up', 'こんにちは', 'Fire 🔥'],
267+
],
268+
terminalWidth: 60,
269+
expected: ['Emoji 😃', 'Asian 汉字', '你好世界'],
270+
},
271+
{
272+
name: 'renders a table with only emojis and text correctly',
273+
headers: ['Happy 😀', 'Rocket 🚀', 'Heart ❤️'],
274+
rows: [
275+
['Smile 😃', 'Fire 🔥', 'Love 💖'],
276+
['Cool 😎', 'Star ⭐', 'Blue 💙'],
277+
],
278+
terminalWidth: 60,
279+
expected: ['Happy 😀', 'Smile 😃', 'Fire 🔥'],
280+
},
281+
{
282+
name: 'renders a table with only Asian characters and text correctly',
283+
headers: ['Chinese 中文', 'Japanese 日本語', 'Korean 한국어'],
284+
rows: [
285+
['你好', 'こんにちは', '안녕하세요'],
286+
['世界', '世界', '세계'],
287+
],
288+
terminalWidth: 60,
289+
expected: ['Chinese 中文', '你好', 'こんにちは'],
290+
},
291+
{
292+
name: 'renders a table with mixed emojis, Asian characters, and text correctly',
293+
headers: ['Mixed 😃 中文', 'Complex 🚀 日本語', 'Text 📝 한국어'],
294+
rows: [
295+
['你好 😃', 'こんにちは 🚀', '안녕하세요 📝'],
296+
['World 🌍', 'Code 💻', 'Pizza 🍕'],
297+
],
298+
terminalWidth: 80,
299+
expected: ['Mixed 😃 中文', '你好 😃', 'こんにちは 🚀'],
300+
},
301+
])('$name', ({ headers, rows, terminalWidth, expected }) => {
302+
const { lastFrame } = renderWithProviders(
303+
<TableRenderer
304+
headers={headers}
305+
rows={rows}
306+
terminalWidth={terminalWidth}
307+
/>,
308+
{ width: terminalWidth },
309+
);
310+
311+
const output = lastFrame();
312+
expected.forEach((text) => {
313+
expect(output).toContain(text);
314+
});
315+
expect(output).toMatchSnapshot();
316+
});
64317
});

0 commit comments

Comments
 (0)