tart icon indicating copy to clipboard operation
tart copied to clipboard

Warn/Success/Info/Error functions

Open tomjn opened this issue 3 years ago • 5 comments
trafficstars

Currently Tart uses print to output its messages, but if there were dedicated wrapper functions then it could standardise error/warning outputs and colour code them

Noting this as a nice to have.

It can be done manually via escape codes in print according to this Stack Overflow answer https://stackoverflow.com/a/27808423/57482

I also expect there's an equivalent to the Chalk JS library written in Swift, I couldn't see one with a quick search that wasn't a full CLI framework though

This likely means a future ticket for a --no-color or --no-colors option

tomjn avatar Nov 10 '22 11:11 tomjn

Spoke too soon, here's examples with named colours using a swift package named chalk:

https://iosexample.com/terminal-colors-using-swift-5s-string-interpolation-extensions/

$ swift sh <<EOF
import Foundation
import Chalk  // @mxcl ~> 0.3

for x in 0..<256 {
    let cell = " \(x)".padding(toLength: 5, withPad: " ", startingAt: 0)
    let terminator = (x + 3).isMultiple(of: 6) ? "\n" : ""
    print("\(cell, color: .extended(15), background: .extended(UInt8(x)))", terminator: terminator)
}
EOF

https://github.com/mxcl/Chalk it looks pretty small as far as libraries go so perhaps it's overkill

tomjn avatar Nov 10 '22 11:11 tomjn

What problem the colors are going to solve?

Colors normally allow you to discern different bits of information quickly, but Tart's output is not that complicated at this moment.

edigaryev avatar Nov 10 '22 15:11 edigaryev

Standardisation or error/warning messages, and beauty, this is a nice to have

tomjn avatar Nov 10 '22 15:11 tomjn

Standardisation or error/warning messages

Do you have log-like output like WARNING: failed to do something in mind?

and beauty, this is a nice to have

Beauty is a pretty subjective thing 😅 There's beauty in simplicity, sometimes to the point of not emitting any output at all, see Unix philosophy.

edigaryev avatar Nov 10 '22 15:11 edigaryev

True but Tart already flounces most of that philosophy by having subcommands and asking for user input. Colour and consistent presentation is a UI/UX feature with usability and accessibility consequences. Otherwise we'd need separate binaries for every subcommand with flags for every possible input/confirmation

tomjn avatar Nov 10 '22 16:11 tomjn

I don't think it's worth adding ASCII output for color. Tart doesn't output that much information. I think the current behaviour of using stdout for regular output and stderr for errors is good enough.

Since there were no other requests to improve the output I think we can close the issue until there is more demand and a cleaner visions for benefits.

fkorotkov avatar Jul 14 '23 16:07 fkorotkov