4 ms·
You can do better -- fmt provides a way to give a dynamic width or precision as an int argument. fmt.Fprintf(os.Stderr, "%*s %s\r", paddingWidth, "", legend)
by cespare 11y ago
You can do better -- fmt provides a way to give a dynamic width or precision as an int argument.
fmt.Fprintf(os.Stderr, "%*s %s\r", paddingWidth, "", legend)
I'd further wonder whether a separate padding calculation is needed at all (too lazy to go read the source on Github at the moment).
- pbnjay 11y agoI started with that, but there's no reason to use the formatting specifiers when the padding string is already blank. With the dynamic width Fprintf still needs to waste time parsing the format string.