Skip to content

Commit b89511c

Browse files
authored
Add notice about main terminal (codesandbox#2984)
* Add notice about main terminal * Fix typecheck
1 parent 1179b68 commit b89511c

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

packages/app/src/app/components/Preview/DevTools/Terminal/Shell/Term.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ import * as fit from 'xterm/lib/addons/fit/fit';
55

66
import ResizeObserver from 'resize-observer-polyfill';
77

8+
import { notificationState } from '@codesandbox/common/lib/utils/notifications';
9+
import { dispatch } from 'codesandbox-api';
10+
import { NotificationStatus } from '@codesandbox/notifications';
811
import getTerminalTheme, { VSTheme } from '../terminal-theme';
912
import { TerminalWithFit } from '../types';
1013

1114
type Props = {
1215
theme: VSTheme;
16+
owned: boolean;
1317
hidden: boolean;
1418
onTerminalInitialized: (term: TerminalWithFit) => void;
1519
};
@@ -35,6 +39,37 @@ export class TerminalComponentNoTheme extends React.PureComponent<Props> {
3539
this.resizeTerminal();
3640
window.addEventListener('resize', this.listenForResize);
3741

42+
let shownNotification = false;
43+
44+
this.term.on('data', () => {
45+
// This is readonly, so let the user know they need to open a new
46+
// terminal
47+
48+
if (!shownNotification) {
49+
if (this.props.owned) {
50+
notificationState.addNotification({
51+
title: 'Terminal Read-Only',
52+
message:
53+
"The main terminal is read-only and runs what's defined in package.json#start, you can create a new terminal to input commands",
54+
status: NotificationStatus.NOTICE,
55+
actions: {
56+
primary: [
57+
{
58+
label: 'Create Terminal',
59+
run: () => {
60+
dispatch({
61+
type: 'codesandbox:create-shell',
62+
});
63+
},
64+
},
65+
],
66+
},
67+
});
68+
}
69+
shownNotification = true;
70+
}
71+
});
72+
3873
this.props.onTerminalInitialized(this.term);
3974
};
4075

packages/app/src/app/components/Preview/DevTools/Terminal/Shell/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { TerminalComponent } from './Term';
1010
type Props = {
1111
id: string;
1212
theme: VSTheme;
13+
owned: boolean;
1314
script?: string;
1415
closeShell: () => void;
1516
endShell: () => void;
@@ -107,9 +108,10 @@ class ShellComponent extends React.PureComponent<Props> {
107108
}
108109

109110
render() {
110-
const { hidden, theme } = this.props;
111+
const { hidden, theme, owned } = this.props;
111112
return (
112113
<TerminalComponent
114+
owned={owned}
113115
hidden={hidden}
114116
theme={theme}
115117
onTerminalInitialized={this.initializeTerminal}

packages/app/src/app/components/Preview/DevTools/Terminal/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ class DevToolTerminal extends React.Component<
152152
<div style={{ position: 'relative', flex: 'auto' }}>
153153
<TerminalComponent
154154
hidden={hidden || selectedShell !== undefined}
155+
owned={this.props.owned}
155156
theme={theme}
156157
onTerminalInitialized={this.setTerminal}
157158
/>
@@ -161,6 +162,7 @@ class DevToolTerminal extends React.Component<
161162
id={shell.id}
162163
script={shell.script}
163164
ended={shell.ended}
165+
owned={this.props.owned}
164166
hidden={hidden || shell.id !== this.state.selectedShell}
165167
closeShell={() => this.closeShell(shell.id)}
166168
endShell={() => this.endShell(shell.id)}

0 commit comments

Comments
 (0)