<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 RichStr consist of pieces of strings and RichStrs
Step1:  __repr__esentation of a rich string shows a "flat" representation of a RichStr - a sequence of styles and strings where style applies to everything after it. This is how terminal works. This representation is useful for debugging.
Step2:  To apply a style or a stylesheet you use sheet named argument of RichStr
Step3:  You can also use dot notation
Step4:  __str__ is overloaded, so you can print. Note that the red is not pure red, it is because here it is indexed, indexed colors depend on terminal palete
Step5:  There is a quick and dirty conversion to HTML, but don't use it, it is too unfinished dirty. There are some methods to get CSS rules for some styles.
Step6:  you can create stylesheets from styles
Step7:  with RichStr.optimizedCodeRepr you can get optimized code sequence in a machine-readable form
<ASSISTANT_TASK:>
Python Code:
n=RichStr("I am ", "normal")
Explanation: RichStr consist of pieces of strings and RichStrs
End of explanation
n
Explanation: __repr__esentation of a rich string shows a "flat" representation of a RichStr - a sequence of styles and strings where style applies to everything after it. This is how terminal works. This representation is useful for debugging.
End of explanation
r=RichStr("RED", sheet=groups["Fore"]["red"])
Explanation: To apply a style or a stylesheet you use sheet named argument of RichStr
End of explanation
r=RichStr("RED", sheet=groups.Fore.red)
str(r)
Explanation: You can also use dot notation
End of explanation
print(r)
Explanation: __str__ is overloaded, so you can print. Note that the red is not pure red, it is because here it is indexed, indexed colors depend on terminal palete
End of explanation
print(r.toHTML())
IPython.display.display_html(r.toHTML(), raw=True)
pureRed=RGBColor("PureRed", 0xFF, bg=True)
prs=RichStr("Pure red", sheet=pureRed)
print(repr(str(prs)))
print(prs)
Explanation: There is a quick and dirty conversion to HTML, but don't use it, it is too unfinished dirty. There are some methods to get CSS rules for some styles.
End of explanation
lightGoldenrod1=RGBColor("lightGoldenrod1", 0xff, 0xff, 0x5f, True)
blackOnGold=Sheet({
	"Back":lightGoldenrod1, # requires 3rd-party libraries
	"Fore":groups.Fore.black
})
g=RichStr(r, " on GOLD", sheet=blackOnGold)
str(g)
print(g)
print(g.toHTML())
IPython.display.display_html(g.toHTML(), raw=True)
g.sheetRepr()
Explanation: you can create stylesheets from styles
End of explanation
g.optimizedCodeRepr()
Explanation: with RichStr.optimizedCodeRepr you can get optimized code sequence in a machine-readable form
End of explanation
<END_TASK>