Skip to content

Commit

Permalink
New: use require('terminal-kit/lib/termkit-no-lazy-require.js') if la…
Browse files Browse the repository at this point in the history
…zy loading is troublesome (#176)
  • Loading branch information
cronvel committed May 24, 2021
1 parent fe37289 commit 786a281
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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
------

Expand Down
139 changes: 139 additions & 0 deletions lib/termkit-no-lazy-require.js
Original file line number Diff line number Diff line change
@@ -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 ) ;

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
7 changes: 4 additions & 3 deletions sample/image-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) ;



Expand Down

0 comments on commit 786a281

Please sign in to comment.