scripts: refactor output formatting functions