()
| 117 | } |
| 118 | |
| 119 | componentDidMount() { |
| 120 | const {props} = this; |
| 121 | |
| 122 | this.termOptions = getTermOptions(props); |
| 123 | this.term = props.term || new Terminal(this.termOptions); |
| 124 | this.termDefaultBellSound = this.term.getOption('bellSound'); |
| 125 | |
| 126 | // The parent element for the terminal is attached and removed manually so |
| 127 | // that we can preserve it across mounts and unmounts of the component |
| 128 | this.termRef = props.term ? props.term.element!.parentElement! : document.createElement('div'); |
| 129 | this.termRef.className = 'term_fit term_term'; |
| 130 | |
| 131 | this.termWrapperRef?.appendChild(this.termRef); |
| 132 | |
| 133 | if (!props.term) { |
| 134 | const needTransparency = Color(props.backgroundColor).alpha() < 1; |
| 135 | let useWebGL = false; |
| 136 | if (props.webGLRenderer) { |
| 137 | if (needTransparency) { |
| 138 | console.warn( |
| 139 | 'WebGL Renderer has been disabled since it does not support transparent backgrounds yet. ' + |
| 140 | 'Falling back to canvas-based rendering.' |
| 141 | ); |
| 142 | } else if (!isWebgl2Supported()) { |
| 143 | console.warn('WebGL2 is not supported on your machine. Falling back to canvas-based rendering.'); |
| 144 | } else { |
| 145 | // Experimental WebGL renderer needs some more glue-code to make it work on Hyper. |
| 146 | // If you're working on enabling back WebGL, you will also need to look into `xterm-addon-ligatures` support for that renderer. |
| 147 | useWebGL = true; |
| 148 | } |
| 149 | } |
| 150 | Term.reportRenderer(props.uid, useWebGL ? 'WebGL' : 'Canvas'); |
| 151 | |
| 152 | const shallActivateWebLink = (event: Record<string, any> | undefined): boolean => { |
| 153 | // eslint-disable-next-line @typescript-eslint/no-unsafe-return |
| 154 | return event && (!props.webLinksActivationKey || event[`${props.webLinksActivationKey}Key`]); |
| 155 | }; |
| 156 | |
| 157 | // eslint-disable-next-line @typescript-eslint/unbound-method |
| 158 | this.term.attachCustomKeyEventHandler(this.keyboardHandler); |
| 159 | this.term.loadAddon(this.fitAddon); |
| 160 | this.term.loadAddon(this.searchAddon); |
| 161 | this.term.loadAddon( |
| 162 | new WebLinksAddon( |
| 163 | (event: MouseEvent | undefined, uri: string) => { |
| 164 | if (shallActivateWebLink(event)) void shell.openExternal(uri); |
| 165 | }, |
| 166 | { |
| 167 | // prevent default electron link handling to allow selection, e.g. via double-click |
| 168 | willLinkActivate: (event: MouseEvent | undefined) => { |
| 169 | event?.preventDefault(); |
| 170 | return shallActivateWebLink(event); |
| 171 | }, |
| 172 | priority: Date.now() |
| 173 | } |
| 174 | ) |
| 175 | ); |
| 176 | this.term.open(this.termRef); |
nothing calls this directly
no test coverage detected