repl: don't use tty control codes when $TERM is set to "dumb" · nodejs/node@ccea33d (original) (raw)

``

1

`+

'use strict';

`

``

2

+

``

3

`+

// Flags: --expose-internals

`

``

4

+

``

5

`+

const common = require('../common');

`

``

6

`+

const stream = require('stream');

`

``

7

`+

const REPL = require('internal/repl');

`

``

8

`+

const assert = require('assert');

`

``

9

`+

const inspect = require('util').inspect;

`

``

10

+

``

11

`+

const tests = [{

`

``

12

`+

env: {},

`

``

13

`+

expected: { terminal: true, useColors: true }

`

``

14

`+

},

`

``

15

`+

{

`

``

16

`+

env: { NODE_DISABLE_COLORS: '1' },

`

``

17

`+

expected: { terminal: true, useColors: false }

`

``

18

`+

},

`

``

19

`+

{

`

``

20

`+

env: { NODE_NO_READLINE: '1' },

`

``

21

`+

expected: { terminal: false, useColors: false }

`

``

22

`+

},

`

``

23

`+

{

`

``

24

`+

env: { TERM: 'dumb' },

`

``

25

`+

expected: { terminal: true, useColors: false }

`

``

26

`+

},

`

``

27

`+

{

`

``

28

`+

env: { NODE_NO_READLINE: '1', NODE_DISABLE_COLORS: '1' },

`

``

29

`+

expected: { terminal: false, useColors: false }

`

``

30

`+

},

`

``

31

`+

{

`

``

32

`+

env: { NODE_NO_READLINE: '0' },

`

``

33

`+

expected: { terminal: true, useColors: true }

`

``

34

`+

}];

`

``

35

+

``

36

`+

function run(test) {

`

``

37

`+

const env = test.env;

`

``

38

`+

const expected = test.expected;

`

``

39

`+

const opts = {

`

``

40

`+

terminal: true,

`

``

41

`+

input: new stream.Readable({ read() {} }),

`

``

42

`+

output: new stream.Writable({ write() {} })

`

``

43

`+

};

`

``

44

+

``

45

`+

REPL.createInternalRepl(env, opts, function(err, repl) {

`

``

46

`+

if (err) throw err;

`

``

47

`+

assert.equal(expected.terminal, repl.terminal,

`

``

48

`+

'Expected ' + inspect(expected) + ' with ' + inspect(env));

`

``

49

`+

assert.equal(expected.useColors, repl.useColors,

`

``

50

`+

'Expected ' + inspect(expected) + ' with ' + inspect(env));

`

``

51

`+

repl.close();

`

``

52

`+

});

`

``

53

`+

}

`

``

54

+

``

55

`+

tests.forEach(run);

`