Skip to content

Commit d471135

Browse files
committed
app: Add button to toggle terminal.
Also preserve terminal state on hide.
1 parent b990084 commit d471135

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

src/app/App.tsx

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import 'react-splitter-layout/lib/index.css';
55
import './app.scss';
66
import { Button, Classes, Spinner } from '@blueprintjs/core';
7-
import { Manual } from '@blueprintjs/icons';
7+
import { Console, Manual } from '@blueprintjs/icons';
88
import React, { useEffect, useState } from 'react';
99

1010
type SideView = 'off' | 'docs';
@@ -121,7 +121,26 @@ const App: React.FunctionComponent = () => {
121121
}
122122
};
123123

124-
const [terminalSplit, setTerminalSplit] = useLocalStorage('app-terminal-split', 30);
124+
const defaultTerminalSplit = 30;
125+
const [terminalSplit, setTerminalSplit] = useLocalStorage(
126+
'app-terminal-split',
127+
defaultTerminalSplit,
128+
);
129+
const [terminalVisible, setTerminalVisible] = useState(true);
130+
131+
const terminalOnClick = () => {
132+
if (terminalVisible && terminalSplit < 10) {
133+
// Treat manually dragged closed like closed, so clicking will
134+
// visually open it at default size.
135+
setTerminalSplit(defaultTerminalSplit);
136+
resetSplitterSize(
137+
'.splitter-layout.pb-show-terminal, .splitter-layout.pb-hide-terminal',
138+
defaultTerminalSplit,
139+
);
140+
} else {
141+
setTerminalVisible(!terminalVisible);
142+
}
143+
};
125144

126145
// Classes.DARK has to be applied to body element, otherwise it won't
127146
// affect portals
@@ -172,6 +191,11 @@ const App: React.FunctionComponent = () => {
172191
>
173192
<SplitterLayout
174193
vertical={true}
194+
customClassName={
195+
terminalVisible
196+
? 'pb-show-terminal'
197+
: 'pb-hide-terminal'
198+
}
175199
percentage={true}
176200
secondaryInitialSize={terminalSplit}
177201
onSecondaryPaneSizeChange={setTerminalSplit}
@@ -187,6 +211,17 @@ const App: React.FunctionComponent = () => {
187211
<Editor />
188212
</React.Suspense>
189213
<div className="pb-app-side-view-buttons">
214+
<Button
215+
large
216+
intent="primary"
217+
icon={<Console />}
218+
title={
219+
terminalVisible
220+
? i18n.translate('terminal.hide')
221+
: i18n.translate('terminal.show')
222+
}
223+
onClick={terminalOnClick}
224+
/>
190225
<Button
191226
large
192227
intent="primary"

src/app/app.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,14 @@ div.pb-hide-docs > :not(.layout-pane-primary) {
211211
width: 0 !important;
212212
min-width: 0 !important;
213213
}
214+
215+
// hide the terminal and resize separator
216+
// Same approach as docs: keep the terminal in the DOM to preserve its content,
217+
// but collapse the secondary pane to zero height.
218+
div.pb-hide-terminal > :not(.layout-pane-primary) {
219+
visibility: hidden;
220+
pointer-events: none;
221+
flex-basis: 0 !important;
222+
height: 0 !important;
223+
min-height: 0 !important;
224+
}

src/app/translations/en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,9 @@
88
"docs": {
99
"show": "Show documentation",
1010
"hide": "Hide documentation"
11+
},
12+
"terminal": {
13+
"show": "Show terminal",
14+
"hide": "Hide terminal"
1115
}
1216
}

0 commit comments

Comments
 (0)