From 786a2816ddc95aa372f15e927a49dbb605951078 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Ronvel?= Date: Mon, 24 May 2021 09:37:58 +0200 Subject: [PATCH] New: use require('terminal-kit/lib/termkit-no-lazy-require.js') if lazy loading is troublesome (#176) --- CHANGELOG | 6 ++ lib/termkit-no-lazy-require.js | 139 +++++++++++++++++++++++++++++++++ package.json | 2 +- sample/image-viewer.js | 7 +- 4 files changed, 150 insertions(+), 4 deletions(-) create mode 100644 lib/termkit-no-lazy-require.js diff --git a/CHANGELOG b/CHANGELOG index 90a272c0..f04a9fca 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,10 @@ +v2.1.3 +------ + +New: use require('terminal-kit/lib/termkit-no-lazy-require.js') if lazy loading is troublesome (#176) + + v2.1.2 ------ diff --git a/lib/termkit-no-lazy-require.js b/lib/termkit-no-lazy-require.js new file mode 100644 index 00000000..7672af94 --- /dev/null +++ b/lib/termkit-no-lazy-require.js @@ -0,0 +1,139 @@ +/* + Terminal Kit + + Copyright (c) 2009 - 2021 Cédric Ronvel + + The MIT License (MIT) + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +"use strict" ; + + + +const termkit = {} ; +module.exports = termkit ; + +const lazy = require( 'lazyness' )( require ) ; + + + +// Global config +termkit.globalConfig = {} ; + + + +termkit.tty = require( './tty.js' ) ; + +// For some reason, starting from node v4, once process.stdin getter is triggered, the 'tty' command would not work properly. +// This 'hack' cache the result of the command 'tty' if we are in the linux console, so 'gpm' can work. +if ( process.env.TERM === 'linux' ) { termkit.tty.getPath() ; } + + + +// Core submodules +Object.assign( termkit , require( './misc.js' ) ) ; +Object.assign( termkit , require( './detectTerminal.js' ) ) ; + +termkit.Terminal = require( './Terminal.js' ) ; +termkit.createTerminal = termkit.Terminal.create ; + +// Windows patches +if ( process.platform === 'win32' ) { require( './windows.js' )( termkit ) ; } + + + +// Lazy submodules +termkit.image = require( './image.js' ) ; +termkit.Palette = require( './Palette.js' ) ; +termkit.Rect = require( './Rect.js' ) ; +termkit.ScreenBuffer = require( './ScreenBuffer.js' ) ; +termkit.ScreenBufferHD = require( './ScreenBufferHD.js' ) ; +termkit.TextBuffer = require( './TextBuffer.js' ) ; +termkit.Vte = require( './vte/Vte.js' ) ; +termkit.autoComplete = require( './autoComplete.js' ) ; +termkit.spChars = require( './spChars.js' ) ; + +// Document model +termkit.Element = require( './document/Element.js' ) ; +termkit.Document = require( './document/Document.js' ) ; +termkit.Container = require( './document/Container.js' ) ; +termkit.Text = require( './document/Text.js' ) ; +termkit.AnimatedText = require( './document/AnimatedText.js' ) ; +termkit.Button = require( './document/Button.js' ) ; +termkit.ToggleButton = require( './document/ToggleButton.js' ) ; +termkit.TextBox = require( './document/TextBox.js' ) ; +termkit.EditableTextBox = require( './document/EditableTextBox.js' ) ; +termkit.Slider = require( './document/Slider.js' ) ; +termkit.Bar = require( './document/Bar.js' ) ; +termkit.LabeledInput = require( './document/LabeledInput.js' ) ; +termkit.InlineInput = require( './document/InlineInput.js' ) ; +termkit.Form = require( './document/Form.js' ) ; +termkit.RowMenu = require( './document/RowMenu.js' ) ; +termkit.ColumnMenu = require( './document/ColumnMenu.js' ) ; +termkit.ColumnMenuMulti = require( './document/ColumnMenuMulti.js' ) ; +termkit.SelectList = require( './document/SelectList.js' ) ; +termkit.SelectListMulti = require( './document/SelectListMulti.js' ) ; +termkit.DropDownMenu = require( './document/DropDownMenu.js' ) ; +termkit.TextTable = require( './document/TextTable.js' ) ; +termkit.Layout = require( './document/Layout.js' ) ; +termkit.Window = require( './document/Window.js' ) ; + +// External modules +termkit.chroma = require( 'chroma-js' ) ; + + + +lazy.properties( termkit , { + terminal: () => { + var guessed = termkit.guessTerminal() ; + return termkit.createTerminal( { + stdin: process.stdin , + stdout: process.stdout , + stderr: process.stderr , + generic: guessed.generic || 'unknown' , + appId: guessed.safe ? guessed.appId : undefined , + // appName: guessed.safe ? guessed.appName : undefined , + isTTY: guessed.isTTY , + isSSH: guessed.isSSH , + processSigwinch: true , + preferProcessSigwinch: !! termkit.globalConfig.preferProcessSigwinch + } ) ; + } , + realTerminal: () => { + var guessed = termkit.guessTerminal( true ) ; + var input = termkit.tty.getInput() ; + var output = termkit.tty.getOutput() ; + + return termkit.createTerminal( { + stdin: input , + stdout: output , + stderr: process.stderr , + generic: guessed.generic || 'unknown' , + appId: guessed.safe ? guessed.appId : undefined , + // appName: guessed.safe ? guessed.appName : undefined , + isTTY: true , + isSSH: guessed.isSSH , + processSigwinch: true , + preferProcessSigwinch: !! termkit.globalConfig.preferProcessSigwinch + } ) ; + } +} , true ) ; + diff --git a/package.json b/package.json index c1ccb71a..04a0aec1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "terminal-kit", - "version": "2.1.2", + "version": "2.1.3", "description": "256 colors, keys and mouse, input field, progress bars, screen buffer (including 32-bit composition and image loading), text buffer, and many more... Whether you just need colors and styles, build a simple interactive command line tool or a complexe terminal app: this is the absolute terminal lib for Node.js!", "main": "lib/termkit.js", "directories": { diff --git a/sample/image-viewer.js b/sample/image-viewer.js index 7e3346e0..1048a8bf 100755 --- a/sample/image-viewer.js +++ b/sample/image-viewer.js @@ -29,9 +29,10 @@ -var termkit = require( 'terminal-kit' ) ; -var term = termkit.terminal ; -var path = require( 'path' ) ; +const termkit = require( '..' ) ; +//const termkit = require( '../lib/termkit-no-lazy-require.js' ) ; +const term = termkit.terminal ; +const path = require( 'path' ) ;