MCPcopy Index your code
hub / github.com/vercel/hyper / Term

Class Term

lib/components/term.tsx:85–464  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83};
84
85export default class Term extends React.PureComponent<TermProps> {
86 termRef: HTMLElement | null;
87 termWrapperRef: HTMLElement | null;
88 termOptions: ITerminalOptions;
89 disposableListeners: IDisposable[];
90 termDefaultBellSound: string | null;
91 fitAddon: FitAddon;
92 searchAddon: SearchAddon;
93 static rendererTypes: Record<string, string>;
94 term!: Terminal;
95 resizeObserver!: ResizeObserver;
96 resizeTimeout!: NodeJS.Timeout;
97 constructor(props: TermProps) {
98 super(props);
99 props.ref_(props.uid, this);
100 this.termRef = null;
101 this.termWrapperRef = null;
102 this.termOptions = {};
103 this.disposableListeners = [];
104 this.termDefaultBellSound = null;
105 this.fitAddon = new FitAddon();
106 this.searchAddon = new SearchAddon();
107 }
108
109 // The main process shows this in the About dialog
110 static reportRenderer(uid: string, type: string) {
111 const rendererTypes = Term.rendererTypes || {};
112 if (rendererTypes[uid] !== type) {
113 rendererTypes[uid] = type;
114 Term.rendererTypes = rendererTypes;
115 window.rpc.emit('info renderer', {uid, type});
116 }
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()) {

Callers

nothing calls this directly

Calls 3

fitResizeMethod · 0.95
processClipboardFunction · 0.85
focusMethod · 0.80

Tested by

no test coverage detected