Skip to content

Commit 27e73fe

Browse files
committed
Context menu item to clear terminal
Closes #3135 Signed-off-by: David Thompson <davthomp@redhat.com>
1 parent 9aa147e commit 27e73fe

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/webview/openshift-terminal/app/terminalInstance.tsx

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ import 'xterm/css/xterm.css';
1414
import '../../common/scrollbar.scss';
1515

1616
/**
17-
* Clone of VS Code's context menu with "Copy" and "Select All" items.
17+
* Clone of VS Code's context menu with "Copy", "Select All", and "Clear" items.
1818
*/
1919
const TerminalContextMenu = (props: {
20+
onClearHandler: React.MouseEventHandler<HTMLButtonElement>;
2021
onCopyHandler: React.MouseEventHandler<HTMLButtonElement>;
2122
onSelectAllHandler: React.MouseEventHandler<HTMLButtonElement>;
2223
}) => {
@@ -77,6 +78,28 @@ const TerminalContextMenu = (props: {
7778
<Typography variant="body1">Ctrl+Shift+A</Typography>
7879
</Stack>
7980
</Button>
81+
<Button
82+
variant="text"
83+
onClick={props.onClearHandler}
84+
sx={{
85+
width: '100%',
86+
textTransform: 'none',
87+
'&:hover': {
88+
backgroundColor:
89+
'color-mix(in srgb, var(--vscode-button-background) 50%, black)',
90+
},
91+
paddingY: '4px',
92+
}}
93+
>
94+
<Stack
95+
direction="row"
96+
justifyContent="flex-start"
97+
marginX="13px"
98+
style={{ width: '100%' }}
99+
>
100+
<Typography variant="body1">Clear</Typography>
101+
</Stack>
102+
</Button>
80103
</Stack>
81104
</Paper>
82105
);
@@ -121,6 +144,16 @@ export const TerminalInstance = (props: {
121144
setContextMenuOpen(false);
122145
};
123146

147+
const handleClear = () => {
148+
term.clear();
149+
window.vscodeApi.postMessage({
150+
kind: 'termClear',
151+
data: {
152+
uuid: props.uuid,
153+
},
154+
});
155+
}
156+
124157
// The xtermjs addon that can be used to resize the terminal according to the size of the div
125158
const fitAddon = React.useMemo(() => {
126159
return new FitAddon();
@@ -336,6 +369,7 @@ export const TerminalInstance = (props: {
336369
<TerminalContextMenu
337370
onCopyHandler={handleCopy}
338371
onSelectAllHandler={handleSelectAll}
372+
onClearHandler={handleClear}
339373
/>
340374
</div>
341375
<div

src/webview/openshift-terminal/openShiftTerminal.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,10 @@ class OpenShiftTerminal {
340340
this.forceKill();
341341
this._sendExitMessage();
342342
}
343+
344+
public clear(): void {
345+
this._headlessTerm.clear();
346+
}
343347
}
344348

345349
/**
@@ -429,6 +433,8 @@ export class OpenShiftTerminalManager implements WebviewViewProvider {
429433
});
430434
} else if (message.kind === 'termSuspend') {
431435
terminal.stopRendering();
436+
} else if (message.kind === 'termClear') {
437+
terminal.clear();
432438
} else if (message.kind === 'input') {
433439
terminal.write(message.data.data);
434440
} else if (message.kind === 'resize') {

0 commit comments

Comments
 (0)