Skip to content

Commit

Permalink
resize fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
divi255 committed Aug 21, 2019
1 parent 552cdb8 commit 9d3719a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 42 deletions.
41 changes: 15 additions & 26 deletions pptop/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
__author__ = 'Altertech, https://www.altertech.com/'
__copyright__ = 'Copyright (C) 2019 Altertech'
__license__ = 'MIT'
__version__ = '0.3.12'
__version__ = '0.3.13'

try:
__doc__ = __doc__.format(version=__version__, license=__license__)
Expand Down Expand Up @@ -59,7 +59,7 @@

from pptop.logger import config as log_config, log, log_traceback

from pptop.exceptions import CriticalException, ResizeException
from pptop.exceptions import CriticalException

logging.getLogger('asyncio').setLevel(logging.CRITICAL)
logging.getLogger('atasker/supervisor').setLevel(100)
Expand Down Expand Up @@ -108,9 +108,6 @@
bottom_bar_help = {10: 'Quit'}
plugin_shortcuts = {}

resize_lock = threading.Lock()
resize_event = threading.Event()

plugin_lock = threading.Lock()

socket_timeout = 15
Expand All @@ -126,6 +123,7 @@ def get_plugins():

def init_curses(initial=False):
stdscr = curses.initscr()
resize_handler.start(stdscr=stdscr)
if initial:
if curses.has_colors():
if config['display'].get('colors'):
Expand All @@ -144,6 +142,7 @@ def init_curses(initial=False):

def end_curses(stdscr):
if stdscr:
resize_handler.stop(wait=False)
curses.nocbreak()
stdscr.keypad(False)
curses.echo()
Expand Down Expand Up @@ -476,21 +475,16 @@ def select_process(stdscr):
selector.title = 'Select process'
selector.show()
selector.start()
_d.current_plugin = {'p': selector}
while True:
try:
try:
if resize_event.is_set():
raise ResizeException
k = format_key(stdscr.getkey())
event = get_key_event(k)
except KeyboardInterrupt:
return
except (ResizeException, curses.error):
log('resize event')
with resize_lock:
resize_event.clear()
resize_handler(stdscr)
selector.resize()
except curses.error:
resize_handler.trigger(force=True)
continue
if k == 'q' or event == 'quit':
selector.stop(wait=False)
Expand Down Expand Up @@ -790,18 +784,20 @@ async def calc_bw(**kwargs):


def sigwinch_handler(signum=None, frame=None):
with resize_lock:
resize_event.set()
resize_handler.trigger(force=True)


def resize_handler(stdscr):
@atasker.background_worker(event=True, daemon=True)
async def resize_handler(stdscr, **kwargs):
log('resize event')
# works in 100% cases
width, height = os.get_terminal_size(0)
with scr_lock:
curses.resizeterm(height, width)
stdscr.resize(height, width)
stdscr.clear()
stdscr.refresh()
_d.current_plugin['p'].resize()
show_process_info.trigger()


def find_lib(name):
Expand Down Expand Up @@ -1091,19 +1087,12 @@ def autostart_plugins(stdscr):
while True:
try:
try:
if resize_event.is_set():
raise ResizeException
k = format_key(stdscr.getkey())
event = get_key_event(k)
except KeyboardInterrupt:
return
except (ResizeException, curses.error):
log('resize event')
with resize_lock:
resize_event.clear()
resize_handler(stdscr)
_d.current_plugin['p'].resize()
show_process_info.trigger()
except curses.error:
resize_handler.trigger(force=True)
continue
if show_process_info.is_stopped():
return
Expand Down
5 changes: 0 additions & 5 deletions pptop/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
class ResizeException(Exception):
pass


class CriticalException(Exception):
pass

2 changes: 1 addition & 1 deletion pptop/injection.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
plugins.
'''

__injection_version__ = '0.3.12'
__injection_version__ = '0.3.13'

import threading
import struct
Expand Down
17 changes: 8 additions & 9 deletions pptop/plugin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__author__ = 'Altertech, https://www.altertech.com/'
__copyright__ = 'Copyright (C) 2019 Altertech'
__license__ = 'MIT'
__version__ = '0.3.12'
__version__ = '0.3.13'

import curses
import tabulate
Expand Down Expand Up @@ -536,11 +536,10 @@ def resize(self):
'''
Automatically called on screen resize
'''
with self.scr_lock:
self.init_render_window()
self.print_title()
self.key_event = 'KEY_RESIZE'
self._display()
self.init_render_window()
self.print_title()
self.key_event = 'KEY_RESIZE'
self._display()

def handle_key_event(self, event, key, dtd):
'''
Expand Down Expand Up @@ -823,9 +822,9 @@ def format_row(element=None, raw=None, max_width=0, hshift=0):
raw, color if color else curses.A_NORMAL)
limit -= len(raw)
# if z < len(cols) - 1 and limit > 0:
# spc = spaces if limit > spaces else limit
# self.window.addstr(' ' * spc)
# limit -= spc
# spc = spaces if limit > spaces else limit
# self.window.addstr(' ' * spc)
# limit -= spc
else:
break
else:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.3.12'
__version__ = '0.3.13'

import setuptools

Expand Down

0 comments on commit 9d3719a

Please sign in to comment.