Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

build/
dist/
.idea/
14 changes: 10 additions & 4 deletions pybart/draw.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
from datetime import datetime
from textwrap import TextWrapper

import re

class EstimateDrawer(object):
"""Class for drawing BART estimates on the terminal."""
bart = None
stations = None
window = None
wrapper = None
end_station = None

prev_lines = 0

def __init__(self, bart, stations, window):
def __init__(self, bart, stations, window, end_station):
self.bart = bart
self.stations = stations
self.window = window
self.wrapper = TextWrapper()
self.end_station = end_station

def _format_minutes(self, minutes):
"""Return the minutes estimate formatted with its color."""
Expand Down Expand Up @@ -84,8 +86,12 @@ def draw(self):
for departure in station.iterfind('etd'):
y += 1
destination = departure.find('destination').text
self.window.addstr(y, 0, destination + ' ' * (
self.window.spacing - len(destination)))
if self.end_station and re.match('.*' + self.end_station + '.*', destination, re.I):
self.window.addstr(y, 0, destination + ' ' * (
self.window.spacing - len(destination)), reverse=True)
else:
self.window.addstr(y, 0, destination + ' ' * (
self.window.spacing - len(destination)))
x = self.window.spacing

# Display all estimates for a destination on the same line
Expand Down
5 changes: 4 additions & 1 deletion pybart/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def main():
)
parser.add_argument(
'-v', '--version', action='version', version=pybart.__version__)
parser.add_argument(
'-d', '--direction', type=str, help='highlight the direction in the estimation list')

# Add parsers for sub-commands
subparsers = parser.add_subparsers(title='commands')
Expand Down Expand Up @@ -131,6 +133,7 @@ def display_estimates(args, parser):
# Use the default stations if no arguments were passed in
try:
stations = args.stations
end_station = args.direction
except AttributeError:
stations = settings.BART_STATIONS

Expand All @@ -140,7 +143,7 @@ def display_estimates(args, parser):
exit(1)

with Window(settings.REFRESH_INTERVAL, settings.TOTAL_COLUMNS) as window:
drawer = EstimateDrawer(BART(), stations, window)
drawer = EstimateDrawer(BART(), stations, window, end_station)
char = ''

# Keep running until 'q' is pressed to exit or an error occurs
Expand Down
5 changes: 3 additions & 2 deletions pybart/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,13 @@ def _update_dimensions(self):
_, self.width = self.window.getmaxyx()
self.spacing = self.width // self.total_columns

def addstr(self, y, x, string, color_name='', bold=False):
def addstr(self, y, x, string, color_name='', bold=False, reverse=False):
"""Add a string with optional color and boldness."""
color = self._get_color(color_name)
if bold:
color |= curses.A_BOLD

if reverse:
color |= curses.A_REVERSE
try:
self.window.addstr(y, x, string, color)
except curses.error:
Expand Down