129 |
130 |
131 |
132 |
133 |
134 | { this.state.loading &&
135 |
136 |
{this.state.loading}
137 |
}
138 |
139 |
140 | {this.state.fullscreen &&
this._onFullscreenResize(e)}>
}
142 |
143 |
this.setFiles(files)}
144 | fullscreen={this.state.fullscreen} exitFullscreen={() => this.exitFullscreen()}
145 | runCommand={line => this.runCommandFromOpenSSLGUI(line)} cipherList={this.state.openSSL.cipherList}
146 | curvesList={this.state.openSSL.curvesList} hashfunList={this.state.openSSL.hashfunList} />
147 |
148 | {!this.state.fullscreen && }
160 |
161 |
162 | )
163 | }
164 |
165 | componentDidUpdate(prevProps, prevState) {
166 |
167 | // resize on fullscreen mode change
168 | if(this.state.fullscreen != prevState.fullscreen)
169 | this.wasmTerm._xtermFitAddon.fit()
170 |
171 | return true // render anyway
172 | }
173 |
174 |
175 | setLoading(value, callback) { // value is string or boolean
176 | if(value) this.setState({ loading: value }, callback)
177 | else this.setState({ loading: false }, callback)
178 | }
179 |
180 | setFiles(files) {
181 | this.wasmTerm._wasmFsFiles = files
182 | this.setState(() => ({ files: this.wasmTerm._wasmFsFiles }))
183 | // state is passed as a function to use latest reference to wasmFsFiles
184 | }
185 |
186 |
187 | async runCommandFromOpenSSLGUI(line) {
188 |
189 | // only run one command at a time
190 | if(this.wasmTerm._isRunningCommand) return
191 |
192 | // show command on terminal
193 | this.wasmTerm._xterm.write(line + "\r\n")
194 |
195 | // abort current repl
196 | this.wasmTerm._xtermEcho.abortRead("Everything is fine, running command from GUI")
197 |
198 | // add command to history
199 | this.wasmTerm._xtermEcho.history.push(line)
200 |
201 | // show loading animation
202 | await this.wasmTerm.onBeforeCommandRun()
203 |
204 | // execute line of commands
205 | await this.wasmTerm.runLine(line)
206 |
207 | // print newline after
208 | this.wasmTerm._xterm.write("\r\n")
209 |
210 | // hide loading animation
211 | await this.wasmTerm.onCommandRunFinish()
212 |
213 | // restart repl
214 | this.wasmTerm.repl()
215 |
216 | }
217 |
218 | _onFullscreenResize(e) {
219 | const x = e.clientX, y = e.clientY
220 | const parentElem = e.target.parentNode
221 | const leftElem = e.target.previousElementSibling
222 | const leftWidth = leftElem.getBoundingClientRect().width
223 | document.onmousemove = (e) => {
224 | const dx = e.clientX - x, dy = e.clientY - y
225 | const newLeftWidth = ((leftWidth + dx) * 100) / parentElem.getBoundingClientRect().width
226 | leftElem.style.width = newLeftWidth + "%"
227 | this.wasmTerm._xtermFitAddon.fit()
228 | }
229 | document.onmouseup = () => document.onmousemove = document.onmouseup = null
230 | }
231 |
232 | enterFullscreen() {
233 | this.setState({ fullscreen: true })
234 | document.getElementsByTagName("html")[0].style.overflow = "hidden"
235 | }
236 |
237 | exitFullscreen() {
238 | this.setState({ fullscreen: false })
239 | document.getElementsByTagName("html")[0].style.overflow = ""
240 | }
241 |
242 | }
243 |
244 | export default CommandLine
245 |
--------------------------------------------------------------------------------
/sources/openssl-gui/CommandField.js:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import { Trans } from "react-i18next"
3 |
4 | import Button from "react-bootstrap/Button"
5 | import FormControl from "react-bootstrap/FormControl"
6 | import InputGroup from "react-bootstrap/InputGroup"
7 |
8 | class CommandField extends React.Component {
9 |
10 | render() {
11 | return (
12 |
13 |