diff --git a/.coveragerc b/.coveragerc index da3d11d..0787932 100644 --- a/.coveragerc +++ b/.coveragerc @@ -3,7 +3,6 @@ source = fahrplan omit = */tests/* */.tox/* - */texttable/* setup.py branch = True diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e11ab0..c7b4942 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ Possible log types: - ... +## [1.2.0] - 2024-10-16 + + - [changed] Improve display by using rich instead of texttable + ## [1.1.2] - 2019-10-09 - No changes, new release to fix a packaging problem diff --git a/fahrplan/display.py b/fahrplan/display.py index 5955b05..8d9491d 100644 --- a/fahrplan/display.py +++ b/fahrplan/display.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from texttable import Texttable +from rich.table import Table # Output formats @@ -14,7 +14,7 @@ def _get_connection_row(i, connection): """ sections = connection['sections'] # Create row - row = [i] + row = [str(i)] for p in [ lambda x: [x['station_from'], x['station_to']], # Station lambda x: [x.get('platform_from') or '-', x.get('platform_to') or '-'], # Platform @@ -37,14 +37,20 @@ def connectionsTable(connections, output_format): """ Get connections in the given output format. """ - table = Texttable(max_width=0) + table = Table(show_lines=True) # Alignments - table.set_cols_valign(['m', 't', 't', 't', 't', 't', 'm', 't', 't']) - table.set_cols_align(['l', 'l', 'c', 'l', 'l', 'c', 'c', 'l', 'l']) - # Header - table.add_row(['#', 'Station', 'Platform', 'Date', 'Time', 'Duration', 'Chg.', 'With', 'Occupancy']) + # Define columns + table.add_column("#", justify="left", vertical="middle") + table.add_column("Station", justify="left", vertical="top") + table.add_column("Platform", justify="center", vertical="top") + table.add_column("Date", justify="left", vertical="top") + table.add_column("Time", justify="left", vertical="top") + table.add_column("Duration", justify="center", vertical="top") + table.add_column("Chg.", justify="center", vertical="middle") + table.add_column("With", justify="left", vertical="top") + table.add_column("Occupancy", justify="left", vertical="top") # Connection rows for i, connection in enumerate(connections): - table.add_row(_get_connection_row(i, connection)) + table.add_row(*_get_connection_row(i, connection)) # Display - return table.draw() + return table diff --git a/fahrplan/main.py b/fahrplan/main.py index 2e6c095..a26a9a7 100755 --- a/fahrplan/main.py +++ b/fahrplan/main.py @@ -27,6 +27,8 @@ from .display import Formats, connectionsTable from .helpers import perror +import rich + def main(): output_format = Formats.SIMPLE @@ -95,7 +97,7 @@ def main(): # 3. Output data table = connectionsTable(connections, output_format) - print(table) + rich.print(table) if __name__ == '__main__': main() diff --git a/requirements.txt b/requirements.txt index b3675ce..53d1025 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ requests>=1,<3 python-dateutil>=2.1,<3 -texttable>=0.8.6,<2 +rich>=13,<14 diff --git a/screenshot.png b/screenshot.png index 4bf86aa..4438d5b 100644 Binary files a/screenshot.png and b/screenshot.png differ