add peak and blinks to goto prompt
parent
e768f2df62
commit
00fc900c2e
|
@ -176,7 +176,7 @@ default_prefs = {
|
||||||
|
|
||||||
bars = {
|
bars = {
|
||||||
"index": "[RET]Open [C]ompose [R]efresh [O]ptions [?]Help [Q]uit",
|
"index": "[RET]Open [C]ompose [R]efresh [O]ptions [?]Help [Q]uit",
|
||||||
"thread": "[C]ompose [RET]Interact [Q]Back [R]efresh [B/T]End [?]Help"
|
"thread": "[C]ompose [RET]Interact [Q]Back [R]efresh [0-9]Goto [B/T]End [?]Help"
|
||||||
}
|
}
|
||||||
|
|
||||||
colormap = [
|
colormap = [
|
||||||
|
@ -698,21 +698,32 @@ class App(object):
|
||||||
size = self.loop.screen_size
|
size = self.loop.screen_size
|
||||||
new_pos = number*5
|
new_pos = number*5
|
||||||
cur_pos = self.box.get_cursor_coords(size)[0]
|
cur_pos = self.box.get_cursor_coords(size)[0]
|
||||||
self.box.change_focus(
|
|
||||||
size, new_pos, coming_from=
|
try:
|
||||||
"below" if (cur_pos < new_pos)
|
self.box.change_focus(
|
||||||
else "above")
|
size, new_pos, coming_from=
|
||||||
|
"below" if (cur_pos < new_pos) else "above")
|
||||||
|
except IndexError:
|
||||||
|
self.temp_footer_message("OUT OF BOUNDS")
|
||||||
|
|
||||||
|
|
||||||
def goto_post_prompt(self, init):
|
def goto_post_prompt(self, init):
|
||||||
|
if self.mode != "thread":
|
||||||
|
return
|
||||||
|
|
||||||
|
count = self.thread["reply_count"]
|
||||||
|
live_display = urwid.Text("")
|
||||||
|
edit = JumpPrompt(count, lambda x: self.goto_post(x))
|
||||||
items = [
|
items = [
|
||||||
urwid.Text(("button", " Jump to post")),
|
urwid.Text(("button", " Jump to post")),
|
||||||
urwid.Text(("bold", ("(max >>%d)" % self.thread["reply_count"]).center(18, " ")))
|
urwid.AttrMap(edit, "opt_prompt"),
|
||||||
|
urwid.Text(("bold", ("(max %d)" % count).center(18, " "))),
|
||||||
|
live_display
|
||||||
]
|
]
|
||||||
|
|
||||||
edit = IntPrompt(lambda x: self.goto_post(x))
|
urwid.connect_signal(edit, "change", self.jump_peek, live_display)
|
||||||
edit.keypress((self.loop.screen_size[0],), init)
|
if init.isdigit():
|
||||||
items.insert(1, urwid.AttrMap(edit, "opt_prompt"))
|
edit.keypress((self.loop.screen_size[0],), init)
|
||||||
|
|
||||||
popup = OptionsMenu(
|
popup = OptionsMenu(
|
||||||
urwid.ListBox(urwid.SimpleFocusListWalker(items)),
|
urwid.ListBox(urwid.SimpleFocusListWalker(items)),
|
||||||
|
@ -725,6 +736,13 @@ class App(object):
|
||||||
width=20, height=6)
|
width=20, height=6)
|
||||||
|
|
||||||
|
|
||||||
|
def jump_peek(self, editor, value, display):
|
||||||
|
if not value:
|
||||||
|
return display.set_text("")
|
||||||
|
msg = self.thread["messages"][int(value)]
|
||||||
|
author = self.usermap[msg["author"]]
|
||||||
|
display.set_text((str(author["color"]), ">>%s %s" % (value, author["user_name"])))
|
||||||
|
|
||||||
|
|
||||||
def set_new_editor(self, button, value, arg):
|
def set_new_editor(self, button, value, arg):
|
||||||
"""
|
"""
|
||||||
|
@ -1277,14 +1295,33 @@ class FootPrompt(Prompt):
|
||||||
app.set_default_footer()
|
app.set_default_footer()
|
||||||
|
|
||||||
|
|
||||||
class IntPrompt(Prompt, urwid.IntEdit):
|
class JumpPrompt(Prompt, urwid.IntEdit):
|
||||||
def __init__(self, callback, *callback_args):
|
def __init__(self, max_length, callback, *callback_args):
|
||||||
super(IntPrompt, self).__init__()
|
super(JumpPrompt, self).__init__()
|
||||||
|
self.max_length = max_length
|
||||||
self.callback = callback
|
self.callback = callback
|
||||||
self.args = callback_args
|
self.args = callback_args
|
||||||
|
|
||||||
|
|
||||||
|
def valid_char(self, char):
|
||||||
|
if not (len(char) == 1 and char in "0123456789"):
|
||||||
|
return False
|
||||||
|
elif int(self.get_edit_text() + char) <= self.max_length:
|
||||||
|
return True
|
||||||
|
try:
|
||||||
|
# flash the display text to indicate bad value
|
||||||
|
text = app.loop.widget.top_w.original_widget.body[2]
|
||||||
|
body = text.get_text()[0]
|
||||||
|
for attr in ("button", "20", "button", "bold"):
|
||||||
|
text.set_text((attr, body))
|
||||||
|
app.loop.draw_screen()
|
||||||
|
sleep(0.05)
|
||||||
|
except: # fuck it who cares
|
||||||
|
pass
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def keypress(self, size, key):
|
def keypress(self, size, key):
|
||||||
super(IntPrompt, self).keypress(size, key)
|
|
||||||
if key == "enter":
|
if key == "enter":
|
||||||
app.remove_overlays()
|
app.remove_overlays()
|
||||||
self.callback(self.value(), *self.args)
|
self.callback(self.value(), *self.args)
|
||||||
|
@ -1292,6 +1329,9 @@ class IntPrompt(Prompt, urwid.IntEdit):
|
||||||
elif key.lower() in ["q", "esc", "ctrl g", "ctrl c"]:
|
elif key.lower() in ["q", "esc", "ctrl g", "ctrl c"]:
|
||||||
app.remove_overlays()
|
app.remove_overlays()
|
||||||
|
|
||||||
|
else: # dont use super because we want to allow zeros in this box
|
||||||
|
urwid.Edit.keypress(self, (size[0],), key)
|
||||||
|
|
||||||
|
|
||||||
class ExternalEditor(urwid.Terminal):
|
class ExternalEditor(urwid.Terminal):
|
||||||
def __init__(self, endpoint, **params):
|
def __init__(self, endpoint, **params):
|
||||||
|
|
Loading…
Reference in New Issue