Skip to content

Commit cd27079

Browse files
committed
feature(gritty) add support of fontFamily
1 parent 7279bd9 commit cd27079

File tree

5 files changed

+36
-7
lines changed

5 files changed

+36
-7
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ Start `gritty`, and go to url `http://localhost:1337`
4343
```js
4444
const prefix = '/gritty'; // default
4545
const env = {}; // default
46+
const fontFamily = 'Courier'; // default
4647

4748
gritty('body', {
4849
prefix,
4950
env,
51+
fontFamily,
5052
});
5153
```
5254

client/gritty.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
require('xterm/dist/xterm.css');
4-
require('../css/gritty.css');
54

65
const fit = require('xterm/lib/addons/fit');
76
const currify = require('currify/legacy');
@@ -33,10 +32,14 @@ module.exports._onTermResize = _onTermResize;
3332
module.exports._onTermData = _onTermData;
3433
module.exports._onWindowResize = _onWindowResize;
3534

35+
const defaultFontFamily = 'Menlo, Consolas, "Liberation Mono", Monaco, "Lucida Console", monospace';
36+
module.exports._defaultFontFamily = defaultFontFamily;
37+
3638
function gritty(element, options = {}) {
3739
const el = getEl(element);
3840

3941
const socketPath = options.socketPath || '';
42+
const fontFamily = options.fontFamily || defaultFontFamily;
4043
const prefix = options.prefix || '/gritty';
4144
const env = getEnv(options.env || {});
4245

@@ -47,15 +50,16 @@ function gritty(element, options = {}) {
4750
return createTerminal(el, {
4851
env,
4952
socket,
53+
fontFamily
5054
});
5155
}
5256

53-
function createTerminal(terminalContainer, {env, socket}) {
57+
function createTerminal(terminalContainer, {env, socket, fontFamily}) {
5458
const terminal = new Terminal({
5559
scrollback: 1000,
5660
tabStopWidth: 4,
57-
theme: 'gritty',
5861
experimentalCharAtlas: 'dynamic',
62+
fontFamily,
5963
});
6064

6165
terminal.open(terminalContainer);

css/gritty.css

Lines changed: 0 additions & 3 deletions
This file was deleted.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
"watch:client:dev": "redrun 6to5:client:dev -- --watch",
3131
"wisdom": "npm run build",
3232
"build": "redrun 6to5:*",
33+
"build:start": "redrun build:client start",
34+
"build:start:dev": "redrun build:client:dev start:dev",
3335
"build:client": "redrun 6to5:client",
3436
"build:client:dev": "redrun 6to5:client:dev",
3537
"watch:lint": "nodemon -w client -w server -w webpack.config.js -x 'redrun lint'",

test/client/gritty.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const {
4848
_onTermResize,
4949
_onTermData,
5050
_onWindowResize,
51+
_defaultFontFamily,
5152
} = require('../../client/gritty');
5253

5354
test('gritty: Terminal: new', (t) => {
@@ -65,7 +66,8 @@ test('gritty: Terminal: args', (t) => {
6566
const args = {
6667
scrollback: 1000,
6768
tabStopWidth: 4,
68-
theme: 'gritty',
69+
experimentalCharAtlas: 'dynamic',
70+
fontFamily: _defaultFontFamily,
6971
};
7072

7173
gritty();
@@ -76,6 +78,28 @@ test('gritty: Terminal: args', (t) => {
7678
t.end();
7779
});
7880

81+
test('gritty: Terminal: args: fontFamily', (t) => {
82+
before();
83+
84+
const fontFamily = 'Droid Sans Mono';
85+
const el = {};
86+
const args = {
87+
scrollback: 1000,
88+
tabStopWidth: 4,
89+
experimentalCharAtlas: 'dynamic',
90+
fontFamily,
91+
};
92+
93+
gritty(el, {
94+
fontFamily
95+
});
96+
97+
t.ok(Terminal.calledWith(args), 'should have been called with args');
98+
99+
after();
100+
t.end();
101+
});
102+
79103
test('gritty: Terminal: open', (t) => {
80104
const el = {};
81105

0 commit comments

Comments
 (0)