Skip to content

Commit

Permalink
Added update_terminal_display() NCurses terminal logging mechanisms
Browse files Browse the repository at this point in the history
  • Loading branch information
jamestaylr committed Aug 25, 2015
1 parent 7d9ba16 commit 591bd26
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/modules/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

logger = logging.getLogger('log')

def setup_logging():
def setup_logging(*positional_parameters, **keyword_parameters):
logger.setLevel(logging.DEBUG)

log_path = r'logs/'
log_path = r'logs/' + time.strftime("%Y-%m-%d %H-%M-%S") + '/'
if not os.path.exists(log_path): os.makedirs(log_path)

if ('name' in keyword_parameters):
Expand All @@ -27,7 +27,10 @@ def setup_logging():

logger.addHandler(file_handler)

panel = None
def setup_terminal_logging():
logger.setLevel(logging.DEBUG)
global panel
screen = curses.initscr()
screen.nodelay(1)
screen.border(0)
Expand All @@ -38,8 +41,11 @@ def setup_terminal_logging():
# height, width, begin_y, begin_x
window = curses.newwin(height, maxx-4, maxy-(height + 1), 2)

panel = curses.newwin(25, maxx-4, 2, 2)
panel.refresh()

curses.setsyx(-1, -1)
screen.addstr(1,2, "SailBOT")

screen.refresh()
window.refresh()
window.scrollok(True)
Expand All @@ -51,6 +57,20 @@ def setup_terminal_logging():
terminal_handler.setFormatter(formatterDisplay)
logger.addHandler(terminal_handler)

def update_terminal_display(data, values):
global panel

panel.addstr(0, 0, "SailBOT Terminal Display", curses.A_BOLD)
panel.addstr(2, 0, "location: " + str(data['location']))
panel.refresh()

for k, j in enumerate([data, values]):
for index, (key, value) in enumerate(j.items()):
if "location" in key:
continue
panel.addstr(index + 4, k * 45, str(key) + ": " + str(value))
panel.refresh()

def shutdown_terminal():
curses.curs_set(1)
curses.nocbreak()
Expand All @@ -65,7 +85,6 @@ def setup_locations(target_locations, boundary_locations):
with open('locations.json', 'r') as myfile:
json_data = json.loads(myfile.read().replace('\n', ''))


for location in json_data['target_locations']:
target_locations.append({"latitude": location["latitude"], "longitude": location["longitude"]})
for location in json_data['boundary_locations']:
Expand Down

0 comments on commit 591bd26

Please sign in to comment.