We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
CodeInput doesn't work with IniLexer
https://gist.github.com/aron-bordin/df00122f90231d5081d4

It's not possible to add [ in the first column:

![screenshot from 2015-06-14 23-48-03](https://cloud.githubusercontent.com/assets/4960137/8152165/1a0127a6-12f0-11e5-9b82-30176653d074.png)


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `kivy/uix/codeinput.py`
Content:
```
1 '''
2 Code Input
3 ==========
4 
5 .. versionadded:: 1.5.0
6 
7 .. image:: images/codeinput.jpg
8 
9 
10 The :class:`CodeInput` provides a box of editable highlighted text like the one
11 shown in the image.
12 
13 It supports all the features provided by the :class:`~kivy.uix.textinput` as
14 well as code highlighting for `languages supported by pygments
15 <http://pygments.org/docs/lexers/>`_ along with `KivyLexer` for
16 :mod:`kivy.lang` highlighting.
17 
18 Usage example
19 -------------
20 
21 To create a CodeInput with highlighting for `KV language`::
22 
23     from kivy.uix.codeinput import CodeInput
24     from kivy.extras.highlight import KivyLexer
25     codeinput = CodeInput(lexer=KivyLexer())
26 
27 To create a CodeInput with highlighting for `Cython`::
28 
29     from kivy.uix.codeinput import CodeInput
30     from pygments.lexers import CythonLexer
31     codeinput = CodeInput(lexer=CythonLexer())
32 
33 '''
34 
35 __all__ = ('CodeInput', )
36 
37 from pygments import highlight
38 from pygments import lexers
39 from pygments import styles
40 from pygments.formatters import BBCodeFormatter
41 
42 from kivy.uix.textinput import TextInput
43 from kivy.core.text.markup import MarkupLabel as Label
44 from kivy.cache import Cache
45 from kivy.properties import ObjectProperty, OptionProperty
46 from kivy.utils import get_hex_from_color
47 
48 Cache_get = Cache.get
49 Cache_append = Cache.append
50 
51 # TODO: color chooser for keywords/strings/...
52 
53 
54 class CodeInput(TextInput):
55     '''CodeInput class, used for displaying highlighted code.
56     '''
57 
58     lexer = ObjectProperty(None)
59     '''This holds the selected Lexer used by pygments to highlight the code.
60 
61 
62     :attr:`lexer` is an :class:`~kivy.properties.ObjectProperty` and
63     defaults to `PythonLexer`.
64     '''
65 
66     style_name = OptionProperty(
67         'default', options=list(styles.get_all_styles())
68     )
69     '''Name of the pygments style to use for formatting.
70 
71     :attr:`style_name` is an :class:`~kivy.properties.OptionProperty`
72     and defaults to ``'default'``.
73 
74     '''
75 
76     style = ObjectProperty(None)
77     '''The pygments style object to use for formatting.
78 
79     When ``style_name`` is set, this will be changed to the
80     corresponding style object.
81 
82     :attr:`style` is a :class:`~kivy.properties.ObjectProperty` and
83     defaults to ``None``
84 
85     '''
86 
87     def __init__(self, **kwargs):
88         stylename = kwargs.get('style_name', 'default')
89         style = kwargs['style'] if 'style' in kwargs \
90             else styles.get_style_by_name(stylename)
91         self.formatter = BBCodeFormatter(style=style)
92         self.lexer = lexers.PythonLexer()
93         self.text_color = '#000000'
94         self._label_cached = Label()
95         self.use_text_color = True
96 
97         super(CodeInput, self).__init__(**kwargs)
98 
99         self._line_options = kw = self._get_line_options()
100         self._label_cached = Label(**kw)
101         # use text_color as foreground color
102         text_color = kwargs.get('foreground_color')
103         if text_color:
104             self.text_color = get_hex_from_color(text_color)
105         # set foreground to white to allow text colors to show
106         # use text_color as the default color in bbcodes
107         self.use_text_color = False
108         self.foreground_color = [1, 1, 1, .999]
109         if not kwargs.get('background_color'):
110             self.background_color = [.9, .92, .92, 1]
111 
112     def on_style_name(self, *args):
113         self.style = styles.get_style_by_name(self.style_name)
114 
115     def on_style(self, *args):
116         self.formatter = BBCodeFormatter(style=self.style)
117         self._trigger_update_graphics()
118 
119     def _create_line_label(self, text, hint=False):
120         # Create a label from a text, using line options
121         ntext = text.replace(u'\n', u'').replace(u'\t', u' ' * self.tab_width)
122         if self.password and not hint:  # Don't replace hint_text with *
123             ntext = u'*' * len(ntext)
124         ntext = self._get_bbcode(ntext)
125         kw = self._get_line_options()
126         cid = u'{}\0{}\0{}'.format(ntext, self.password, kw)
127         texture = Cache_get('textinput.label', cid)
128 
129         if texture is None:
130             # FIXME right now, we can't render very long line...
131             # if we move on "VBO" version as fallback, we won't need to
132             # do this.
133             # try to find the maximum text we can handle
134             label = Label(text=ntext, **kw)
135             if text.find(u'\n') > 0:
136                 label.text = u''
137             else:
138                 label.text = ntext
139             label.refresh()
140 
141             # ok, we found it.
142             texture = label.texture
143             Cache_append('textinput.label', cid, texture)
144             label.text = ''
145         return texture
146 
147     def _get_line_options(self):
148         kw = super(CodeInput, self)._get_line_options()
149         kw['markup'] = True
150         kw['valign'] = 'top'
151         kw['codeinput'] = repr(self.lexer)
152         return kw
153 
154     def _get_text_width(self, text, tab_width, _label_cached):
155         # Return the width of a text, according to the current line options.
156         cid = u'{}\0{}\0{}'.format(text, self.password,
157                                    self._get_line_options())
158         width = Cache_get('textinput.width', cid)
159         if width is not None:
160             return width
161         lbl = self._create_line_label(text)
162         width = lbl.width
163         Cache_append('textinput.width', cid, width)
164         return width
165 
166     def _get_bbcode(self, ntext):
167         # get bbcoded text for python
168         try:
169             ntext[0]
170             # replace brackets with special chars that aren't highlighted
171             # by pygment. can't use &bl; ... cause & is highlighted
172             ntext = ntext.replace(u'[', u'\x01;').replace(u']', u'\x02;')
173             ntext = highlight(ntext, self.lexer, self.formatter)
174             ntext = ntext.replace(u'\x01;', u'&bl;').replace(u'\x02;', u'&br;')
175             # replace special chars with &bl; and &br;
176             ntext = ''.join((u'[color=', str(self.text_color), u']',
177                              ntext, u'[/color]'))
178             ntext = ntext.replace(u'\n', u'')
179             return ntext
180         except IndexError:
181             return ''
182 
183     # overriden to prevent cursor position off screen
184     def _cursor_offset(self):
185         '''Get the cursor x offset on the current line
186         '''
187         offset = 0
188         try:
189             if self.cursor_col:
190                 offset = self._get_text_width(
191                     self._lines[self.cursor_row][:self.cursor_col])
192                 return offset
193         except:
194             pass
195         finally:
196             return offset
197 
198     def on_lexer(self, instance, value):
199         self._trigger_refresh_text()
200 
201     def on_foreground_color(self, instance, text_color):
202         if not self.use_text_color:
203             self.use_text_color = True
204             return
205         self.text_color = get_hex_from_color(text_color)
206         self.use_text_color = False
207         self.foreground_color = (1, 1, 1, .999)
208         self._trigger_refresh_text()
209 
210 
211 if __name__ == '__main__':
212     from kivy.extras.highlight import KivyLexer
213     from kivy.app import App
214 
215     class CodeInputTest(App):
216         def build(self):
217             return CodeInput(lexer=KivyLexer(),
218                              font_name='data/fonts/DroidSansMono.ttf',
219                              font_size=12,
220                              text='''
221 #:kivy 1.0
222 
223 <YourWidget>:
224     canvas:
225         Color:
226             rgb: .5, .5, .5
227         Rectangle:
228             pos: self.pos
229             size: self.size''')
230 
231     CodeInputTest().run()
232
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/kivy/uix/codeinput.py b/kivy/uix/codeinput.py
--- a/kivy/uix/codeinput.py
+++ b/kivy/uix/codeinput.py
@@ -169,9 +169,9 @@
             ntext[0]
             # replace brackets with special chars that aren't highlighted
             # by pygment. can't use &bl; ... cause & is highlighted
-            ntext = ntext.replace(u'[', u'\x01;').replace(u']', u'\x02;')
+            ntext = ntext.replace(u'[', u'\x01').replace(u']', u'\x02')
             ntext = highlight(ntext, self.lexer, self.formatter)
-            ntext = ntext.replace(u'\x01;', u'&bl;').replace(u'\x02;', u'&br;')
+            ntext = ntext.replace(u'\x01', u'&bl;').replace(u'\x02', u'&br;')
             # replace special chars with &bl; and &br;
             ntext = ''.join((u'[color=', str(self.text_color), u']',
                              ntext, u'[/color]'))

{"golden_diff": "diff --git a/kivy/uix/codeinput.py b/kivy/uix/codeinput.py\n--- a/kivy/uix/codeinput.py\n+++ b/kivy/uix/codeinput.py\n@@ -169,9 +169,9 @@\n             ntext[0]\n             # replace brackets with special chars that aren't highlighted\n             # by pygment. can't use &bl; ... cause & is highlighted\n-            ntext = ntext.replace(u'[', u'\\x01;').replace(u']', u'\\x02;')\n+            ntext = ntext.replace(u'[', u'\\x01').replace(u']', u'\\x02')\n             ntext = highlight(ntext, self.lexer, self.formatter)\n-            ntext = ntext.replace(u'\\x01;', u'&bl;').replace(u'\\x02;', u'&br;')\n+            ntext = ntext.replace(u'\\x01', u'&bl;').replace(u'\\x02', u'&br;')\n             # replace special chars with &bl; and &br;\n             ntext = ''.join((u'[color=', str(self.text_color), u']',\n                              ntext, u'[/color]'))\n", "issue": "CodeInput doesn't work with IniLexer\nhttps://gist.github.com/aron-bordin/df00122f90231d5081d4\n\nIt's not possible to add [ in the first column:\n\n![screenshot from 2015-06-14 23-48-03](https://cloud.githubusercontent.com/assets/4960137/8152165/1a0127a6-12f0-11e5-9b82-30176653d074.png)\n\n", "before_files": [{"content": "'''\nCode Input\n==========\n\n.. versionadded:: 1.5.0\n\n.. image:: images/codeinput.jpg\n\n\nThe :class:`CodeInput` provides a box of editable highlighted text like the one\nshown in the image.\n\nIt supports all the features provided by the :class:`~kivy.uix.textinput` as\nwell as code highlighting for `languages supported by pygments\n<http://pygments.org/docs/lexers/>`_ along with `KivyLexer` for\n:mod:`kivy.lang` highlighting.\n\nUsage example\n-------------\n\nTo create a CodeInput with highlighting for `KV language`::\n\n    from kivy.uix.codeinput import CodeInput\n    from kivy.extras.highlight import KivyLexer\n    codeinput = CodeInput(lexer=KivyLexer())\n\nTo create a CodeInput with highlighting for `Cython`::\n\n    from kivy.uix.codeinput import CodeInput\n    from pygments.lexers import CythonLexer\n    codeinput = CodeInput(lexer=CythonLexer())\n\n'''\n\n__all__ = ('CodeInput', )\n\nfrom pygments import highlight\nfrom pygments import lexers\nfrom pygments import styles\nfrom pygments.formatters import BBCodeFormatter\n\nfrom kivy.uix.textinput import TextInput\nfrom kivy.core.text.markup import MarkupLabel as Label\nfrom kivy.cache import Cache\nfrom kivy.properties import ObjectProperty, OptionProperty\nfrom kivy.utils import get_hex_from_color\n\nCache_get = Cache.get\nCache_append = Cache.append\n\n# TODO: color chooser for keywords/strings/...\n\n\nclass CodeInput(TextInput):\n    '''CodeInput class, used for displaying highlighted code.\n    '''\n\n    lexer = ObjectProperty(None)\n    '''This holds the selected Lexer used by pygments to highlight the code.\n\n\n    :attr:`lexer` is an :class:`~kivy.properties.ObjectProperty` and\n    defaults to `PythonLexer`.\n    '''\n\n    style_name = OptionProperty(\n        'default', options=list(styles.get_all_styles())\n    )\n    '''Name of the pygments style to use for formatting.\n\n    :attr:`style_name` is an :class:`~kivy.properties.OptionProperty`\n    and defaults to ``'default'``.\n\n    '''\n\n    style = ObjectProperty(None)\n    '''The pygments style object to use for formatting.\n\n    When ``style_name`` is set, this will be changed to the\n    corresponding style object.\n\n    :attr:`style` is a :class:`~kivy.properties.ObjectProperty` and\n    defaults to ``None``\n\n    '''\n\n    def __init__(self, **kwargs):\n        stylename = kwargs.get('style_name', 'default')\n        style = kwargs['style'] if 'style' in kwargs \\\n            else styles.get_style_by_name(stylename)\n        self.formatter = BBCodeFormatter(style=style)\n        self.lexer = lexers.PythonLexer()\n        self.text_color = '#000000'\n        self._label_cached = Label()\n        self.use_text_color = True\n\n        super(CodeInput, self).__init__(**kwargs)\n\n        self._line_options = kw = self._get_line_options()\n        self._label_cached = Label(**kw)\n        # use text_color as foreground color\n        text_color = kwargs.get('foreground_color')\n        if text_color:\n            self.text_color = get_hex_from_color(text_color)\n        # set foreground to white to allow text colors to show\n        # use text_color as the default color in bbcodes\n        self.use_text_color = False\n        self.foreground_color = [1, 1, 1, .999]\n        if not kwargs.get('background_color'):\n            self.background_color = [.9, .92, .92, 1]\n\n    def on_style_name(self, *args):\n        self.style = styles.get_style_by_name(self.style_name)\n\n    def on_style(self, *args):\n        self.formatter = BBCodeFormatter(style=self.style)\n        self._trigger_update_graphics()\n\n    def _create_line_label(self, text, hint=False):\n        # Create a label from a text, using line options\n        ntext = text.replace(u'\\n', u'').replace(u'\\t', u' ' * self.tab_width)\n        if self.password and not hint:  # Don't replace hint_text with *\n            ntext = u'*' * len(ntext)\n        ntext = self._get_bbcode(ntext)\n        kw = self._get_line_options()\n        cid = u'{}\\0{}\\0{}'.format(ntext, self.password, kw)\n        texture = Cache_get('textinput.label', cid)\n\n        if texture is None:\n            # FIXME right now, we can't render very long line...\n            # if we move on \"VBO\" version as fallback, we won't need to\n            # do this.\n            # try to find the maximum text we can handle\n            label = Label(text=ntext, **kw)\n            if text.find(u'\\n') > 0:\n                label.text = u''\n            else:\n                label.text = ntext\n            label.refresh()\n\n            # ok, we found it.\n            texture = label.texture\n            Cache_append('textinput.label', cid, texture)\n            label.text = ''\n        return texture\n\n    def _get_line_options(self):\n        kw = super(CodeInput, self)._get_line_options()\n        kw['markup'] = True\n        kw['valign'] = 'top'\n        kw['codeinput'] = repr(self.lexer)\n        return kw\n\n    def _get_text_width(self, text, tab_width, _label_cached):\n        # Return the width of a text, according to the current line options.\n        cid = u'{}\\0{}\\0{}'.format(text, self.password,\n                                   self._get_line_options())\n        width = Cache_get('textinput.width', cid)\n        if width is not None:\n            return width\n        lbl = self._create_line_label(text)\n        width = lbl.width\n        Cache_append('textinput.width', cid, width)\n        return width\n\n    def _get_bbcode(self, ntext):\n        # get bbcoded text for python\n        try:\n            ntext[0]\n            # replace brackets with special chars that aren't highlighted\n            # by pygment. can't use &bl; ... cause & is highlighted\n            ntext = ntext.replace(u'[', u'\\x01;').replace(u']', u'\\x02;')\n            ntext = highlight(ntext, self.lexer, self.formatter)\n            ntext = ntext.replace(u'\\x01;', u'&bl;').replace(u'\\x02;', u'&br;')\n            # replace special chars with &bl; and &br;\n            ntext = ''.join((u'[color=', str(self.text_color), u']',\n                             ntext, u'[/color]'))\n            ntext = ntext.replace(u'\\n', u'')\n            return ntext\n        except IndexError:\n            return ''\n\n    # overriden to prevent cursor position off screen\n    def _cursor_offset(self):\n        '''Get the cursor x offset on the current line\n        '''\n        offset = 0\n        try:\n            if self.cursor_col:\n                offset = self._get_text_width(\n                    self._lines[self.cursor_row][:self.cursor_col])\n                return offset\n        except:\n            pass\n        finally:\n            return offset\n\n    def on_lexer(self, instance, value):\n        self._trigger_refresh_text()\n\n    def on_foreground_color(self, instance, text_color):\n        if not self.use_text_color:\n            self.use_text_color = True\n            return\n        self.text_color = get_hex_from_color(text_color)\n        self.use_text_color = False\n        self.foreground_color = (1, 1, 1, .999)\n        self._trigger_refresh_text()\n\n\nif __name__ == '__main__':\n    from kivy.extras.highlight import KivyLexer\n    from kivy.app import App\n\n    class CodeInputTest(App):\n        def build(self):\n            return CodeInput(lexer=KivyLexer(),\n                             font_name='data/fonts/DroidSansMono.ttf',\n                             font_size=12,\n                             text='''\n#:kivy 1.0\n\n<YourWidget>:\n    canvas:\n        Color:\n            rgb: .5, .5, .5\n        Rectangle:\n            pos: self.pos\n            size: self.size''')\n\n    CodeInputTest().run()\n", "path": "kivy/uix/codeinput.py"}], "after_files": [{"content": "'''\nCode Input\n==========\n\n.. versionadded:: 1.5.0\n\n.. image:: images/codeinput.jpg\n\n\nThe :class:`CodeInput` provides a box of editable highlighted text like the one\nshown in the image.\n\nIt supports all the features provided by the :class:`~kivy.uix.textinput` as\nwell as code highlighting for `languages supported by pygments\n<http://pygments.org/docs/lexers/>`_ along with `KivyLexer` for\n:mod:`kivy.lang` highlighting.\n\nUsage example\n-------------\n\nTo create a CodeInput with highlighting for `KV language`::\n\n    from kivy.uix.codeinput import CodeInput\n    from kivy.extras.highlight import KivyLexer\n    codeinput = CodeInput(lexer=KivyLexer())\n\nTo create a CodeInput with highlighting for `Cython`::\n\n    from kivy.uix.codeinput import CodeInput\n    from pygments.lexers import CythonLexer\n    codeinput = CodeInput(lexer=CythonLexer())\n\n'''\n\n__all__ = ('CodeInput', )\n\nfrom pygments import highlight\nfrom pygments import lexers\nfrom pygments import styles\nfrom pygments.formatters import BBCodeFormatter\n\nfrom kivy.uix.textinput import TextInput\nfrom kivy.core.text.markup import MarkupLabel as Label\nfrom kivy.cache import Cache\nfrom kivy.properties import ObjectProperty, OptionProperty\nfrom kivy.utils import get_hex_from_color\n\nCache_get = Cache.get\nCache_append = Cache.append\n\n# TODO: color chooser for keywords/strings/...\n\n\nclass CodeInput(TextInput):\n    '''CodeInput class, used for displaying highlighted code.\n    '''\n\n    lexer = ObjectProperty(None)\n    '''This holds the selected Lexer used by pygments to highlight the code.\n\n\n    :attr:`lexer` is an :class:`~kivy.properties.ObjectProperty` and\n    defaults to `PythonLexer`.\n    '''\n\n    style_name = OptionProperty(\n        'default', options=list(styles.get_all_styles())\n    )\n    '''Name of the pygments style to use for formatting.\n\n    :attr:`style_name` is an :class:`~kivy.properties.OptionProperty`\n    and defaults to ``'default'``.\n\n    '''\n\n    style = ObjectProperty(None)\n    '''The pygments style object to use for formatting.\n\n    When ``style_name`` is set, this will be changed to the\n    corresponding style object.\n\n    :attr:`style` is a :class:`~kivy.properties.ObjectProperty` and\n    defaults to ``None``\n\n    '''\n\n    def __init__(self, **kwargs):\n        stylename = kwargs.get('style_name', 'default')\n        style = kwargs['style'] if 'style' in kwargs \\\n            else styles.get_style_by_name(stylename)\n        self.formatter = BBCodeFormatter(style=style)\n        self.lexer = lexers.PythonLexer()\n        self.text_color = '#000000'\n        self._label_cached = Label()\n        self.use_text_color = True\n\n        super(CodeInput, self).__init__(**kwargs)\n\n        self._line_options = kw = self._get_line_options()\n        self._label_cached = Label(**kw)\n        # use text_color as foreground color\n        text_color = kwargs.get('foreground_color')\n        if text_color:\n            self.text_color = get_hex_from_color(text_color)\n        # set foreground to white to allow text colors to show\n        # use text_color as the default color in bbcodes\n        self.use_text_color = False\n        self.foreground_color = [1, 1, 1, .999]\n        if not kwargs.get('background_color'):\n            self.background_color = [.9, .92, .92, 1]\n\n    def on_style_name(self, *args):\n        self.style = styles.get_style_by_name(self.style_name)\n\n    def on_style(self, *args):\n        self.formatter = BBCodeFormatter(style=self.style)\n        self._trigger_update_graphics()\n\n    def _create_line_label(self, text, hint=False):\n        # Create a label from a text, using line options\n        ntext = text.replace(u'\\n', u'').replace(u'\\t', u' ' * self.tab_width)\n        if self.password and not hint:  # Don't replace hint_text with *\n            ntext = u'*' * len(ntext)\n        ntext = self._get_bbcode(ntext)\n        kw = self._get_line_options()\n        cid = u'{}\\0{}\\0{}'.format(ntext, self.password, kw)\n        texture = Cache_get('textinput.label', cid)\n\n        if texture is None:\n            # FIXME right now, we can't render very long line...\n            # if we move on \"VBO\" version as fallback, we won't need to\n            # do this.\n            # try to find the maximum text we can handle\n            label = Label(text=ntext, **kw)\n            if text.find(u'\\n') > 0:\n                label.text = u''\n            else:\n                label.text = ntext\n            label.refresh()\n\n            # ok, we found it.\n            texture = label.texture\n            Cache_append('textinput.label', cid, texture)\n            label.text = ''\n        return texture\n\n    def _get_line_options(self):\n        kw = super(CodeInput, self)._get_line_options()\n        kw['markup'] = True\n        kw['valign'] = 'top'\n        kw['codeinput'] = repr(self.lexer)\n        return kw\n\n    def _get_text_width(self, text, tab_width, _label_cached):\n        # Return the width of a text, according to the current line options.\n        cid = u'{}\\0{}\\0{}'.format(text, self.password,\n                                   self._get_line_options())\n        width = Cache_get('textinput.width', cid)\n        if width is not None:\n            return width\n        lbl = self._create_line_label(text)\n        width = lbl.width\n        Cache_append('textinput.width', cid, width)\n        return width\n\n    def _get_bbcode(self, ntext):\n        # get bbcoded text for python\n        try:\n            ntext[0]\n            # replace brackets with special chars that aren't highlighted\n            # by pygment. can't use &bl; ... cause & is highlighted\n            ntext = ntext.replace(u'[', u'\\x01').replace(u']', u'\\x02')\n            ntext = highlight(ntext, self.lexer, self.formatter)\n            ntext = ntext.replace(u'\\x01', u'&bl;').replace(u'\\x02', u'&br;')\n            # replace special chars with &bl; and &br;\n            ntext = ''.join((u'[color=', str(self.text_color), u']',\n                             ntext, u'[/color]'))\n            ntext = ntext.replace(u'\\n', u'')\n            return ntext\n        except IndexError:\n            return ''\n\n    # overriden to prevent cursor position off screen\n    def _cursor_offset(self):\n        '''Get the cursor x offset on the current line\n        '''\n        offset = 0\n        try:\n            if self.cursor_col:\n                offset = self._get_text_width(\n                    self._lines[self.cursor_row][:self.cursor_col])\n                return offset\n        except:\n            pass\n        finally:\n            return offset\n\n    def on_lexer(self, instance, value):\n        self._trigger_refresh_text()\n\n    def on_foreground_color(self, instance, text_color):\n        if not self.use_text_color:\n            self.use_text_color = True\n            return\n        self.text_color = get_hex_from_color(text_color)\n        self.use_text_color = False\n        self.foreground_color = (1, 1, 1, .999)\n        self._trigger_refresh_text()\n\n\nif __name__ == '__main__':\n    from kivy.extras.highlight import KivyLexer\n    from kivy.app import App\n\n    class CodeInputTest(App):\n        def build(self):\n            return CodeInput(lexer=KivyLexer(),\n                             font_name='data/fonts/DroidSansMono.ttf',\n                             font_size=12,\n                             text='''\n#:kivy 1.0\n\n<YourWidget>:\n    canvas:\n        Color:\n            rgb: .5, .5, .5\n        Rectangle:\n            pos: self.pos\n            size: self.size''')\n\n    CodeInputTest().run()\n", "path": "kivy/uix/codeinput.py"}]}