UNPKG

3.41 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/* global describe, it, before, after */
34
35
36const termkit = require( '../lib/termkit.js' ) ;
37const term = termkit.terminal ;
38
39
40
41async function termInfo( t ) {
42 var r ;
43
44 term( 'Terminal name: %s\n' , t.appName ) ;
45 term( 'Terminal app ID: %s\n' , t.appId ) ;
46 term( 'Generic terminal: %s\n' , t.generic ) ;
47 term( 'Config file: %s\n' , t.termconfigFile ) ;
48 term( '\n' ) ;
49
50 term( "Support for delta escape sequence: " + ( t.support.deltaEscapeSequence ? "^GOK^:\n" : "^RNO^:\n" ) ) ;
51 term( "Support for 256 colors: " + ( t.support['256colors'] ? "^GOK^:\n" : "^RNO^:\n" ) ) ;
52 term( "Support for true colors: " + ( t.support.trueColor ? "^GOK^:\n" : "^RNO^:\n" ) ) ;
53
54 try {
55 term( "Support for cursor location request: " ) ;
56 r = await t.getCursorLocation() ;
57 term( "^GOK^ ^K(%N)^:\n" , r ) ;
58 }
59 catch ( error ) {
60 term( "^RFAILED^ (%s)^:\n" , error ) ;
61 }
62
63 try {
64 term( "Support for palette request: " ) ;
65 await t.getPalette() ;
66 term( "^GOK^:\n" ) ;
67 }
68 catch ( error ) {
69 term( "^RFAILED^ (%s)^:\n" , error ) ;
70 }
71
72 term( "Issue #116 CURSOR_LOCATION keymap: " + ( t.keymap.CURSOR_LOCATION && typeof t.keymap.CURSOR_LOCATION === 'object' ? "^GOK^:\n" : "^RNO^:\n" ) ) ;
73 term( "Issue #116 cursorLocation handler: " + ( typeof t.handler.cursorLocation === 'function' ? "^GOK^:\n" : "^RNO^:\n" ) ) ;
74
75 term( '\n' ) ;
76}
77
78
79
80async function detect() {
81 var info , newTerm ;
82
83 term.green( '\n== Environment variable ==\n\n' ) ;
84 term( '$TERM: %s\n' , process.env.TERM ) ;
85 term( '$COLORTERM: %s\n' , process.env.COLORTERM ) ;
86 term( '$VTE_VERSION: %s\n' , process.env.VTE_VERSION ) ;
87 term( '\n' ) ;
88
89
90
91 term.green( '\n== Using simple terminal guessing ==\n\n' ) ;
92 term( '.guessTerminal(): %J\n' , termkit.guessTerminal() ) ;
93 await termInfo( term ) ;
94
95
96
97 term.green( '\n== Using advanced terminal detection ==\n\n' ) ;
98 try {
99 info = await termkit.getParentTerminalInfo( info ) ;
100 term( '.getParentTerminalInfo(): %J\n' , info ) ;
101 }
102 catch ( error ) {
103 term.red( "Can't get parent terminal info: %E" , error ) ;
104 }
105
106 try {
107 newTerm = await termkit.getDetectedTerminal() ;
108 await termInfo( newTerm ) ;
109 }
110 catch ( error ) {
111 term.red( "Can't get detect real terminal: %E" , error ) ;
112 }
113}
114
115detect() ;
116