Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
row.forEach(function (col, c) {
// leave room for left and right padding.
col.width = widths[c]
if (_this.wrap) wrapped = wrap.hard(_this._negatePadding(col))(col.text).split('\n')
else wrapped = col.text.split('\n')
// add top and bottom padding.
if (col.padding) {
for (i = 0; i < (col.padding[top] || 0); i++) wrapped.unshift('')
for (i = 0; i < (col.padding[bottom] || 0); i++) wrapped.push('')
}
wrapped.forEach(function (str, r) {
if (!rrows[r]) rrows.push([])
rrow = rrows[r]
for (var i = 0; i < c; i++) {
if (rrow[i] === undefined) rrow.push('')
}
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//
var _ = require('underscore');
var fs = require('fs');
var path = require('path');
var read = require('read');
var wrap = require('wordwrap').hard(0, 75);
var util = require('util');
var Constants = require('./constants');
var userHome = require('user-home');
exports.camelcase = function (flag) {
return flag.split('-').reduce(function (str, word) {
return str + word[0].toUpperCase() + word.slice(1);
});
};
exports.ignoreCaseEquals = function (a, b) {
return a === b ||
(a !== null && a !== undefined &&
b !== null && b !== undefined &&
(a.toLowerCase() === b.toLowerCase())) === true;
};
import * as fs from 'fs'
import * as handlebars from 'handlebars'
import * as moment from 'moment'
import * as path from 'path'
import * as wordwrap from 'wordwrap'
import * as S from 'sanctuary'
const testing = process.env.NODE_ENV === 'testing'
if (testing || process.env.COLOR === 'false') {
color.disable()
}
export const colors = color
const wrap = wordwrap.hard(0, 80)
function stripHandlebarsNewLine(str) {
return str.replace(/[\s\t\r\n](\{\{[#\/])/g, '$1')
}
export function debug(...args) {
if (!process.env.GH_VERBOSE) {
return
}
if (typeof args[0] === 'string') {
args[0] = `DEBUG: ${args[0]}`
console.log(...args)
return
}
lines () {
if (!this.text) return []
return wrap.hard(0, this.charactersPerLine)(this.text).split('\n')
}
}
display.session._message = function (message) {
var text = wordwrap.hard(0, padded)(message.plain)
var address = message.senderAddr.toString()
var txId = colors.grey(message.txId)
if (message.origin === 'remote') {
address = wordwrap.hard(padded - address.length, padded)(address)
txId = colors.grey(wordwrap.hard(padded - message.txId.length, padded)(message.txId))
if (text.length < padded) {
text = wordwrap.hard(padded - text.length, padded)(text)
}
}
address = colors.red(address)
return [[address], [txId], [text]]
}
reportFormat.forEach(function (item) {
var title = item[0] + ':';
var field = item[1];
var formatter = item[2] || defaultFormat;
var value = getProperty(data, field);
if (formatter instanceof Array) {
outfn(spaces(indentation) + toWidth(title, headerWidth));
doReport(indentation + headerWidth, formatter, value, outfn);
} else {
var leftIndentation = 'verbose: '.length + indentation + headerWidth;
var formatted = wrap.hard(leftIndentation, maxWidth)(formatter(value));
formatted = spaces(indentation) + toWidth(title, headerWidth) +
formatted.slice(leftIndentation);
outfn(formatted);
}
});
}
display.session = function (session, addr) {
var table = new Table({
head: ['Chat ' + session.txId],
colWidths: [columns],
truncate: false
})
var senderAddr = session.senderAddr.toString()
var isSender = senderAddr === addr.toString()
var sender = isSender ? session.receiverAddr.toString() : senderAddr
var initAddr = session.init.senderAddr
var isInit = initAddr.toString() === addr.toString()
var theirAuth = session.getTheirAuth()
theirAuth = theirAuth ? theirAuth.txId : 'Not accepted'
theirAuth = wordwrap.hard(padded - theirAuth.length, padded)(theirAuth)
theirAuth = colors.grey(theirAuth)
var ourAuth = session.getOurAuth()
ourAuth = ourAuth ? colors.grey(ourAuth.txId) : colors.red('Accept?')
var firstAuth = isInit ? ourAuth : theirAuth
var secondAuth = isInit ? theirAuth : ourAuth
var messages = session.messages.length + ' Message'
messages += session.messages.length !== 1 ? 's' : ''
var newMessages = session.unreadMessages ? session.unreadMessages + ' New / ' : ''
var info = colors.green(newMessages) + colors.grey(messages)
var infoWidth = sender.length + messages.length + newMessages.length
var right = wordwrap.hard(padded - infoWidth, padded)
table.push([firstAuth], [secondAuth], [sender + right(info)])
process.stderr.cursorTo(0)
process.stderr.write(table.toString())
display.newLine()
}
reportFormat.forEach(function (item) {
const title = item[0] + ":";
const field = item[1];
const formatter = item[2] || defaultFormat;
const value = getProperty(data, field);
if (formatter instanceof Array) {
outfn(spaces(indentation) + toWidth(title, headerWidth));
doReport(indentation + headerWidth, formatter, value, outfn);
} else {
const leftIndentation = "verbose: ".length + indentation + headerWidth;
let formatted = wrap.hard(leftIndentation, maxWidth)(formatter(value));
formatted = spaces(indentation) + toWidth(title, headerWidth) +
formatted.slice(leftIndentation);
outfn(formatted);
}
});
}
var initAddr = session.init.senderAddr
var isInit = initAddr.toString() === addr.toString()
var theirAuth = session.getTheirAuth()
theirAuth = theirAuth ? theirAuth.txId : 'Not accepted'
theirAuth = wordwrap.hard(padded - theirAuth.length, padded)(theirAuth)
theirAuth = colors.grey(theirAuth)
var ourAuth = session.getOurAuth()
ourAuth = ourAuth ? colors.grey(ourAuth.txId) : colors.red('Accept?')
var firstAuth = isInit ? ourAuth : theirAuth
var secondAuth = isInit ? theirAuth : ourAuth
var messages = session.messages.length + ' Message'
messages += session.messages.length !== 1 ? 's' : ''
var newMessages = session.unreadMessages ? session.unreadMessages + ' New / ' : ''
var info = colors.green(newMessages) + colors.grey(messages)
var infoWidth = sender.length + messages.length + newMessages.length
var right = wordwrap.hard(padded - infoWidth, padded)
table.push([firstAuth], [secondAuth], [sender + right(info)])
process.stderr.cursorTo(0)
process.stderr.write(table.toString())
display.newLine()
}