Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorFeross Aboukhadijeh <feross@feross.org>2016-01-10 19:06:55 +0300
committerFeross Aboukhadijeh <feross@feross.org>2016-01-11 02:08:59 +0300
commit37ecd873cb15ad33bd1897485ddc471ca42684a6 (patch)
tree00d435ec55bcf430dc7b68c60e812188891b8629 /bin
parentab2e4583734835499caeb75c787d0d1a9310a511 (diff)
cmd: better UI at smaller terminal widths
Diffstat (limited to 'bin')
-rwxr-xr-xbin/cmd.js79
1 files changed, 34 insertions, 45 deletions
diff --git a/bin/cmd.js b/bin/cmd.js
index aae3402..457249a 100755
--- a/bin/cmd.js
+++ b/bin/cmd.js
@@ -323,7 +323,6 @@ function runDownload (torrentId) {
}
server.listen(argv.port, initServer)
-
.on('error', function (err) {
// In case the port is unusable
if (err.code === 'EADDRINUSE' || err.code === 'EACCES') {
@@ -512,51 +511,40 @@ function drawTorrent (torrent) {
clivas.clear()
- clivas.line(
+ line(
'{green:' + (seeding ? 'Seeding' : 'Downloading') + ': }' +
'{bold:' + torrent.name + '}'
)
var seeding = torrent.done
- if (seeding) {
- clivas.line('{green:Info hash: }' + torrent.infoHash)
- linesRemaining -= 1
- }
+ if (seeding) line('{green:Info hash: }' + torrent.infoHash)
if (playerName) {
- clivas.line(
+ line(
'{green:Streaming to: }{bold:' + playerName + '} ' +
'{green:Server running at: }{bold:' + href + '}'
)
- linesRemaining -= 1
- }
- if (!playerName && server) {
- clivas.line('{green:Server running at: }{bold:' + href + '}')
- linesRemaining -= 1
- }
- if (argv.out) {
- clivas.line('{green:Downloading to: }{bold:' + argv.out + '}')
- linesRemaining -= 1
+ } else if (server) {
+ line('{green:Server running at: }{bold:' + href + '}')
}
- clivas.line(
+ if (argv.out) line('{green:Downloading to: }{bold:' + argv.out + '}')
+ line(
'{green:Speed: }{bold:' + prettyBytes(speed) + '/s} ' +
'{green:Downloaded:} {bold:' + prettyBytes(torrent.downloaded) + '}' +
'/{bold:' + prettyBytes(torrent.length) + '} ' +
'{green:Uploaded:} {bold:' + prettyBytes(torrent.uploaded) + '}'
)
- clivas.line(
+ line(
'{green:Running time:} {bold:' + getRuntime() + 's} ' +
'{green:Time remaining:} {bold:' + estimate + '} ' +
'{green:Peers:} {bold:' + unchoked.length + '/' + torrent.swarm.wires.length + '}'
)
if (argv.verbose) {
- clivas.line(
+ line(
'{green:Queued peers:} {bold:' + torrent.swarm.numQueued + '} ' +
'{green:Blocked peers:} {bold:' + torrent.numBlockedPeers + '} ' +
'{green:Hotswaps:} {bold:' + hotswaps + '}'
)
- linesRemaining -= 1
}
- clivas.line('{80:}')
- linesRemaining -= 5
+ line('')
torrent.swarm.wires.every(function (wire) {
var progress = '?'
@@ -571,41 +559,42 @@ function drawTorrent (torrent) {
progress = bits === piececount ? 'S' : Math.floor(100 * bits / piececount) + '%'
}
- var tags = []
- var reqStats = []
-
- if (argv.verbose) {
- if (wire.requests.length > 0) tags.push(wire.requests.length + ' reqs')
- if (wire.peerChoking) tags.push('choked')
- reqStats = wire.requests.map(function (req) { return req.piece })
- }
-
- clivas.line(
- '{3:%s} {25+magenta:%s} {10:%s} {12+cyan:%s/s} {12+red:%s/s} {15+grey:%s}' +
- '{10+grey:%s}',
+ var str = '{3:%s} {25+magenta:%s} {10:%s} {12+cyan:%s/s} {12+red:%s/s}'
+ var args = [
progress,
wire.remoteAddress
? (wire.remoteAddress + ':' + wire.remotePort)
: 'Unknown',
prettyBytes(wire.downloaded),
prettyBytes(wire.downloadSpeed()),
- prettyBytes(wire.uploadSpeed()),
- tags.join(', '),
- reqStats.join(' ')
- )
- peerslisted++
- return linesRemaining - peerslisted > 4
+ prettyBytes(wire.uploadSpeed())
+ ]
+ if (argv.verbose) {
+ str += ' {15+grey:%s} {10+grey:%s}'
+ var tags = []
+ if (wire.requests.length > 0) tags.push(wire.requests.length + ' reqs')
+ if (wire.peerChoking) tags.push('choked')
+ var reqStats = wire.requests.map(function (req) { return req.piece })
+ args.push(tags.join(', '), reqStats.join(' '))
+ }
+ line.apply(undefined, [].concat(str, args))
+
+ peerslisted += 1
+ return linesRemaining > 4
})
- linesRemaining -= peerslisted
if (torrent.swarm.wires.length > peerslisted) {
- clivas.line('{80:}')
- clivas.line('... and %s more', torrent.swarm.wires.length - peerslisted)
+ line('{60:}')
+ line('... and %s more', torrent.swarm.wires.length - peerslisted)
}
- clivas.line('{80:}')
+ line('{60:}')
clivas.flush(true)
}
+
+ function line () {
+ clivas.line.apply(clivas, arguments)
+ }
}
function torrentDone () {
@@ -629,7 +618,7 @@ function gracefulExit () {
process.removeListener('SIGTERM', gracefulExit)
clearInterval(drawInterval)
- clivas.line('\n{green:webtorrent is gracefully exiting...}')
+ clivas.line('\n{green:webtorrent is exiting...}')
if (!client) return