Skip to content

Commit 251c7be

Browse files
authored
Merge pull request dbrgn#37 from The-Compiler/rich
Use rich for nicer tables
2 parents bf05e5e + b49acb1 commit 251c7be

File tree

6 files changed

+23
-12
lines changed

6 files changed

+23
-12
lines changed

Diff for: .coveragerc

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ source = fahrplan
33
omit =
44
*/tests/*
55
*/.tox/*
6-
*/texttable/*
76
setup.py
87
branch = True
98

Diff for: CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ Possible log types:
1515

1616
- ...
1717

18+
## [1.2.0] - 2024-10-16
19+
20+
- [changed] Improve display by using rich instead of texttable
21+
1822
## [1.1.2] - 2019-10-09
1923

2024
- No changes, new release to fix a packaging problem

Diff for: fahrplan/display.py

+15-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
from texttable import Texttable
2+
from rich.table import Table
33

44

55
# Output formats
@@ -14,7 +14,7 @@ def _get_connection_row(i, connection):
1414
"""
1515
sections = connection['sections']
1616
# Create row
17-
row = [i]
17+
row = [str(i)]
1818
for p in [
1919
lambda x: [x['station_from'], x['station_to']], # Station
2020
lambda x: [x.get('platform_from') or '-', x.get('platform_to') or '-'], # Platform
@@ -37,14 +37,20 @@ def connectionsTable(connections, output_format):
3737
"""
3838
Get connections in the given output format.
3939
"""
40-
table = Texttable(max_width=0)
40+
table = Table(show_lines=True)
4141
# Alignments
42-
table.set_cols_valign(['m', 't', 't', 't', 't', 't', 'm', 't', 't'])
43-
table.set_cols_align(['l', 'l', 'c', 'l', 'l', 'c', 'c', 'l', 'l'])
44-
# Header
45-
table.add_row(['#', 'Station', 'Platform', 'Date', 'Time', 'Duration', 'Chg.', 'With', 'Occupancy'])
42+
# Define columns
43+
table.add_column("#", justify="left", vertical="middle")
44+
table.add_column("Station", justify="left", vertical="top")
45+
table.add_column("Platform", justify="center", vertical="top")
46+
table.add_column("Date", justify="left", vertical="top")
47+
table.add_column("Time", justify="left", vertical="top")
48+
table.add_column("Duration", justify="center", vertical="top")
49+
table.add_column("Chg.", justify="center", vertical="middle")
50+
table.add_column("With", justify="left", vertical="top")
51+
table.add_column("Occupancy", justify="left", vertical="top")
4652
# Connection rows
4753
for i, connection in enumerate(connections):
48-
table.add_row(_get_connection_row(i, connection))
54+
table.add_row(*_get_connection_row(i, connection))
4955
# Display
50-
return table.draw()
56+
return table

Diff for: fahrplan/main.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
from .display import Formats, connectionsTable
2828
from .helpers import perror
2929

30+
import rich
31+
3032

3133
def main():
3234
output_format = Formats.SIMPLE
@@ -95,7 +97,7 @@ def main():
9597

9698
# 3. Output data
9799
table = connectionsTable(connections, output_format)
98-
print(table)
100+
rich.print(table)
99101

100102
if __name__ == '__main__':
101103
main()

Diff for: requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
requests>=1,<3
22
python-dateutil>=2.1,<3
3-
texttable>=0.8.6,<2
3+
rich>=13,<14

Diff for: screenshot.png

-145 KB
Loading

0 commit comments

Comments
 (0)