Skip to content

Commit

Permalink
zauberzeug#288 fix log.push for lines containing line breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Jan 24, 2023
1 parent dfa7929 commit 988285a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion nicegui/elements/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ def __init__(self, max_lines: Optional[int] = None) -> None:
self.lines: deque[str] = deque(maxlen=max_lines)

def push(self, line: str) -> None:
self.lines.append(line)
self.lines.extend(line.splitlines())
self._props['lines'] = '\n'.join(self.lines)
self.run_method('push', line)
17 changes: 13 additions & 4 deletions tests/test_log.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from selenium.webdriver.common.by import By

from nicegui import ui

from .screen import Screen
Expand All @@ -11,7 +13,14 @@ def test_log(screen: Screen):
log.push('D')

screen.open('/')
screen.should_not_contain('A')
screen.should_contain('B')
screen.should_contain('C')
screen.should_contain('D')
assert screen.selenium.find_element(By.ID, log.id).text == 'B\nC\nD'


def test_log_with_newlines(screen: Screen):
log = ui.log(max_lines=3)
log.push('A')
log.push('B')
log.push('C\nD')

screen.open('/')
assert screen.selenium.find_element(By.ID, log.id).text == 'B\nC\nD'

0 comments on commit 988285a

Please sign in to comment.