Open Carreau opened 9 years ago
from prompt_toolkit.layout import Float from prompt_toolkit.formatted_text import HTML
class Cursor: instance = None
def __new__(cls):
if cls.instance is None:
cls.instance = super(Cursor, cls).__new__(cls)
return cls.instance
def __add__(self, value):
return self
def __sub__(self, value):
return self
cursor = Cursor()
def write_to_screen(text, cursor_pos, color): return [ Float( top=cursor_pos, left=cursor_pos, content=HTML(text), background_color=color, ) ]
layout = write_to_screen("Hello", cursor + 1, "red") + write_to_screen("World", cursor - 3, "blue")
I think I understand the usage of
(x|y)cursor
in Float that are after used here inwrite_to_screen
, do you think it could be a better/simpler idea to have a singletoncursor_pos = object()
(or even a specific string"cursor"
) that could could be use forFloat
s top/left/bottom/right arguments ?The advantage of the
Cursor
singleton object is you could implement__add__/__sub__
dunder,And do things like:
Thoughts?