cardiff: Code refactoring

All the printing operations are common between components, it's better
to make the code into a single function and call it several times.