Skip to content

Commit

Permalink
Fix command execution in terminal on Windows (#12620)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonah-iden authored Jun 23, 2023
1 parent 803efc9 commit 8493606
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 11 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/browser/common-frontend-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { AboutDialog } from './about-dialog';
import * as browser from './browser';
import URI from '../common/uri';
import { ContextKey, ContextKeyService } from './context-key-service';
import { OS, isOSX, isWindows } from '../common/os';
import { OS, isOSX, isWindows, EOL } from '../common/os';
import { ResourceContextKey } from './resource-context-key';
import { UriSelection } from '../common/selection';
import { StorageService } from './storage-service';
Expand Down Expand Up @@ -736,7 +736,7 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
isEnabled: uris => Array.isArray(uris) && uris.some(uri => uri instanceof URI),
execute: async uris => {
if (uris.length) {
const lineDelimiter = isWindows ? '\r\n' : '\n';
const lineDelimiter = EOL;
const text = uris.map(resource => resource.path.fsPath()).join(lineDelimiter);
await this.clipboardService.writeText(text);
} else {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/browser/preloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ async function loadBackendOS(): Promise<void> {
OS.backend.isOSX = isOSX;
OS.backend.isWindows = isWindows;
OS.backend.type = () => osType;
OS.backend.EOL = isWindows ? '\r\n' : '\n';
}

function initBackground(): void {
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/common/os.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ function is(userAgent: string, platform: string): boolean {
export const isWindows = is('Windows', 'win32');
export const isOSX = is('Mac', 'darwin');

export const EOL = isWindows ? '\r\n' : '\n';

export type CMD = [string, string[]];
export function cmd(command: string, ...args: string[]): CMD {
return [
Expand Down Expand Up @@ -65,7 +67,8 @@ export namespace OS {
export const backend = {
type,
isWindows,
isOSX
isOSX,
EOL
};

}
2 changes: 1 addition & 1 deletion packages/monaco/src/browser/monaco-text-model-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class MonacoTextModelService implements ITextModelService {
if (eol && eol !== 'auto') {
return eol;
}
return OS.backend.isWindows ? '\r\n' : '\n';
return OS.backend.EOL;
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
codicon,
TopDownTreeIterator
} from '@theia/core/lib/browser';
import { CancellationTokenSource, Emitter, Event, isWindows, ProgressService } from '@theia/core';
import { CancellationTokenSource, Emitter, EOL, Event, ProgressService } from '@theia/core';
import {
EditorManager, EditorDecoration, TrackedRangeStickiness, OverviewRulerLane,
EditorWidget, EditorOpenerOptions, FindMatch
Expand Down Expand Up @@ -1210,7 +1210,7 @@ export class SearchInWorkspaceResultTreeWidget extends TreeWidget {
strings.push(string);
}
}
return strings.join(isWindows ? '\r\n' : '\n');
return strings.join(EOL);
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/task/src/node/task-abstract-line-matcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { isWindows } from '@theia/core/lib/common/os';
import { EOL } from '@theia/core/lib/common/os';
import { Diagnostic, DiagnosticSeverity, Range } from '@theia/core/shared/vscode-languageserver-protocol';
import {
FileLocationKind, ProblemMatcher, ProblemPattern,
Expand All @@ -31,7 +31,7 @@ import { URI as vscodeURI } from '@theia/core/shared/vscode-uri';
import { Severity } from '@theia/core/lib/common/severity';
import { MAX_SAFE_INTEGER } from '@theia/core/lib/common/numbers';

const endOfLine: string = isWindows ? '\r\n' : '\n';
const endOfLine: string = EOL;

export interface ProblemData {
kind?: ProblemLocationKind;
Expand Down
2 changes: 1 addition & 1 deletion packages/terminal/src/browser/terminal-widget-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget
}

async executeCommand(commandOptions: CommandLineOptions): Promise<void> {
this.sendText(this.shellCommandBuilder.buildCommand(await this.processInfo, commandOptions) + '\n');
this.sendText(this.shellCommandBuilder.buildCommand(await this.processInfo, commandOptions) + OS.backend.EOL);
}

scrollLineUp(): void {
Expand Down
4 changes: 2 additions & 2 deletions packages/workspace/src/browser/workspace-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { WorkspaceCompareHandler } from './workspace-compare-handler';
import { FileDownloadCommands } from '@theia/filesystem/lib/browser/download/file-download-command-contribution';
import { FileSystemCommands } from '@theia/filesystem/lib/browser/filesystem-frontend-contribution';
import { WorkspaceInputDialog } from './workspace-input-dialog';
import { Emitter, Event, isWindows, OS } from '@theia/core/lib/common';
import { Emitter, EOL, Event, OS } from '@theia/core/lib/common';
import { FileService } from '@theia/filesystem/lib/browser/file-service';
import { FileStat } from '@theia/filesystem/lib/common/files';
import { nls } from '@theia/core/lib/common/nls';
Expand Down Expand Up @@ -313,7 +313,7 @@ export class WorkspaceCommandContribution implements CommandContribution {
isEnabled: uris => !!uris.length,
isVisible: uris => !!uris.length,
execute: async uris => {
const lineDelimiter = isWindows ? '\r\n' : '\n';
const lineDelimiter = EOL;
const text = uris.map((uri: URI) => {
const workspaceRoot = this.workspaceService.getWorkspaceRootUri(uri);
if (workspaceRoot) {
Expand Down

0 comments on commit 8493606

Please sign in to comment.