Skip to content

Commit 5d9d2fb

Browse files
committed
feat(runtime): option for setting terminal open by default
1 parent 1f022aa commit 5d9d2fb

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

docs/tutorialkit.dev/src/content/docs/reference/configuration.mdx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ Configures one or more terminals. TutorialKit provides two types of terminals: r
148148

149149
You can define which terminal panel will be active by default by specifying the `activePanel` value. The value is the given terminal's position in the `panels` array. If you omit the `activePanel` property, the first panel will be the active one.
150150

151+
You can set terminal open by default by specifying the `open` value.
152+
151153
An interactive terminal will disable the output redirect syntax by default. For instance, you cannot create a file `world.txt` with the contents `hello` using the command `echo hello > world.txt`. The reason is that this could disrupt the lesson if a user overwrites certain files. To allow output redirection, you can change the behavior with the `allowRedirects` setting. You can define this setting either per panel or for all panels at once.
152154

153155
Additionally, you may not want users to run arbitrary commands. For example, if you are creating a lesson about `vitest`, you could specify that the only command the user can run is `vitest` by providing a list of `allowCommands`. Any other command executed by the user will be blocked. You can define the `allowCommands` setting either per panel or for all panels at once.
@@ -162,7 +164,8 @@ type Terminal = {
162164
panels: TerminalPanel[],
163165
activePanel?: number,
164166
allowRedirects?: boolean,
165-
allowCommands?: string[]
167+
allowCommands?: string[],
168+
open?: boolean,
166169
}
167170
168171
type TerminalPanel = TerminalType
@@ -177,6 +180,7 @@ Example value:
177180

178181
```yaml
179182
terminal:
183+
open: true
180184
activePanel: 1
181185
panels:
182186
- ['output', 'Dev Server']

packages/components/react/src/Panels/WorkspacePanel.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ export function WorkspacePanel({ tutorialStore, theme }: Props) {
9393
setHelpAction('reset');
9494
}
9595

96+
if (tutorialStore.terminalConfig.value?.defaultOpen) {
97+
showTerminal();
98+
}
99+
96100
return () => unsubscribe();
97101
}, [tutorialStore.ref]);
98102

packages/runtime/src/webcontainer/terminal-config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { ITerminal } from '../utils/terminal.js';
55
interface NormalizedTerminalConfig {
66
panels: TerminalPanel[];
77
activePanel: number;
8+
defaultOpen: boolean;
89
}
910

1011
interface TerminalPanelOptions {
@@ -30,6 +31,10 @@ export class TerminalConfig {
3031
get activePanel() {
3132
return this._config.activePanel;
3233
}
34+
35+
get defaultOpen() {
36+
return this._config.defaultOpen;
37+
}
3338
}
3439

3540
const TERMINAL_PANEL_TITLES: Record<TerminalPanelType, string> = {
@@ -192,6 +197,7 @@ function normalizeTerminalConfig(config?: TerminalSchema): NormalizedTerminalCon
192197
return {
193198
panels: [],
194199
activePanel,
200+
defaultOpen: false,
195201
};
196202
}
197203

@@ -203,6 +209,7 @@ function normalizeTerminalConfig(config?: TerminalSchema): NormalizedTerminalCon
203209
return {
204210
panels: [new TerminalPanel('output')],
205211
activePanel,
212+
defaultOpen: false,
206213
};
207214
}
208215

@@ -254,5 +261,6 @@ function normalizeTerminalConfig(config?: TerminalSchema): NormalizedTerminalCon
254261
return {
255262
activePanel,
256263
panels,
264+
defaultOpen: config.open || false,
257265
};
258266
}

packages/types/src/schemas/common.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ export const terminalSchema = z.union([
7474
z.boolean(),
7575

7676
z.strictObject({
77+
open: z.boolean().optional().describe('Defines if terminal should be open by default'),
78+
7779
panels: z.union([
7880
// either literally just `output`
7981
z.literal('output'),

0 commit comments

Comments
 (0)