UNPKG

4.03 kBJavaScriptView Raw
1#!/usr/bin/env node
2/*
3 Terminal Kit
4
5 Copyright (c) 2009 - 2020 Cédric Ronvel
6
7 The MIT License (MIT)
8
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15
16 The above copyright notice and this permission notice shall be included in all
17 copies or substantial portions of the Software.
18
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 SOFTWARE.
26*/
27
28"use strict" ;
29
30
31
32/* jshint unused:false */
33
34
35
36var terminal = require( '../lib/termkit.js' ) ;
37
38
39
40terminal.getDetectedTerminal( function( error , term ) {
41
42 var i ;
43
44 //term = terminal.terminal ;
45
46 // First set black as the background color?
47 //term.bgBlack() ;
48 term( 'This is the style test, each word should be styled accordingly with what it says it is.\n\n' ) ;
49
50
51
52 // Test foreground colors
53
54 term.bold( '=== Foreground colors ===\n\n' ) ;
55
56 term.white( 'white ' ).brightWhite( 'brightWhite' )( '\n' ) ;
57 term.black( 'black ' ).brightBlack( 'brightBlack' )( '\n' ) ;
58 term.red( 'red ' ).brightRed( 'brightRed' )( '\n' ) ;
59 term.yellow( 'yellow ' ).brightYellow( 'brightYellow' )( '\n' ) ;
60 term.green( 'green ' ).brightGreen( 'brightGreen' )( '\n' ) ;
61 term.cyan( 'cyan ' ).brightCyan( 'brightCyan' )( '\n' ) ;
62 term.blue( 'blue ' ).brightBlue( 'brightBlue' )( '\n' ) ;
63 term.magenta( 'magenta ' ).brightMagenta( 'brightMagenta' )( '\n' ) ;
64
65 // Check the color() function
66 for ( i = 0 ; i < 16 ; i ++ ) { term.color( i , '*' ) ; }
67 term( '\n' ) ;
68
69
70
71 // Test background colors
72
73 term.bold( '\n=== Background colors ===\n\n' ) ;
74
75 term.bgWhite( 'bgWhite ' ).bgBrightWhite( 'bgBrightWhite' )( '\n' ) ;
76 term.bgBlack( 'bgBlack ' ).bgBrightBlack( 'bgBrightBlack' )( '\n' ) ;
77 term.bgRed( 'bgRed ' ).bgBrightRed( 'bgBrightRed' )( '\n' ) ;
78 term.bgYellow( 'bgYellow ' ).bgBrightYellow( 'bgBrightYellow' )( '\n' ) ;
79 term.bgGreen( 'bgGreen ' ).bgBrightGreen( 'bgBrightGreen' )( '\n' ) ;
80 term.bgCyan( 'bgCyan ' ).bgBrightCyan( 'bgBrightCyan' )( '\n' ) ;
81 term.bgBlue( 'bgBlue ' ).bgBrightBlue( 'bgBrightBlue' )( '\n' ) ;
82 term.bgMagenta( 'bgMagenta ' ).bgBrightMagenta( 'bgBrightMagenta' )( '\n' ) ;
83
84 // Check the bgColor() function
85 for ( i = 0 ; i < 16 ; i ++ ) { term.bgColor( i , ' ' ) ; }
86 term( '\n' ) ;
87
88
89
90 // Test styles
91
92 term.bold( '\n=== Styles ===\n\n' ) ;
93
94 term.bold( 'bold' )( '\n' ) ;
95 term.dim( 'dim' )( '\n' ) ;
96 term.italic( 'italic' )( '\n' ) ;
97 term.underline( 'underline' )( '\n' ) ;
98 term.blink( 'blink' )( '\n' ) ;
99 term.inverse( 'inverse' )( '\n' ) ;
100 term.hidden( 'hidden' )( ' <-- hidden\n' ) ;
101 term.strike( 'strike' )( '\n' ) ;
102
103
104
105 // Test mixed styles
106
107 term.bold( '\n=== Mixed styles ===\n\n' ) ;
108
109 term.bold.red( 'bold-red' )( '\n' ) ;
110 term.dim.red( 'dim-red' )( '\n' ) ;
111 term.bold.dim.red( 'bold-dim-red' )( '\n' ) ;
112 term.cyan.bgRed( 'cyan-on-red' )( '\n' ) ;
113 term.bold.cyan.bgRed( 'bold-cyan-on-red' )( '\n' ) ;
114 term.bold.italic.underline( 'bold-italic-underline' )( '\n' ) ;
115
116
117
118 // Test object2attr
119
120 var attr ;
121 attr = term.object2attr( { color: 'blue' , bgColor: 'red' , underline: true , italic: true } ) ;
122 term( attr ) ;
123 term( '\nAttr test' ) ;
124 attr = term.object2attr( { color: 'blue' } ) ;
125 term( attr ) ;
126 term( '\nAttr test2' ) ;
127
128 // Reset before exiting...
129
130 term( '\n' ) ;
131 term.styleReset() ;
132 term( 'Reset...\n' ) ;
133
134} ) ;
135