Skip to content

Commit c53cf2a

Browse files
Temp status bar things messages clear automatically
requires master curtsies TODO use a different event type - this kind of scheduled refresh is really different than "I need a refresh so I can keep doing my thing"
1 parent 5138dce commit c53cf2a

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

bpython/curtsies.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from __future__ import absolute_import
22

3-
import sys
43
import code
54
import logging
5+
import sys
6+
import time
67
from subprocess import Popen, PIPE
78
from optparse import Option
89
from itertools import izip
@@ -79,8 +80,8 @@ def mainloop(config, locals_, banner, interp=None, paste=None, interactive=True)
7980
def request_reload(desc):
8081
reload_requests.append(curtsies.events.ReloadEvent([desc]))
8182
refresh_requests = []
82-
def request_refresh():
83-
refresh_requests.append(curtsies.events.RefreshRequestEvent())
83+
def request_refresh(when='now'):
84+
refresh_requests.append(curtsies.events.RefreshRequestEvent(when=when))
8485

8586
watcher = wdtest.ModuleChangedEventHandler([], request_reload)
8687

@@ -95,17 +96,17 @@ def new_import(name, globals={}, locals={}, fromlist=[], level=-1):
9596

9697
def event_or_refresh(timeout=None):
9798
while True:
98-
if refresh_requests:
99-
yield refresh_requests.pop()
100-
else:
101-
while True:
102-
if reload_requests:
103-
e = reload_requests.pop()
104-
else:
105-
e = input_generator.send(.2)
106-
if e is not None:
107-
break
99+
t = time.time()
100+
refresh_requests.sort(key=lambda r: 0 if r.when == 'now' else r.when)
101+
if refresh_requests and (refresh_requests[0].when == 'now' or refresh_requests[-1].when < t):
102+
yield refresh_requests.pop(0)
103+
elif reload_requests:
104+
e = reload_requests.pop()
108105
yield e
106+
else:
107+
e = input_generator.send(.2)
108+
if e is not None:
109+
yield e
109110

110111
global repl # global for easy introspection `from bpython.curtsies import repl`
111112
with Repl(config=config,

bpython/curtsiesfrontend/interaction.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def has_focus(self):
4141
def message(self, msg):
4242
self.message_start_time = time.time()
4343
self._message = msg
44+
self.refresh_request(time.time() + self.message_time)
4445

4546
def _check_for_expired_message(self):
4647
if self._message and time.time() > self.message_start_time + self.message_time:

bpython/curtsiesfrontend/repl.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ def __init__(self, locals_=None, config=None,
183183
config is a bpython config.Struct with config attributes
184184
request_refresh is a function that will be called when the Repl
185185
wants to refresh the display, but wants control returned to it afterwards
186+
Takes as a kwarg when= which is when to fire
186187
get_term_hw is a function that returns the current width and height
187188
of the terminal
188189
get_cursor_vertical_diff is a function that returns how the cursor moved
@@ -210,11 +211,11 @@ def __init__(self, locals_=None, config=None,
210211

211212
self.reevaluating = False
212213
self.fake_refresh_requested = False
213-
def smarter_request_refresh():
214+
def smarter_request_refresh(when='now'):
214215
if self.reevaluating or self.paste_mode:
215216
self.fake_refresh_requested = True
216217
else:
217-
request_refresh()
218+
request_refresh(when=when)
218219
self.request_refresh = smarter_request_refresh
219220
self.get_term_hw = get_term_hw
220221
self.get_cursor_vertical_diff = get_cursor_vertical_diff
@@ -328,7 +329,9 @@ def process_event(self, e):
328329

329330
logger.debug("processing event %r", e)
330331
if isinstance(e, events.RefreshRequestEvent):
331-
if self.status_bar.has_focus:
332+
if e.when != 'now':
333+
pass # This is a scheduled refresh - it's really just a refresh (so nop)
334+
elif self.status_bar.has_focus:
332335
self.status_bar.process_event(e)
333336
else:
334337
assert self.coderunner.code_is_waiting

0 commit comments

Comments
 (0)