Skip to content

Commit

Permalink
Fixed rendering issue when using percent sign (%%)
Browse files Browse the repository at this point in the history
  • Loading branch information
dholm committed Feb 23, 2013
1 parent 46c39e8 commit 1b311ae
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ if __name__ == '__main__':

## Changelog

### 0.2.1
- Fixes invalid length calculation when using AnsiTerminal
- Fixes issue when writing percent sign (%%)

### 0.2.0
- Defines a domain-specific language for themes.
- Breaks Python 3000 support in this release.
Expand Down
9 changes: 5 additions & 4 deletions flowui/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,19 @@ def _filter_string(self, string):
string = string.expandtabs()
if string[-1] == '\n':
string = string[:-1] + ('%s\n' % self._sgr(0))
return string
return ''.join(['%(face-normal)s', string])

def _fmt_string(self, string, dictionary=None):
d = self._faces
if dictionary:
d.update(dictionary)
return string % d
return self._filter_string(string) % d

def len(self, string, dictionary=None):
filtered = self._fmt_string(self._filter_string(string), dictionary)
filtered = self._fmt_string(string, dictionary)
return len(self._ansi_escape_expression.sub('', filtered))

def write(self, string, dictionary=None):
'''Apply theme formatting and return the resulting string'''
self._terminal.write(self._fmt_string(string, dictionary))
filtered = self._fmt_string(string, dictionary)
self._terminal.write(filtered)
1 change: 0 additions & 1 deletion flowui/widgets/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ def _draw_rows(self, terminal, width):
def draw(self, terminal, width):
'''Draw the table on the specified terminal constrained to the
specified width'''
terminal.write('%(face-normal)s')
if self._rows:
self._draw_rows(terminal, width)
if self._cells:
Expand Down
2 changes: 2 additions & 0 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
def suite():
loader = unittest.TestLoader()
test_suite = unittest.TestSuite()
test_suite.addTests(loader.loadTestsFromModule(tests.terminals))
test_suite.addTests(loader.loadTestsFromModule(tests.themes))
test_suite.addTests(loader.loadTestsFromModule(tests.widgets))
return test_suite


def run_tests():
s = suite()
runner = unittest.TextTestRunner(verbosity=2)
Expand Down
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from tests.terminals import SysTerminalTest
from tests.themes import SolarizedTest, ZenburnTest
from tests.widgets import WidgetsTest
44 changes: 44 additions & 0 deletions tests/terminals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# FlowUI terminals unit tests
#
# Copyright (c) 2012-2013, David Holm <dholmster@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the author of FlowUI nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL DAVID HOLM BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from unittest import TestCase

from flowui.terminals import SysTerminal


class SysTerminalTest(TestCase):
def setUp(self):
self._terminal = SysTerminal()

def tearDown(self):
self._terminal.reset()

def test_percent(self):
self._terminal.write('Unformatted: %%\n')

def test_write(self):
self._terminal.write('Test\n')
3 changes: 3 additions & 0 deletions tests/themes.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def setUp(self, terminal, theme):
def tearDown(self):
self._terminal.reset()

def test_percent(self):
self._terminal.write('Unformatted: %%\n')

def test_faces(self):
self._terminal.reset()
for name in self._theme.faces.keys():
Expand Down

0 comments on commit 1b311ae

Please sign in to comment.