| 16 | } |
| 17 | |
| 18 | function createTerminal(options: IPlayerOptions): xterm.Terminal { |
| 19 | const opts: xterm.ITerminalOptions = { |
| 20 | fontSize: options.fontSize || 15, |
| 21 | fontFamily: options.fontFamily || 'Consolas, Menlo', |
| 22 | fontWeight: options.fontWeight || 'normal', |
| 23 | fontWeightBold: options.fontWeightBold || 'bold', |
| 24 | theme: options.theme || {}, |
| 25 | } |
| 26 | |
| 27 | // Workaround: xterm.js only supports browser env via global variable Terminal, |
| 28 | // which is different from typescript usage. |
| 29 | // Use constructor from window.Terminal if it's browser env |
| 30 | if (xterm.Terminal) { |
| 31 | return new xterm.Terminal(opts) |
| 32 | } |
| 33 | if (window) { |
| 34 | return new window.Terminal(opts) |
| 35 | } |
| 36 | throw new Error('Cannot create xterm Terminal object') |
| 37 | } |
| 38 | |
| 39 | export class XtermPlayer implements XtermPlayerApi { |
| 40 | static readonly THEME_SOLARIZED_DARK: xterm.ITheme = SOLARIZED_DARK |