Specifying preservation of ANSI codes in rclone output

What is the problem you are having with rclone?

Essentially, it's not a rclone problem, it's rather specific rclone use-case problem. I need to modify rclone output a bit. So, in this case I have to redirect output -> modify -> return back. But during pipelining rclone detects it outputs not in a terminal and doesn't put ANSI codes in its output. After some investigation I came up with these options:

  1. Check rclone flags in order to find something like --color=always. It's a common flag to preserve ANSI in a program output. Did not find. (have I mistaken ?)
  2. Put line breaks and indents on my own. - works in almost 75% cases. But very unreliable and fragile way.
  3. Trick rclone to think it executes in TTY. - with default script or external unbuffer utilities it was quite easy, but it doesn't work with plain console (/dev/console). Very strange, but during execution under script utility using /dev/console it produces ONLY ANSI codes :upside_down_face: But again It works great in TTY and PTY.
  4. Request for help here \ Feature request to add the flag. Maybe I have other solutions to the problem that I missed ?

What is your rclone version (output from rclone version) && OS

rclone v1.51.0

  • os/arch: linux/amd64
  • go version: go1.13.7

Which cloud storage system are you using? (eg Google Drive)

MEGA

The command you were trying to run (eg rclone copy /tmp remote:tmp)

rclone sync FROM TO --progress

You could get rclone to output a more computer friendly log with --json-log that has the stats values it so will have everything in easy to parse format.

Yes, I've been considering this option too

  1. It's actually --use-json-log and it's rather about logging than output. It prints stats block only at the end of execution. So, with --progress option it does not bring much of help.
  2. Another important detail is approach. Trying to make a log look like an output - is not that good idea, it will complicate things a lot. Especially when the initial task was to achieve the ability to pipeline formatted rclone output.
  3. And again, for the sake of simplicity. I'm just talking about classic bash-script use-case: pipeline output -> prepend/append/modify with regex (process somehow) -> pass on.
  4. Ok, I don't know "Go" at all and rclone structure in particular. But I suppose It should be not a big deal to add this simple flag. After all, it could be very useful in shell-oriented scripting where I think rclone is used very often :grin:

Oh, sorry for the bloated wording I'm just trying to be clear.

Change the timing of the stats blocks with --stats 1s. Then you'll essentially have the same output as progress.

If the flag is what you need then that is understood! I thought about adding it when I did the original feature but I couldn't work out what to call it or whether there was a standard for it!

If you want to have a go at adding it, then start here...

That library probably needs a global config flag which is set by rclone's command parser.

Thank you for pointing out on this file! I have just replaced this:

	once.Do(func() {
		f := os.Stdout
		if !terminal.IsTerminal(int(f.Fd())) {
			// If stdout not a tty then remove escape codes
			Out = colorable.NewNonColorable(f)
		} else if runtime.GOOS == "windows" && os.Getenv("TERM") != "" {
			// If TERM is set just use stdout
			Out = f
		} else {
			Out = colorable.NewColorable(f)
		}
	})

with this:

	once.Do(func() {
	f := os.Stdout
	Out = colorable.NewColorable(f)
})

Rebuilt it and got all I wanted :grinning: Very lucky that It was as simple as go build. (hello java maven!)

Sad but true.

I would love to do it, but the truth is that I even read Go sources with difficulty. I'm not the one who will contribute to rclone, even such simple things like this. Well, anyway, I've tried to introduce UseAnsiCodes represented by AnsiCodesMode [AUTO (DEFAULT), ALWAYS, NEVER] but it didn't make out anyhow. So, just replaced that lines and called it my best.

Thank you!

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.