forked from ph4r05/ph4-walkingpad
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add option to save records to a file
- Loading branch information
Showing
5 changed files
with
295 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ language: python | |
python: | ||
- "3.6" | ||
- "3.7" | ||
|
||
install: | ||
- pip install . | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
|
||
# Some sources inspired by: | ||
# Copyright (c) 2016-present Valentin Kazakov | ||
# | ||
# This module is part of asyncpg and is released under | ||
# the Apache 2.0 License: http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# This lib is inspired by Cmd standard lib Python >3.5 (under Python Software | ||
# Foundation License 2) | ||
|
||
import asyncio | ||
import logging | ||
|
||
import ph4acmd2 | ||
from blessed import Terminal | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Ph4Cmd(ph4acmd2.Cmd): | ||
prompt = "$> " | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(allow_cli_args=False, **kwargs) | ||
|
||
self.t = Terminal() | ||
self.worker_loop = None | ||
self.cmd_running = True | ||
|
||
def looper(self, loop): | ||
logger.debug('Starting looper for loop %s' % (loop,)) | ||
asyncio.set_event_loop(loop) | ||
loop.run_forever() | ||
|
||
def submit_coro(self, coro, loop=None): | ||
return asyncio.run_coroutine_threadsafe(coro, loop or self.worker_loop) | ||
|
||
def wait_coro(self, coro, loop=None): | ||
future = self.submit_coro(coro, loop=loop) | ||
return future.result() | ||
|
||
def get_term_width(self): | ||
try: | ||
width = self.t.width | ||
if width is None or width <= 0: | ||
return 80 | ||
return width | ||
except: | ||
pass | ||
return 80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.