@@ -167,12 +167,52 @@ class Statusbar(object):
167
167
The "widget" attribute is an urwid widget.
168
168
"""
169
169
170
- def __init__ (self , config , s = None ):
170
+ def __init__ (self , config , s = None , main_loop = None ):
171
171
self .config = config
172
+ self .timer = None
173
+ self .main_loop = main_loop
172
174
self .s = s or ''
173
175
174
- # XXX wrap in AttrMap for wrapping?
175
176
self .widget = urwid .Text (('main' , self .s ))
177
+ # use wrap mode 'clip' to just cut off at the end of line
178
+ self .widget .set_wrap_mode ('clip' )
179
+
180
+ def _check (self , callback , userdata = None ):
181
+ """This is the method is called from the timer to reset the status bar."""
182
+ self .timer = None
183
+ self .settext (self .s )
184
+
185
+ def message (self , s , n = 3 ):
186
+ """Display a message for a short n seconds on the statusbar and return
187
+ it to its original state."""
188
+
189
+ self .settext (s )
190
+ self .timer = self .main_loop .set_alarm_in (n , self ._check )
191
+
192
+ def prompt (self , s = '' ):
193
+ """Prompt the user for some input (with the optional prompt 's') and
194
+ return the input text, then restore the statusbar to its original
195
+ value."""
196
+
197
+ # TODO
198
+ return ''
199
+
200
+ def settext (self , s , permanent = False ):
201
+ """Set the text on the status bar to a new value. If permanent is True,
202
+ the new value will be permanent."""
203
+
204
+ if self .timer is not None :
205
+ self .main_loop .remove_alarm (self .timer )
206
+ self .timer = None
207
+
208
+ self .widget .set_text (('main' , s ))
209
+ if permanent :
210
+ self .s = s
211
+
212
+ def clear (self ):
213
+ """Clear the status bar."""
214
+ self .settext ('' )
215
+
176
216
177
217
def decoding_input_filter (keys , raw ):
178
218
"""Input filter for urwid which decodes each key with the locale's
@@ -476,6 +516,7 @@ def __init__(self, event_loop, palette, interpreter, config):
476
516
self .frame , palette ,
477
517
event_loop = event_loop , unhandled_input = self .handle_input ,
478
518
input_filter = input_filter , handle_mouse = False )
519
+ self .statusbar .main_loop = self .main_loop
479
520
480
521
self .edits = []
481
522
self .edit = None
0 commit comments