@Phlurim if really needed and important, you could use this little function I had written for somebody else who wanted colored printing in the console.
I just have modified it to support colored and bold in the console.
from objc_util import *
import ui
UIColor = ObjCClass('UIColor')
NSMutableAttributedString = ObjCClass('NSMutableAttributedString')
UIFont = ObjCClass('UIFont')
@on_main_thread
def colored_bold(txt):
from objc_util import ObjCClass
win = ObjCClass('UIApplication').sharedApplication().keyWindow()
main_view = win.rootViewController().view()
ret = ''
font = UIFont.fontWithName_size_('Menlo', 15)
traits = 0 | 1 << 1
font_bold = UIFont.fontWithName_size_traits_('Menlo', 15,traits)
def analyze(v):
for tv in v.subviews():
if 'OMTextView' in str(tv._get_objc_classname()):
su = tv.superview()
if 'OMTextEditorView' in str(su._get_objc_classname()):
continue
# tv = console is a OMTextView baseClass = UIScrollView
#print(dir(tv))
if isinstance(txt,list):
txt_list = txt
else:
txt_list = [txt]
for ele in txt_list:
bold = False
if isinstance(ele,tuple):
t = ele[0]
c = ele[1]
if 'bold' in ele:
bold = True
else:
t = ele
c = 'black'
color = UIColor.colorWithRed_green_blue_alpha_(*ui.parse_color(c))
attr_str = NSMutableAttributedString.alloc().initWithString_(t)
if bold:
attributes = {ns('NSColor'):color, ns('NSFont'):font_bold}
else:
attributes = {ns('NSColor'):color, ns('NSFont'):font}
attr_str.setAttributes_range_(attributes, NSRange(0, len(t)))
tv.appendAttributedText_(attr_str)
ret = analyze(tv)
if ret:
return ret
ret = analyze(main_view)
if __name__ == '__main__':
colored_bold([('red text', 'red'), ' normal ', ('blue text', 'blue','bold')])
print()
