Skip to content

Commit

Permalink
improve ability to be bundled
Browse files Browse the repository at this point in the history
  • Loading branch information
erossignon committed Sep 23, 2024
1 parent 9278d66 commit 12a5681
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
8 changes: 4 additions & 4 deletions browser/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright (c) 2013-2015, Christopher Jeffrey and contributors (MIT License).
* https://github.com/chjj/blessed
*/

var path = require('path');
var Transform = require('stream').Transform
, path = require('path')
, fs = require('fs');
Expand Down Expand Up @@ -43,8 +43,8 @@ var requireWidgets = widgets.reduce(function(out, name) {
* terminfo or termcap, just use xterm terminfo/cap.
*/

var infoPath = path.resolve(__dirname, '..', 'usr', 'xterm-256color')
, capPath = path.resolve(__dirname, '..', 'usr', 'xterm.termcap');
var infoPath = path.resolve(path.join(__dirname, '../usr/xterm-256color'))
, capPath = path.resolve(path.join(__dirname, '../usr/xterm.termcap'));

var infoPathFake = path.resolve(
path.sep, 'usr', 'share', 'terminfo',
Expand All @@ -53,7 +53,7 @@ var infoPathFake = path.resolve(
);

function readMethods() {
Tput._infoBuffer = new Buffer(TERMINFO, 'base64');
Tput._infoBuffer = Buffer.from(TERMINFO, 'base64');

Tput.prototype.readTerminfo = function() {
this.terminal = TERMINFO_NAME;
Expand Down
20 changes: 16 additions & 4 deletions lib/tput.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ Tput.prototype._debug = function() {
return console.log.apply(console, arguments);
};


function findFindInUser(name) {
const f2 = path.join(__dirname, "usr", name);
if (fs.existsSync(f2)) {
return f2;
}
const f1 = path.join(__dirname, '../usr', name);
if (fs.existsSync(f1)) {
return f1;
}
throw new Error('Terminfo not found. : ' + name);
}
/**
* Fallback
*/
Expand All @@ -111,21 +123,21 @@ Tput.prototype._useVt102Cap = function() {
};

Tput.prototype._useXtermCap = function() {
return this.injectTermcap(path.join(__dirname,'../usr/xterm.termcap'));
return this.injectTermcap(findFindInUser('xterm.termcap'));
};

Tput.prototype._useXtermInfo = function() {
return this.injectTerminfo(path.join(__dirname, '/../usr/xterm.bin'));
return this.injectTerminfo(findFindInUser("xterm"));
};

Tput.prototype._useInternalInfo = function(name) {
name = path.basename(name);
return this.injectTerminfo(path.join(__dirname, '/../usr/' + name));
return this.injectTerminfo(findFindInUser(name));
};

Tput.prototype._useInternalCap = function(name) {
name = path.basename(name);
return this.injectTermcap(__dirname + '/../usr/' + name + '.termcap');
return this.injectTermcap(findFindInUser(name + '.termcap'));
};

/**
Expand Down
File renamed without changes.

0 comments on commit 12a5681

Please sign in to comment.