Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/core/src/services/shellExecutionService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,24 @@ describe('ShellExecutionService', () => {
);
});

it('should not wrap long lines in the final output', async () => {
// Set a small width to force wrapping
const narrowConfig = { ...shellExecutionConfig, terminalWidth: 10 };
const longString = '123456789012345'; // 15 chars, should wrap at 10

const { result } = await simulateExecution(
'long-line-command',
(pty) => {
pty.onData.mock.calls[0][0](longString);
pty.onExit.mock.calls[0][0]({ exitCode: 0, signal: null });
},
narrowConfig,
);

expect(result.exitCode).toBe(0);
expect(result.output.trim()).toBe(longString);
});

it('should not add extra padding but preserve explicit trailing whitespace', async () => {
const { result } = await simulateExecution('cmd', (pty) => {
// "value" should not get terminal-width padding
Expand Down
24 changes: 22 additions & 2 deletions packages/core/src/services/shellExecutionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,28 @@ const getFullBufferText = (terminal: pkg.Terminal): string => {
const lines: string[] = [];
for (let i = 0; i < buffer.length; i++) {
const line = buffer.getLine(i);
const lineContent = line ? line.translateToString(true) : '';
lines.push(lineContent);
if (!line) {
continue;
}
// If the NEXT line is wrapped, it means it's a continuation of THIS line.
// We should not trim the right side of this line because trailing spaces
// might be significant parts of the wrapped content.
// If it's not wrapped, we trim normally.
let trimRight = true;
if (i + 1 < buffer.length) {
const nextLine = buffer.getLine(i + 1);
if (nextLine?.isWrapped) {
trimRight = false;
}
}
Comment on lines +126 to +132
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The current logic for determining trimRight may cause a regression. For the last line in the buffer, trimRight defaults to true, which will remove any intentional trailing whitespace. This could break tests that expect trailing whitespace to be preserved, such as the existing should not add extra padding but preserve explicit trailing whitespace test.

The logic should be adjusted to not trim the last line of the buffer if it's a standalone line (i.e., not part of a wrapped sequence). This preserves potentially significant trailing whitespace.

    let trimRight = true;
    if (i + 1 < buffer.length) {
      const nextLine = buffer.getLine(i + 1);
      if (nextLine?.isWrapped) {
        trimRight = false;
      }
    } else if (!line.isWrapped) {
      // Don't trim the last line of the buffer if it's a standalone line
      // to preserve potentially significant trailing whitespace.
      trimRight = false;
    }


const lineContent = line.translateToString(trimRight);

if (line.isWrapped && lines.length > 0) {
lines[lines.length - 1] += lineContent;
} else {
lines.push(lineContent);
}
}

// Remove trailing empty lines
Expand Down