Xterm.js: How to set terminal colors?

Created on 31 May 2016  路  9Comments  路  Source: xtermjs/xterm.js

I was looking into using xterm.js for vscode's integrated terminal but the colors seem to be gone after I swapped out jeremyramin/term.js.

image

Expected:

image

This is how I was setting the colors:

terminal.colors = [...]; // array of 16 string in format '#rrggbb'
terminal.refresh(0, terminal.rows);

Most helpful comment

@zwhitchcox the current way to do this:

const term = new Terminal({
  'theme', { background: '#fdf6e3' }
});

// or

term.setOption('theme', { background: '#fdf6e3' });

All 9 comments

I believe xterm.js uses an external stylesheet instead of styles embedded into the JavaScript like term.js. Therefore you have to import xterm.css in your HTML. If you want to change the default colors, the stylesheet makes it a lot easier to override certain color rules. Adding it also makes the <textarea> used for input disappear.

Thanks, that clears that up :)

Hi @Tyriar, @petschekr got it completely right; xterm.js depends on xterm.css for proper color rendering, in order to allow theming of the terminal.

I guess it would be helpful to document this in a more visible place though 馃槉 .

This does not allow you to set the background color of the terminal

I set the background terminal color with

term._core.renderer.colorManager.colors.background = {
  css: "#fdf6e3",
  rgba: "rgb(253, 246, 227)",
}

@zwhitchcox the current way to do this:

const term = new Terminal({
  'theme', { background: '#fdf6e3' }
});

// or

term.setOption('theme', { background: '#fdf6e3' });

On a related note, are there any known themes out there or NPM packages containing themes?

@sdegutis not that I'm aware of

@Tyriar Thanks, I'll just check out the ones VS Code comes with.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

circuitry2 picture circuitry2  路  4Comments

LB-J picture LB-J  路  3Comments

chris-tse picture chris-tse  路  4Comments

goxr3plus picture goxr3plus  路  3Comments

zhangjie2012 picture zhangjie2012  路  3Comments