dat icon indicating copy to clipboard operation
dat copied to clipboard

dat CLI outputs color codes even when output is piped

Open bnewbold opened this issue 7 years ago • 2 comments

I am reporting a bug or unexpected behavior

Bug Report

bnewbold@wbgrp-svc206$ cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.4 LTS"
bnewbold@wbgrp-svc206$ nodejs --version
v8.11.3
bnewbold@wbgrp-svc206$ dat --version
13.11.0

Expected behavior

Most UNIX CLI programs which use color output can detect when stdout isn't going to a terminal, and will not include color codes.

Actual behavior

The dat command seems to always output color codes, even when output is being piped into another process.

bnewbold@wbgrp-svc206$ dat status | xxd
00000000: 1b5b 3f32 356c 6461 743a 2f2f 3166 6137  .[?25ldat://1fa7
00000010: 3632 6637 6165 3062 6538 6337 3332 3066  62f7ae0be8c7320f
00000020: 6134 3137 3433 6139 6464 6631 6338 6533  a41743a9ddf1c8e3
00000030: 3166 6131 3334 3537 3939 3137 3436 3062  1fa134579917460b
00000040: 3633 3161 6636 3263 3331 3163 0a38 2066  631af62c311c.8 f
00000050: 696c 6573 2028 3433 204d 4229 0a56 6572  iles (43 MB).Ver
00000060: 7369 6f6e 3a20 3137 1b5b 3f32 3568       sion: 17.[?25h

Here, the color code is being printed as [?25l.

bnewbold avatar Jul 16 '18 05:07 bnewbold

We might also want to support the emerging NO_COLOR standard.

millette avatar Aug 23 '18 22:08 millette

The current behaviour makes it impossible to determine the state when dat is run from systemd.

Sep 25 08:29:07 macchina dat[24052]: [2.0K blob data]
Sep 25 08:29:11 macchina dat[24052]: [366B blob data]
Sep 25 11:18:14 macchina dat[24052]: [70B blob data]
Sep 25 11:18:16 macchina dat[24052]: [77B blob data]
Sep 25 11:18:17 macchina dat[24052]: [62B blob data]
Sep 25 11:18:17 macchina dat[24052]: [74B blob data]
Sep 25 11:18:33 macchina dat[24052]: [1.4K blob data]
Sep 25 13:02:35 macchina dat[24052]: [61B blob data]

For this use case, maybe we could have a one-line summary of the current state (e.g.: number of connections, sync progress) that is updated every 5(?) seconds, as long as there are changes, and less frequently (once an hour?) if there are no changes.

Or should I be using hypercored instead if I need to run it as a service?

apexo avatar Sep 25 '18 11:09 apexo