@@ -14,9 +14,10 @@ import 'xterm/css/xterm.css';
1414import '../../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 */
1919const 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
0 commit comments