(really rough) thread reply windows
parent
bbc213f0fe
commit
b6e5ad80e9
|
@ -111,6 +111,25 @@ class App(object):
|
||||||
self.loop.widget.footer = urwid.AttrMap(urwid.Text(text), "bar")
|
self.loop.widget.footer = urwid.AttrMap(urwid.Text(text), "bar")
|
||||||
|
|
||||||
|
|
||||||
|
def close_editor(self):
|
||||||
|
if self.window_split:
|
||||||
|
self.window_split = False
|
||||||
|
self.loop.widget.focus_position = "body"
|
||||||
|
self.set_footer("lmao")
|
||||||
|
else:
|
||||||
|
self.loop.widget = self.loop.widget[0]
|
||||||
|
|
||||||
|
|
||||||
|
def switch_editor(self):
|
||||||
|
if not self.window_split:
|
||||||
|
return
|
||||||
|
elif self.loop.widget.focus_position == "body":
|
||||||
|
self.loop.widget.focus_position = "footer"
|
||||||
|
else:
|
||||||
|
self.loop.widget.focus_position = "body"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def readable_delta(self, modified):
|
def readable_delta(self, modified):
|
||||||
"""
|
"""
|
||||||
Return a human-readable string representing the difference
|
Return a human-readable string representing the difference
|
||||||
|
@ -241,6 +260,7 @@ class App(object):
|
||||||
|
|
||||||
|
|
||||||
def compose(self, title=None):
|
def compose(self, title=None):
|
||||||
|
editor = ExternalEditor if self.prefs["editor"] else InternalEditor
|
||||||
if self.mode == "index":
|
if self.mode == "index":
|
||||||
if not title:
|
if not title:
|
||||||
return self.footer_prompt("Title", self.compose)
|
return self.footer_prompt("Title", self.compose)
|
||||||
|
@ -250,24 +270,32 @@ class App(object):
|
||||||
return self.footer_prompt(
|
return self.footer_prompt(
|
||||||
"Title", self.compose, extra_text=e.description)
|
"Title", self.compose, extra_text=e.description)
|
||||||
|
|
||||||
if self.prefs["editor"]:
|
|
||||||
editor = ExternalEditor("thread_create", title=title)
|
|
||||||
footer = "[F1]Abort [Save and quit to submit your thread]"
|
|
||||||
else:
|
|
||||||
editor = urwid.Edit()
|
|
||||||
|
|
||||||
self.set_header('Composing "{}"', title)
|
self.set_header('Composing "{}"', title)
|
||||||
self.set_footer(static_string=
|
self.set_footer(static_string=
|
||||||
"[F1]Abort [Save and quit to submit your thread]")
|
"[F1]Abort [Save and quit to submit your thread]")
|
||||||
|
|
||||||
self.loop.widget = urwid.Overlay(
|
self.loop.widget = urwid.Overlay(
|
||||||
urwid.LineBox(editor, title=self.prefs["editor"]),
|
urwid.LineBox(
|
||||||
self.loop.widget,
|
editor("thread_create", title=title),
|
||||||
align="center",
|
title=self.prefs["editor"]),
|
||||||
|
self.loop.widget, align="center", valign="middle",
|
||||||
width=self.loop.screen_size[0] - 2,
|
width=self.loop.screen_size[0] - 2,
|
||||||
valign="middle",
|
|
||||||
height=(self.loop.screen_size[1] - 4))
|
height=(self.loop.screen_size[1] - 4))
|
||||||
|
|
||||||
|
elif self.mode == "thread":
|
||||||
|
self.window_split=True
|
||||||
|
self.set_header('Replying to "{}"', self.thread["title"])
|
||||||
|
self.loop.widget.footer = urwid.BoxAdapter(
|
||||||
|
urwid.Frame(
|
||||||
|
urwid.LineBox(editor("thread_reply", thread_id=self.thread["thread_id"])),
|
||||||
|
footer=urwid.AttrMap(urwid.Text("[F1]Abort [F2]Swap [F3]Send"), "bar")
|
||||||
|
)
|
||||||
|
,
|
||||||
|
20)
|
||||||
|
self.switch_editor()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class MessageBody(urwid.Text):
|
class MessageBody(urwid.Text):
|
||||||
|
@ -289,6 +317,21 @@ class FootPrompt(urwid.Edit):
|
||||||
self.callback(self.get_edit_text(), *self.args)
|
self.callback(self.get_edit_text(), *self.args)
|
||||||
|
|
||||||
|
|
||||||
|
class InternalEditor(urwid.Edit):
|
||||||
|
def __init__(self, endpoint, **params):
|
||||||
|
super(InternalEditor, self).__init__()
|
||||||
|
self.endpoint = endpoint
|
||||||
|
self.params = params
|
||||||
|
|
||||||
|
def keypress(self, size, key):
|
||||||
|
if key not in ["f1", "f2"]:
|
||||||
|
return super(InternalEditor, self).keypress(size, key)
|
||||||
|
elif key == "f1":
|
||||||
|
return app.close_editor()
|
||||||
|
elif key == "f2":
|
||||||
|
return app.switch_editor()
|
||||||
|
|
||||||
|
|
||||||
class ExternalEditor(urwid.Terminal):
|
class ExternalEditor(urwid.Terminal):
|
||||||
def __init__(self, endpoint, **params):
|
def __init__(self, endpoint, **params):
|
||||||
self.file_descriptor, self.path = tempfile.mkstemp()
|
self.file_descriptor, self.path = tempfile.mkstemp()
|
||||||
|
@ -303,30 +346,20 @@ class ExternalEditor(urwid.Terminal):
|
||||||
|
|
||||||
def keypress(self, size, key):
|
def keypress(self, size, key):
|
||||||
if self.terminated:
|
if self.terminated:
|
||||||
if app.window_split:
|
app.close_editor()
|
||||||
app.window_split = False
|
|
||||||
app.loop.widget.focus_position = "body"
|
|
||||||
app.set_footer("this")
|
|
||||||
else:
|
|
||||||
app.loop.widget = app.loop.widget[0]
|
|
||||||
with open(self.file_descriptor) as _:
|
with open(self.file_descriptor) as _:
|
||||||
self.params.update({"body": _.read()})
|
self.params.update({"body": _.read()})
|
||||||
network.request(self.endpoint, **self.params)
|
network.request(self.endpoint, **self.params)
|
||||||
os.remove(self.path)
|
os.remove(self.path)
|
||||||
return app.refresh()
|
return app.refresh()
|
||||||
|
|
||||||
elif key != "f1":
|
elif key not in ["f1", "f2"]:
|
||||||
return super(ExternalEditor, self).keypress(size, key)
|
return super(ExternalEditor, self).keypress(size, key)
|
||||||
|
elif key == "f1":
|
||||||
if app.window_split:
|
self.terminate()
|
||||||
app.loop.widget.focus_position = "body"
|
app.close_editor()
|
||||||
return app.loop.widget.footer.set_title(
|
app.refresh()
|
||||||
"press f1 to return to the editor")
|
app.switch_editor()
|
||||||
|
|
||||||
self.terminate()
|
|
||||||
app.loop.widget = app.loop.widget[0]
|
|
||||||
app.refresh()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ActionBox(urwid.ListBox):
|
class ActionBox(urwid.ListBox):
|
||||||
|
@ -336,9 +369,8 @@ class ActionBox(urwid.ListBox):
|
||||||
def keypress(self, size, key):
|
def keypress(self, size, key):
|
||||||
super(ActionBox, self).keypress(size, key)
|
super(ActionBox, self).keypress(size, key)
|
||||||
|
|
||||||
if key == "f1" and app.window_split:
|
if key == "f2":
|
||||||
app.loop.widget.focus_position = "footer"
|
app.switch_editor()
|
||||||
app.loop.widget.footer.set_title("press F1 to focus the thread")
|
|
||||||
|
|
||||||
elif key in ["j", "n", "ctrl n"]:
|
elif key in ["j", "n", "ctrl n"]:
|
||||||
self._keypress_down(size)
|
self._keypress_down(size)
|
||||||
|
@ -374,24 +406,32 @@ class ActionBox(urwid.ListBox):
|
||||||
|
|
||||||
elif key.lower() == "q":
|
elif key.lower() == "q":
|
||||||
if app.mode == "index":
|
if app.mode == "index":
|
||||||
app.loop.stop()
|
frilly_exit()
|
||||||
if app.prefs["dramatic_exit"]:
|
|
||||||
width, height = app.loop.screen_size
|
|
||||||
for x in range(height - 1):
|
|
||||||
motherfucking_rainbows(
|
|
||||||
"".join([choice([" ", choice(punctuation)])
|
|
||||||
for x in range(width)]
|
|
||||||
))
|
|
||||||
out = " ~~CoMeE BaCkK SooOn~~ 0000000"
|
|
||||||
motherfucking_rainbows(out.zfill(width))
|
|
||||||
else:
|
|
||||||
run("clear", shell=True)
|
|
||||||
motherfucking_rainbows("Come back soon! <3")
|
|
||||||
exit()
|
|
||||||
else:
|
else:
|
||||||
app.back()
|
app.back()
|
||||||
|
|
||||||
|
|
||||||
|
def frilly_exit():
|
||||||
|
"""
|
||||||
|
Exit with some flair. Will fill the screen with rainbows
|
||||||
|
and shit, or just say bye, depending on the user's bbjrc
|
||||||
|
setting, `dramatic_exit`
|
||||||
|
"""
|
||||||
|
app.loop.stop()
|
||||||
|
if app.prefs["dramatic_exit"]:
|
||||||
|
width, height = app.loop.screen_size
|
||||||
|
for x in range(height - 1):
|
||||||
|
motherfucking_rainbows(
|
||||||
|
"".join([choice([" ", choice(punctuation)])
|
||||||
|
for x in range(width)]
|
||||||
|
))
|
||||||
|
out = " ~~CoMeE BaCkK SooOn~~ 0000000"
|
||||||
|
motherfucking_rainbows(out.zfill(width))
|
||||||
|
else:
|
||||||
|
run("clear", shell=True)
|
||||||
|
motherfucking_rainbows("Come back soon! <3")
|
||||||
|
exit()
|
||||||
|
|
||||||
|
|
||||||
def cute_button(label, callback=None, data=None):
|
def cute_button(label, callback=None, data=None):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue