Skip to content

Commit

Permalink
Expose show texture atlas command
Browse files Browse the repository at this point in the history
This creates a file in the workspace and opens it currently, this could
be made nicer but it does the job for now.

Fixes #158920
  • Loading branch information
Tyriar committed Oct 7, 2022
1 parent 30a8ab3 commit 7d1b7b6
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/vs/workbench/contrib/terminal/browser/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,11 @@ export interface IXtermTerminal {

readonly onDidChangeSelection: Event<void>;

/**
* Gets a view of the current texture atlas used by the renderers.
*/
readonly textureAtlas: Promise<ImageBitmap> | undefined;

/**
* The position of the terminal.
*/
Expand Down
39 changes: 39 additions & 0 deletions src/vs/workbench/contrib/terminal/browser/terminalActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ import { clearShellFileHistory, getCommandHistory } from 'vs/workbench/contrib/t
import { Categories } from 'vs/platform/action/common/actionCommonCategories';
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
import { TerminalCapability } from 'vs/platform/terminal/common/capabilities/capabilities';
import { IFileService } from 'vs/platform/files/common/files';
import { VSBuffer } from 'vs/base/common/buffer';

export const switchTerminalActionViewItemSeparator = '\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500';
export const switchTerminalShowTabsTitle = localize('showTerminalTabs', "Show Tabs");
Expand Down Expand Up @@ -2226,6 +2228,43 @@ export function registerTerminalActions() {
clearShellFileHistory();
}
});
registerAction2(class extends Action2 {
constructor() {
super({
id: TerminalCommandId.ShowTextureAtlas,
title: { value: localize('workbench.action.terminal.showTextureAtlas', "Show Terminal Texture Atlas"), original: 'Show Terminal Texture Atlas' },
f1: true,
category: Categories.Developer.value,
precondition: ContextKeyExpr.or(TerminalContextKeys.processSupported, TerminalContextKeys.terminalHasBeenCreated)
});
}
async run(accessor: ServicesAccessor) {
const terminalService = accessor.get(ITerminalService);
const fileService = accessor.get(IFileService);
const openerService = accessor.get(IOpenerService);
const workspaceContextService = accessor.get(IWorkspaceContextService);
const bitmap = await terminalService.activeInstance?.xterm?.textureAtlas;
if (!bitmap) {
return;
}
const cwdUri = workspaceContextService.getWorkspace().folders[0].uri;
const fileUri = URI.joinPath(cwdUri, 'textureAtlas.png');
const canvas = document.createElement('canvas');
canvas.width = bitmap.width;
canvas.height = bitmap.height;
const ctx = canvas.getContext('bitmaprenderer');
if (!ctx) {
return;
}
ctx.transferFromImageBitmap(bitmap);
const blob = await new Promise<Blob | null>((res) => canvas.toBlob(res));
if (!blob) {
return;
}
await fileService.writeFile(fileUri, VSBuffer.wrap(new Uint8Array(await blob.arrayBuffer())));
openerService.open(fileUri);
}
});
registerAction2(class extends Action2 {
constructor() {
super({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ export class XtermTerminal extends DisposableStore implements IXtermTerminal, II
}
get target(): TerminalLocation | undefined { return this._target; }

get textureAtlas(): Promise<ImageBitmap> | undefined {
const canvas = this._webglAddon?.textureAtlas || this._canvasAddon?.textureAtlas;
if (!canvas) {
return undefined;
}
return createImageBitmap(canvas);
}

/**
* @param xtermCtor The xterm.js constructor, this is passed in so it can be fetched lazily
* outside of this class such that {@link raw} is not nullable.
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/contrib/terminal/common/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ export const enum TerminalCommandId {
SetDimensions = 'workbench.action.terminal.setDimensions',
ClearCommandHistory = 'workbench.action.terminal.clearCommandHistory',
WriteDataToTerminal = 'workbench.action.terminal.writeDataToTerminal',
ShowTextureAtlas = 'workbench.action.terminal.showTextureAtlas',
}

export const DEFAULT_COMMANDS_TO_SKIP_SHELL: string[] = [
Expand Down

0 comments on commit 7d1b7b6

Please sign in to comment.