Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose show texture atlas command #162993

Merged
merged 2 commits into from
Oct 7, 2022
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
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.isOpen)
});
}
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