<spanid="evennia-utils-ansi"></span><h1>evennia.utils.ansi<aclass="headerlink"href="#module-evennia.utils.ansi"title="Permalink to this headline">¶</a></h1>
<p>ANSI - Gives colour to text.</p>
<p>Use the codes defined in the <em>ANSIParser</em> class to apply colour to text. The
<strong>parse_ansi</strong> function in this module parses text for markup and <strong>strip_ansi</strong>
removes it.</p>
<p>You should usually not need to call <strong>parse_ansi</strong> explicitly; it is run by
Evennia just before returning data to/from the user. Alternative markup is
possible by overriding the parser class (see also contrib/ for deprecated
markup schemes).</p>
<p>Supported standards:</p>
<ulclass="simple">
<li><p>ANSI 8 bright and 8 dark fg (foreground) colors</p></li>
<li><p>ANSI 8 dark bg (background) colors</p></li>
<li><p>‘ANSI’ 8 bright bg colors ‘faked’ with xterm256 (bright bg not included in ANSI standard)</p></li>
<li><p><strong>|[R|g</strong> bg dark red, fg bright green</p></li>
</ul>
<divclass="highlight-default notranslate"><divclass="highlight"><pre><span></span><spanclass="s2">"This is |rRed text|n and this is normal again."</span>
</pre></div>
</div>
<p>Xterm256 colors are given as RGB (Red-Green-Blue), with values 0-5:</p>
<divclass="highlight-default notranslate"><divclass="highlight"><pre><span></span><spanclass="s2">"This is |500Red text|n and this is normal again."</span>
<spanclass="s2">"This is |[=jText on dark grey background"</span>
</pre></div>
</div>
<hrclass="docutils"/>
<dlclass="py class">
<dtid="evennia.utils.ansi.ANSIParser">
<emclass="property">class </em><codeclass="sig-prename descclassname">evennia.utils.ansi.</code><codeclass="sig-name descname">ANSIParser</code><aclass="reference internal"href="../_modules/evennia/utils/ansi.html#ANSIParser"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.ansi.ANSIParser"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">xterm256_fg</code><emclass="property"> = ['\\|([0-5])([0-5])([0-5])']</em><aclass="headerlink"href="#evennia.utils.ansi.ANSIParser.xterm256_fg"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">xterm256_bg</code><emclass="property"> = ['\\|\\[([0-5])([0-5])([0-5])']</em><aclass="headerlink"href="#evennia.utils.ansi.ANSIParser.xterm256_bg"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">xterm256_gfg</code><emclass="property"> = ['\\|=([a-z])']</em><aclass="headerlink"href="#evennia.utils.ansi.ANSIParser.xterm256_gfg"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">xterm256_gbg</code><emclass="property"> = ['\\|\\[=([a-z])']</em><aclass="headerlink"href="#evennia.utils.ansi.ANSIParser.xterm256_gbg"title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dlclass="py attribute">
<dtid="evennia.utils.ansi.ANSIParser.mxp_re">
<codeclass="sig-name descname">mxp_re</code><emclass="property"> = '\\|lc(.*?)\\|lt(.*?)\\|le'</em><aclass="headerlink"href="#evennia.utils.ansi.ANSIParser.mxp_re"title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dlclass="py attribute">
<dtid="evennia.utils.ansi.ANSIParser.mxp_url_re">
<codeclass="sig-name descname">mxp_url_re</code><emclass="property"> = '\\|lu(.*?)\\|lt(.*?)\\|le'</em><aclass="headerlink"href="#evennia.utils.ansi.ANSIParser.mxp_url_re"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">brightbg_sub</code><emclass="property"> = re.compile('(?<!\\|)\\|\\[r|(?<!\\|)\\|\\[g|(?<!\\|)\\|\\[y|(?<!\\|)\\|\\[b|(?<!\\|)\\|\\[m|(?<!\\|)\\|\\[c|(?<!\\|)\\|\\[w|(?<!\\|)\\|\\[x', re.DOTALL)</em><aclass="headerlink"href="#evennia.utils.ansi.ANSIParser.brightbg_sub"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">xterm256_fg_sub</code><emclass="property"> = re.compile('\\|([0-5])([0-5])([0-5])', re.DOTALL)</em><aclass="headerlink"href="#evennia.utils.ansi.ANSIParser.xterm256_fg_sub"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">xterm256_bg_sub</code><emclass="property"> = re.compile('\\|\\[([0-5])([0-5])([0-5])', re.DOTALL)</em><aclass="headerlink"href="#evennia.utils.ansi.ANSIParser.xterm256_bg_sub"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">xterm256_gfg_sub</code><emclass="property"> = re.compile('\\|=([a-z])', re.DOTALL)</em><aclass="headerlink"href="#evennia.utils.ansi.ANSIParser.xterm256_gfg_sub"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">xterm256_gbg_sub</code><emclass="property"> = re.compile('\\|\\[=([a-z])', re.DOTALL)</em><aclass="headerlink"href="#evennia.utils.ansi.ANSIParser.xterm256_gbg_sub"title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dlclass="py attribute">
<dtid="evennia.utils.ansi.ANSIParser.ansi_sub">
<codeclass="sig-name descname">ansi_sub</code><emclass="property"> = re.compile('\\|n|\\|/|\\|\\-|\\|>|\\|_|\\|\\*|\\|\\^|\\|u|\\|r|\\|g|\\|y|\\|b|\\|m|\\|c|\\|w|\\|x|\\|R|\\|G|\\|Y|\\|B|\\|M|\\|C|\\|W|\\|X|\\|h|\\|H|\\|!R|\\|!G|\\|!Y|\\|!B|\\|!M|\\|!C|\\|!W|\\|!X|\\|\\[R|\\|\\[G, re.DOTALL)</em><aclass="headerlink"href="#evennia.utils.ansi.ANSIParser.ansi_sub"title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dlclass="py attribute">
<dtid="evennia.utils.ansi.ANSIParser.mxp_sub">
<codeclass="sig-name descname">mxp_sub</code><emclass="property"> = re.compile('\\|lc(.*?)\\|lt(.*?)\\|le', re.DOTALL)</em><aclass="headerlink"href="#evennia.utils.ansi.ANSIParser.mxp_sub"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">mxp_url_sub</code><emclass="property"> = re.compile('\\|lu(.*?)\\|lt(.*?)\\|le', re.DOTALL)</em><aclass="headerlink"href="#evennia.utils.ansi.ANSIParser.mxp_url_sub"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">ansi_re</code><emclass="property"> = '\\033\\[[0-9;]+m'</em><aclass="headerlink"href="#evennia.utils.ansi.ANSIParser.ansi_re"title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dlclass="py attribute">
<dtid="evennia.utils.ansi.ANSIParser.ansi_regex">
<codeclass="sig-name descname">ansi_regex</code><emclass="property"> = re.compile('\\033\\[[0-9;]+m')</em><aclass="headerlink"href="#evennia.utils.ansi.ANSIParser.ansi_regex"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">ansi_escapes</code><emclass="property"> = re.compile('({{|\\\\|\\|\\|)', re.DOTALL)</em><aclass="headerlink"href="#evennia.utils.ansi.ANSIParser.ansi_escapes"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">unsafe_tokens</code><emclass="property"> = re.compile('\\|\\/|\\|-', re.DOTALL)</em><aclass="headerlink"href="#evennia.utils.ansi.ANSIParser.unsafe_tokens"title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIParser.sub_ansi">
<codeclass="sig-name descname">sub_ansi</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">ansimatch</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/ansi.html#ANSIParser.sub_ansi"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.ansi.ANSIParser.sub_ansi"title="Permalink to this definition">¶</a></dt>
<dd><p>Replacer used by <strong>re.sub</strong> to replace ANSI
markers with correct ANSI sequences</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>ansimatch</strong> (<em>re.matchobject</em>) – The match.</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>processed (str)</em>– The processed match string.</p>
<codeclass="sig-name descname">sub_brightbg</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">ansimatch</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/ansi.html#ANSIParser.sub_brightbg"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.ansi.ANSIParser.sub_brightbg"title="Permalink to this definition">¶</a></dt>
<dd><p>Replacer used by <strong>re.sub</strong> to replace ANSI
bright background markers with Xterm256 replacement</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>ansimatch</strong> (<em>re.matchobject</em>) – The match.</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>processed (str)</em>– The processed match string.</p>
<codeclass="sig-name descname">sub_xterm256</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">rgbmatch</span></em>, <emclass="sig-param"><spanclass="n">use_xterm256</span><spanclass="o">=</span><spanclass="default_value">False</span></em>, <emclass="sig-param"><spanclass="n">color_type</span><spanclass="o">=</span><spanclass="default_value">'fg'</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/ansi.html#ANSIParser.sub_xterm256"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.ansi.ANSIParser.sub_xterm256"title="Permalink to this definition">¶</a></dt>
<dd><p>This is a replacer method called by <strong>re.sub</strong> with the matched
tag. It must return the correct ansi sequence.</p>
<p>It checks <strong>self.do_xterm256</strong> to determine if conversion
to standard ANSI should be done or not.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>rgbmatch</strong> (<em>re.matchobject</em>) – The match.</p></li>
<li><p><strong>use_xterm256</strong> (<em>bool</em><em>, </em><em>optional</em>) – Don’t convert 256-colors to 16.</p></li>
<li><p><strong>color_type</strong> (<em>str</em>) – One of ‘fg’, ‘bg’, ‘gfg’, ‘gbg’.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>processed (str)</em>– The processed match string.</p>
<codeclass="sig-name descname">strip_raw_codes</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">string</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/ansi.html#ANSIParser.strip_raw_codes"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.ansi.ANSIParser.strip_raw_codes"title="Permalink to this definition">¶</a></dt>
<dd><p>Strips raw ANSI codes from a string.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>string</strong> (<em>str</em>) – The string to strip.</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>string (str)</em>– The processed string.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIParser.strip_mxp">
<codeclass="sig-name descname">strip_mxp</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">string</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/ansi.html#ANSIParser.strip_mxp"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.ansi.ANSIParser.strip_mxp"title="Permalink to this definition">¶</a></dt>
<dd><p>Strips all MXP codes from a string.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>string</strong> (<em>str</em>) – The string to strip.</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>string (str)</em>– The processed string.</p>
<codeclass="sig-name descname">strip_unsafe_tokens</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">string</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/ansi.html#ANSIParser.strip_unsafe_tokens"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.ansi.ANSIParser.strip_unsafe_tokens"title="Permalink to this definition">¶</a></dt>
<dd><p>Strip explicitly ansi line breaks and tabs.</p>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIParser.parse_ansi">
<codeclass="sig-name descname">parse_ansi</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">string</span></em>, <emclass="sig-param"><spanclass="n">strip_ansi</span><spanclass="o">=</span><spanclass="default_value">False</span></em>, <emclass="sig-param"><spanclass="n">xterm256</span><spanclass="o">=</span><spanclass="default_value">False</span></em>, <emclass="sig-param"><spanclass="n">mxp</span><spanclass="o">=</span><spanclass="default_value">False</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/ansi.html#ANSIParser.parse_ansi"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.ansi.ANSIParser.parse_ansi"title="Permalink to this definition">¶</a></dt>
<dd><p>Parses a string, subbing color codes according to the stored
mapping.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>string</strong> (<em>str</em>) – The string to parse.</p></li>
<li><p><strong>strip_ansi</strong> (<em>boolean</em><em>, </em><em>optional</em>) – Strip all found ansi markup.</p></li>
<li><p><strong>xterm256</strong> (<em>boolean</em><em>, </em><em>optional</em>) – If actually using xterm256 or if
these values should be converted to 16-color ANSI.</p></li>
<li><p><strong>mxp</strong> (<em>boolean</em><em>, </em><em>optional</em>) – Parse MXP commands in string.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>string (str)</em>– The parsed string.</p>
</dd>
</dl>
</dd></dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.ansi.parse_ansi">
<codeclass="sig-prename descclassname">evennia.utils.ansi.</code><codeclass="sig-name descname">parse_ansi</code><spanclass="sig-paren">(</span><emclass="sig-param">string</em>, <emclass="sig-param">strip_ansi=False</em>, <emclass="sig-param">parser=<evennia.utils.ansi.ANSIParser object></em>, <emclass="sig-param">xterm256=False</em>, <emclass="sig-param">mxp=False</em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/ansi.html#parse_ansi"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.ansi.parse_ansi"title="Permalink to this definition">¶</a></dt>
<dd><p>Parses a string, subbing color codes as needed.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>string</strong> (<em>str</em>) – The string to parse.</p></li>
<li><p><strong>strip_ansi</strong> (<em>bool</em><em>, </em><em>optional</em>) – Strip all ANSI sequences.</p></li>
<li><p><strong>parser</strong> (<em>ansi.AnsiParser</em><em>, </em><em>optional</em>) – A parser instance to use.</p></li>
<li><p><strong>xterm256</strong> (<em>bool</em><em>, </em><em>optional</em>) – Support xterm256 or not.</p></li>
<li><p><strong>mxp</strong> (<em>bool</em><em>, </em><em>optional</em>) – Support MXP markup or not.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>string (str)</em>– The parsed string.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.ansi.strip_ansi">
<codeclass="sig-prename descclassname">evennia.utils.ansi.</code><codeclass="sig-name descname">strip_ansi</code><spanclass="sig-paren">(</span><emclass="sig-param">string</em>, <emclass="sig-param">parser=<evennia.utils.ansi.ANSIParser object></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/ansi.html#strip_ansi"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.ansi.strip_ansi"title="Permalink to this definition">¶</a></dt>
<dd><p>Strip all ansi from the string. This handles the Evennia-specific
markup.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>string</strong> (<em>str</em>) – The string to strip.</p></li>
<li><p><strong>parser</strong> (<em>ansi.AnsiParser</em><em>, </em><em>optional</em>) – The parser to use.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>string (str)</em>– The stripped string.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.ansi.strip_raw_ansi">
<codeclass="sig-prename descclassname">evennia.utils.ansi.</code><codeclass="sig-name descname">strip_raw_ansi</code><spanclass="sig-paren">(</span><emclass="sig-param">string</em>, <emclass="sig-param">parser=<evennia.utils.ansi.ANSIParser object></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/ansi.html#strip_raw_ansi"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.ansi.strip_raw_ansi"title="Permalink to this definition">¶</a></dt>
<dd><p>Remove raw ansi codes from string. This assumes pure
ANSI-bytecodes in the string.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>string</strong> (<em>str</em>) – The string to parse.</p></li>
<li><p><strong>parser</strong> (<em>bool</em><em>, </em><em>optional</em>) – The parser to use.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>string (str)</em>– the stripped string.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.ansi.strip_unsafe_tokens">
<codeclass="sig-prename descclassname">evennia.utils.ansi.</code><codeclass="sig-name descname">strip_unsafe_tokens</code><spanclass="sig-paren">(</span><emclass="sig-param">string</em>, <emclass="sig-param">parser=<evennia.utils.ansi.ANSIParser object></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/ansi.html#strip_unsafe_tokens"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.ansi.strip_unsafe_tokens"title="Permalink to this definition">¶</a></dt>
<dd><p>Strip markup that can be used to create visual exploits
(notably linebreaks and tags)</p>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.ansi.strip_mxp">
<codeclass="sig-prename descclassname">evennia.utils.ansi.</code><codeclass="sig-name descname">strip_mxp</code><spanclass="sig-paren">(</span><emclass="sig-param">string</em>, <emclass="sig-param">parser=<evennia.utils.ansi.ANSIParser object></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/ansi.html#strip_mxp"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.ansi.strip_mxp"title="Permalink to this definition">¶</a></dt>
<dd><p>Strip MXP markup.</p>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.ansi.raw">
<codeclass="sig-prename descclassname">evennia.utils.ansi.</code><codeclass="sig-name descname">raw</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">string</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/ansi.html#raw"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.ansi.raw"title="Permalink to this definition">¶</a></dt>
<dd><p>Escapes a string into a form which won’t be colorized by the ansi
parser.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Returns</dt>
<ddclass="field-odd"><p><em>string (str)</em>– The raw, escaped string.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py class">
<dtid="evennia.utils.ansi.ANSIMeta">
<emclass="property">class </em><codeclass="sig-prename descclassname">evennia.utils.ansi.</code><codeclass="sig-name descname">ANSIMeta</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="o">*</span><spanclass="n">args</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/ansi.html#ANSIMeta"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.ansi.ANSIMeta"title="Permalink to this definition">¶</a></dt>
<p>Many functions on ANSIString are just light wrappers around the string
base class. We apply them here, as part of the classes construction.</p>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIMeta.__init__">
<codeclass="sig-name descname">__init__</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="o">*</span><spanclass="n">args</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/ansi.html#ANSIMeta.__init__"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.ansi.ANSIMeta.__init__"title="Permalink to this definition">¶</a></dt>
<dd><p>Initialize self. See help(type(self)) for accurate signature.</p>
</dd></dl>
</dd></dl>
<dlclass="py class">
<dtid="evennia.utils.ansi.ANSIString">
<emclass="property">class </em><codeclass="sig-prename descclassname">evennia.utils.ansi.</code><codeclass="sig-name descname">ANSIString</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="o">*</span><spanclass="n">args</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/ansi.html#ANSIString"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.ansi.ANSIString"title="Permalink to this definition">¶</a></dt>
<p>Unicode-like object that is aware of ANSI codes.</p>
<p>This class can be used nearly identically to strings, in that it will
report string length, handle slices, etc, much like a string object
would. The methods should be used identically as string methods are.</p>
<p>There is at least one exception to this (and there may be more, though
they have not come up yet). When using ‘’.join() or u’’.join() on an
ANSIString, color information will get lost. You must use
ANSIString(‘’).join() to preserve color information.</p>
<p>This implementation isn’t perfectly clean, as it doesn’t really have an
understanding of what the codes mean in order to eliminate
redundant characters– though cleaning up the strings might end up being
inefficient and slow without some C code when dealing with larger values.
Such enhancements could be made as an enhancement to ANSI_PARSER
if needed, however.</p>
<p>If one is going to use ANSIString, one should generally avoid converting
away from it until one is about to send information on the wire. This is
because escape sequences in the string may otherwise already be decoded,
and taken literally the second time around.</p>
<dlclass="py attribute">
<dtid="evennia.utils.ansi.ANSIString.re_format">
<codeclass="sig-name descname">re_format</code><emclass="property"> = re.compile('(?i)(?P<just>(?P<fill>.)?(?P<align>\\<|\\>|\\=|\\^))?(?P<sign>\\+|\\-| )?(?P<alt>\\#)?(?P<zero>0)?(?P<width>\\d+)?(?P<grouping>\\_|\\,)?(?:\\.(?P<precision>\\d+))?(?P<type>b|c|d|e|E|f|F|g|G|n|o|s|x|X, re.IGNORECASE)</em><aclass="headerlink"href="#evennia.utils.ansi.ANSIString.re_format"title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.__init__">
<codeclass="sig-name descname">__init__</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="o">*</span><spanclass="n">_</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/ansi.html#ANSIString.__init__"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.ansi.ANSIString.__init__"title="Permalink to this definition">¶</a></dt>
<dd><p>When the ANSIString is first initialized, a few internal variables
have to be set.</p>
<p>The first is the parser. It is possible to replace Evennia’s standard
ANSI parser with one of your own syntax if you wish, so long as it
implements the same interface.</p>
<p>The second is the _raw_string. This is the original “dumb” string
with ansi escapes that ANSIString represents.</p>
<p>The third thing to set is the _clean_string. This is a string that is
devoid of all ANSI Escapes.</p>
<p>Finally, _code_indexes and _char_indexes are defined. These are lookup
tables for which characters in the raw string are related to ANSI
escapes, and which are for the readable text.</p>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.clean">
<codeclass="sig-name descname">clean</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/ansi.html#ANSIString.clean"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.ansi.ANSIString.clean"title="Permalink to this definition">¶</a></dt>
<dd><p>Return a string object <em>without</em> the ANSI escapes.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Returns</dt>
<ddclass="field-odd"><p><em>clean_string (str)</em>– A unicode object with no ANSI escapes.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.raw">
<codeclass="sig-name descname">raw</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/ansi.html#ANSIString.raw"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.ansi.ANSIString.raw"title="Permalink to this definition">¶</a></dt>
<dd><p>Return a string object with the ANSI escapes.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Returns</dt>
<ddclass="field-odd"><p><em>raw (str)</em>– A unicode object <em>with</em> the raw ANSI escape sequences.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.partition">
<codeclass="sig-name descname">partition</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">sep</span></em>, <emclass="sig-param"><spanclass="n">reverse</span><spanclass="o">=</span><spanclass="default_value">False</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/ansi.html#ANSIString.partition"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.ansi.ANSIString.partition"title="Permalink to this definition">¶</a></dt>
<dd><p>Splits once into three sections (with the separator being the middle section)</p>
<p>We use the same techniques we used in split() to make sure each are
colored.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>sep</strong> (<em>str</em>) – The separator to split the string on.</p></li>
<li><p><strong>reverse</strong> (<em>boolean</em>) – Whether to split the string on the last
occurrence of the separator rather than the first.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>ANSIString</em>– The part of the string before the separator
ANSIString: The separator itself
ANSIString: The part of the string after the separator.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.split">
<codeclass="sig-name descname">split</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">by</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <emclass="sig-param"><spanclass="n">maxsplit</span><spanclass="o">=</span><spanclass="default_value">- 1</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/ansi.html#ANSIString.split"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.ansi.ANSIString.split"title="Permalink to this definition">¶</a></dt>
<dd><p>Splits a string based on a separator.</p>
<p>Stolen from PyPy’s pure Python string implementation, tweaked for
<li><p><strong>by</strong> (<em>str</em>) – A string to search for which will be used to split
the string. For instance, ‘,’ for ‘Hello,world’ would
result in [‘Hello’, ‘world’]</p></li>
<li><p><strong>maxsplit</strong> (<em>int</em>) – The maximum number of times to split the string.
For example, a maxsplit of 2 with a by of ‘,’ on the string
‘Hello,world,test,string’ would result in
[‘Hello’, ‘world’, ‘test,string’]</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><p><em>result (list of ANSIStrings)</em>–</p>
<dlclass="simple">
<dt>A list of ANSIStrings derived from</dt><dd><p>this string.</p>
</dd>
</dl>
</p>
</dd>
</dl>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.rsplit">
<codeclass="sig-name descname">rsplit</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">by</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <emclass="sig-param"><spanclass="n">maxsplit</span><spanclass="o">=</span><spanclass="default_value">- 1</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/ansi.html#ANSIString.rsplit"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.ansi.ANSIString.rsplit"title="Permalink to this definition">¶</a></dt>
<dd><p>Like split, but starts from the end of the string rather than the
beginning.</p>
<p>Stolen from PyPy’s pure Python string implementation, tweaked for
<li><p><strong>by</strong> (<em>str</em>) – A string to search for which will be used to split
the string. For instance, ‘,’ for ‘Hello,world’ would
result in [‘Hello’, ‘world’]</p></li>
<li><p><strong>maxsplit</strong> (<em>int</em>) – The maximum number of times to split the string.
For example, a maxsplit of 2 with a by of ‘,’ on the string
‘Hello,world,test,string’ would result in
[‘Hello,world’, ‘test’, ‘string’]</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><p><em>result (list of ANSIStrings)</em>–</p>
<dlclass="simple">
<dt>A list of ANSIStrings derived from</dt><dd><p>this string.</p>
</dd>
</dl>
</p>
</dd>
</dl>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.strip">
<codeclass="sig-name descname">strip</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">chars</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/ansi.html#ANSIString.strip"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.ansi.ANSIString.strip"title="Permalink to this definition">¶</a></dt>
<dd><p>Strip from both ends, taking ANSI markers into account.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>chars</strong> (<em>str</em><em>, </em><em>optional</em>) – A string containing individual characters
to strip off of both ends of the string. By default, any blank
<dt>A new ANSIString with the ends trimmed of the</dt><dd><p>relevant characters.</p>
</dd>
</dl>
</p>
</dd>
</dl>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.lstrip">
<codeclass="sig-name descname">lstrip</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">chars</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/ansi.html#ANSIString.lstrip"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.ansi.ANSIString.lstrip"title="Permalink to this definition">¶</a></dt>
<dd><p>Strip from the left, taking ANSI markers into account.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>chars</strong> (<em>str</em><em>, </em><em>optional</em>) – A string containing individual characters
to strip off of the left end of the string. By default, any
<dt>A new ANSIString with the left end trimmed of</dt><dd><p>the relevant characters.</p>
</dd>
</dl>
</p>
</dd>
</dl>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.capitalize">
<codeclass="sig-name descname">capitalize</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="o">*</span><spanclass="n">args</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#evennia.utils.ansi.ANSIString.capitalize"title="Permalink to this definition">¶</a></dt>
<dd><p>Return a capitalized version of the string.</p>
<p>More specifically, make the first character have upper case and the rest lower
case.</p>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.count">
<codeclass="sig-name descname">count</code><spanclass="sig-paren">(</span><emclass="sig-param">sub</em><spanclass="optional">[</span>, <emclass="sig-param">start</em><spanclass="optional">[</span>, <emclass="sig-param">end</em><spanclass="optional">]</span><spanclass="optional">]</span><spanclass="sig-paren">)</span>→ int<aclass="headerlink"href="#evennia.utils.ansi.ANSIString.count"title="Permalink to this definition">¶</a></dt>
<dd><p>Return the number of non-overlapping occurrences of substring sub in
string S[start:end]. Optional arguments start and end are
interpreted as in slice notation.</p>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.decode">
<codeclass="sig-name descname">decode</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="o">*</span><spanclass="n">args</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#evennia.utils.ansi.ANSIString.decode"title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.encode">
<codeclass="sig-name descname">encode</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="o">*</span><spanclass="n">args</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#evennia.utils.ansi.ANSIString.encode"title="Permalink to this definition">¶</a></dt>
<dd><p>Encode the string using the codec registered for encoding.</p>
<dlclass="simple">
<dt>encoding</dt><dd><p>The encoding in which to encode the string.</p>
</dd>
<dt>errors</dt><dd><p>The error handling scheme to use for encoding errors.
The default is ‘strict’ meaning that encoding errors raise a
UnicodeEncodeError. Other possible values are ‘ignore’, ‘replace’ and
‘xmlcharrefreplace’ as well as any other name registered with
codecs.register_error that can handle UnicodeEncodeErrors.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.endswith">
<codeclass="sig-name descname">endswith</code><spanclass="sig-paren">(</span><emclass="sig-param">suffix</em><spanclass="optional">[</span>, <emclass="sig-param">start</em><spanclass="optional">[</span>, <emclass="sig-param">end</em><spanclass="optional">]</span><spanclass="optional">]</span><spanclass="sig-paren">)</span>→ bool<aclass="headerlink"href="#evennia.utils.ansi.ANSIString.endswith"title="Permalink to this definition">¶</a></dt>
<dd><p>Return True if S ends with the specified suffix, False otherwise.
With optional start, test S beginning at that position.
With optional end, stop comparing S at that position.
suffix can also be a tuple of strings to try.</p>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.expandtabs">
<codeclass="sig-name descname">expandtabs</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="o">*</span><spanclass="n">args</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#evennia.utils.ansi.ANSIString.expandtabs"title="Permalink to this definition">¶</a></dt>
<dd><p>Return a copy where all tab characters are expanded using spaces.</p>
<p>If tabsize is not given, a tab size of 8 characters is assumed.</p>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.find">
<codeclass="sig-name descname">find</code><spanclass="sig-paren">(</span><emclass="sig-param">sub</em><spanclass="optional">[</span>, <emclass="sig-param">start</em><spanclass="optional">[</span>, <emclass="sig-param">end</em><spanclass="optional">]</span><spanclass="optional">]</span><spanclass="sig-paren">)</span>→ int<aclass="headerlink"href="#evennia.utils.ansi.ANSIString.find"title="Permalink to this definition">¶</a></dt>
<dd><p>Return the lowest index in S where substring sub is found,
such that sub is contained within S[start:end]. Optional
arguments start and end are interpreted as in slice notation.</p>
<p>Return -1 on failure.</p>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.format">
<codeclass="sig-name descname">format</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="o">*</span><spanclass="n">args</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span>→ str<aclass="headerlink"href="#evennia.utils.ansi.ANSIString.format"title="Permalink to this definition">¶</a></dt>
<dd><p>Return a formatted version of S, using substitutions from args and kwargs.
The substitutions are identified by braces (‘{’ and ‘}’).</p>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.index">
<codeclass="sig-name descname">index</code><spanclass="sig-paren">(</span><emclass="sig-param">sub</em><spanclass="optional">[</span>, <emclass="sig-param">start</em><spanclass="optional">[</span>, <emclass="sig-param">end</em><spanclass="optional">]</span><spanclass="optional">]</span><spanclass="sig-paren">)</span>→ int<aclass="headerlink"href="#evennia.utils.ansi.ANSIString.index"title="Permalink to this definition">¶</a></dt>
<dd><p>Return the lowest index in S where substring sub is found,
such that sub is contained within S[start:end]. Optional
arguments start and end are interpreted as in slice notation.</p>
<p>Raises ValueError when the substring is not found.</p>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.isalnum">
<codeclass="sig-name descname">isalnum</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="o">*</span><spanclass="n">args</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#evennia.utils.ansi.ANSIString.isalnum"title="Permalink to this definition">¶</a></dt>
<dd><p>Return True if the string is an alpha-numeric string, False otherwise.</p>
<p>A string is alpha-numeric if all characters in the string are alpha-numeric and
there is at least one character in the string.</p>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.isalpha">
<codeclass="sig-name descname">isalpha</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="o">*</span><spanclass="n">args</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#evennia.utils.ansi.ANSIString.isalpha"title="Permalink to this definition">¶</a></dt>
<dd><p>Return True if the string is an alphabetic string, False otherwise.</p>
<p>A string is alphabetic if all characters in the string are alphabetic and there
is at least one character in the string.</p>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.isdigit">
<codeclass="sig-name descname">isdigit</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="o">*</span><spanclass="n">args</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#evennia.utils.ansi.ANSIString.isdigit"title="Permalink to this definition">¶</a></dt>
<dd><p>Return True if the string is a digit string, False otherwise.</p>
<p>A string is a digit string if all characters in the string are digits and there
is at least one character in the string.</p>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.islower">
<codeclass="sig-name descname">islower</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="o">*</span><spanclass="n">args</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#evennia.utils.ansi.ANSIString.islower"title="Permalink to this definition">¶</a></dt>
<dd><p>Return True if the string is a lowercase string, False otherwise.</p>
<p>A string is lowercase if all cased characters in the string are lowercase and
there is at least one cased character in the string.</p>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.isspace">
<codeclass="sig-name descname">isspace</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="o">*</span><spanclass="n">args</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#evennia.utils.ansi.ANSIString.isspace"title="Permalink to this definition">¶</a></dt>
<dd><p>Return True if the string is a whitespace string, False otherwise.</p>
<p>A string is whitespace if all characters in the string are whitespace and there
is at least one character in the string.</p>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.istitle">
<codeclass="sig-name descname">istitle</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="o">*</span><spanclass="n">args</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#evennia.utils.ansi.ANSIString.istitle"title="Permalink to this definition">¶</a></dt>
<dd><p>Return True if the string is a title-cased string, False otherwise.</p>
<p>In a title-cased string, upper- and title-case characters may only
follow uncased characters and lowercase characters only cased ones.</p>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.isupper">
<codeclass="sig-name descname">isupper</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="o">*</span><spanclass="n">args</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#evennia.utils.ansi.ANSIString.isupper"title="Permalink to this definition">¶</a></dt>
<dd><p>Return True if the string is an uppercase string, False otherwise.</p>
<p>A string is uppercase if all cased characters in the string are uppercase and
there is at least one cased character in the string.</p>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.lower">
<codeclass="sig-name descname">lower</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="o">*</span><spanclass="n">args</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#evennia.utils.ansi.ANSIString.lower"title="Permalink to this definition">¶</a></dt>
<dd><p>Return a copy of the string converted to lowercase.</p>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.replace">
<codeclass="sig-name descname">replace</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="o">*</span><spanclass="n">args</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#evennia.utils.ansi.ANSIString.replace"title="Permalink to this definition">¶</a></dt>
<dd><p>Return a copy with all occurrences of substring old replaced by new.</p>
<blockquote>
<div><dlclass="simple">
<dt>count</dt><dd><p>Maximum number of occurrences to replace.
-1 (the default value) means replace all occurrences.</p>
</dd>
</dl>
</div></blockquote>
<p>If the optional argument count is given, only the first count occurrences are
replaced.</p>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.rfind">
<codeclass="sig-name descname">rfind</code><spanclass="sig-paren">(</span><emclass="sig-param">sub</em><spanclass="optional">[</span>, <emclass="sig-param">start</em><spanclass="optional">[</span>, <emclass="sig-param">end</em><spanclass="optional">]</span><spanclass="optional">]</span><spanclass="sig-paren">)</span>→ int<aclass="headerlink"href="#evennia.utils.ansi.ANSIString.rfind"title="Permalink to this definition">¶</a></dt>
<dd><p>Return the highest index in S where substring sub is found,
such that sub is contained within S[start:end]. Optional
arguments start and end are interpreted as in slice notation.</p>
<p>Return -1 on failure.</p>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.rindex">
<codeclass="sig-name descname">rindex</code><spanclass="sig-paren">(</span><emclass="sig-param">sub</em><spanclass="optional">[</span>, <emclass="sig-param">start</em><spanclass="optional">[</span>, <emclass="sig-param">end</em><spanclass="optional">]</span><spanclass="optional">]</span><spanclass="sig-paren">)</span>→ int<aclass="headerlink"href="#evennia.utils.ansi.ANSIString.rindex"title="Permalink to this definition">¶</a></dt>
<dd><p>Return the highest index in S where substring sub is found,
such that sub is contained within S[start:end]. Optional
arguments start and end are interpreted as in slice notation.</p>
<p>Raises ValueError when the substring is not found.</p>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.rstrip">
<codeclass="sig-name descname">rstrip</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">chars</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/ansi.html#ANSIString.rstrip"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.ansi.ANSIString.rstrip"title="Permalink to this definition">¶</a></dt>
<dd><p>Strip from the right, taking ANSI markers into account.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>chars</strong> (<em>str</em><em>, </em><em>optional</em>) – A string containing individual characters
to strip off of the right end of the string. By default, any
<dt>A new ANSIString with the right end trimmed of</dt><dd><p>the relevant characters.</p>
</dd>
</dl>
</p>
</dd>
</dl>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.startswith">
<codeclass="sig-name descname">startswith</code><spanclass="sig-paren">(</span><emclass="sig-param">prefix</em><spanclass="optional">[</span>, <emclass="sig-param">start</em><spanclass="optional">[</span>, <emclass="sig-param">end</em><spanclass="optional">]</span><spanclass="optional">]</span><spanclass="sig-paren">)</span>→ bool<aclass="headerlink"href="#evennia.utils.ansi.ANSIString.startswith"title="Permalink to this definition">¶</a></dt>
<dd><p>Return True if S starts with the specified prefix, False otherwise.
With optional start, test S beginning at that position.
With optional end, stop comparing S at that position.
prefix can also be a tuple of strings to try.</p>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.swapcase">
<codeclass="sig-name descname">swapcase</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="o">*</span><spanclass="n">args</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#evennia.utils.ansi.ANSIString.swapcase"title="Permalink to this definition">¶</a></dt>
<dd><p>Convert uppercase characters to lowercase and lowercase characters to uppercase.</p>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.translate">
<codeclass="sig-name descname">translate</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="o">*</span><spanclass="n">args</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#evennia.utils.ansi.ANSIString.translate"title="Permalink to this definition">¶</a></dt>
<dd><p>Replace each character in the string using the given translation table.</p>
<blockquote>
<div><dlclass="simple">
<dt>table</dt><dd><p>Translation table, which must be a mapping of Unicode ordinals to
Unicode ordinals, strings, or None.</p>
</dd>
</dl>
</div></blockquote>
<p>The table must implement lookup/indexing via __getitem__, for instance a
dictionary or list. If this operation raises LookupError, the character is
left untouched. Characters mapped to None are deleted.</p>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.upper">
<codeclass="sig-name descname">upper</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="o">*</span><spanclass="n">args</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#evennia.utils.ansi.ANSIString.upper"title="Permalink to this definition">¶</a></dt>
<dd><p>Return a copy of the string converted to uppercase.</p>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.join">
<codeclass="sig-name descname">join</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">iterable</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/ansi.html#ANSIString.join"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.ansi.ANSIString.join"title="Permalink to this definition">¶</a></dt>
<dd><p>Joins together strings in an iterable, using this string between each
one.</p>
<p>NOTE: This should always be used for joining strings when ANSIStrings
are involved. Otherwise color information will be discarded by python,
due to details in the C implementation of strings.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>iterable</strong> (<em>list of strings</em>) – A list of strings to join together</p>
<codeclass="sig-name descname">center</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">width</span></em>, <emclass="sig-param"><spanclass="n">fillchar</span></em>, <emclass="sig-param"><spanclass="n">_difference</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/ansi.html#ANSIString.center"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.ansi.ANSIString.center"title="Permalink to this definition">¶</a></dt>
<dd><p>Center some text with some spaces padding both sides.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>width</strong> (<em>int</em>) – The target width of the output string.</p></li>
<li><p><strong>fillchar</strong> (<em>str</em>) – A single character string to pad the output string
with.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>result (ANSIString)</em>– A string padded on both ends with fillchar.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.ljust">
<codeclass="sig-name descname">ljust</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">width</span></em>, <emclass="sig-param"><spanclass="n">fillchar</span></em>, <emclass="sig-param"><spanclass="n">_difference</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/ansi.html#ANSIString.ljust"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.ansi.ANSIString.ljust"title="Permalink to this definition">¶</a></dt>
<dd><p>Left justify some text.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>width</strong> (<em>int</em>) – The target width of the output string.</p></li>
<li><p><strong>fillchar</strong> (<em>str</em>) – A single character string to pad the output string
with.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>result (ANSIString)</em>– A string padded on the right with fillchar.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py method">
<dtid="evennia.utils.ansi.ANSIString.rjust">
<codeclass="sig-name descname">rjust</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">width</span></em>, <emclass="sig-param"><spanclass="n">fillchar</span></em>, <emclass="sig-param"><spanclass="n">_difference</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/ansi.html#ANSIString.rjust"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.ansi.ANSIString.rjust"title="Permalink to this definition">¶</a></dt>
<dd><p>Right justify some text.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>width</strong> (<em>int</em>) – The target width of the output string.</p></li>
<li><p><strong>fillchar</strong> (<em>str</em>) – A single character string to pad the output string
with.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>result (ANSIString)</em>– A string padded on the left with fillchar.</p>