from textual.widgets import Button, Static
from textual.app import ComposeResult
from textual.containers import Container
class Gemtext(Static):
"""Gemtext widget."""
def __init__(self, fp, id):
super().__init__(id=id)
self.addlines(fp)
def addlines(self, fp):
for line in fp:
if type(line) is bytes:
line = line.decode("UTF-8")
if line.startswith("=>"):
path = line[2:].lstrip().split(' ')[0]
text = ' '.join(line[2:].lstrip().split(' ')[1:])
self.mount(Button(text or path, name=path))
else:
self.mount(Static(line))
if __name__ == "__main__":
from textual.app import App
class Test(App):
def compose(self) -> ComposeResult:
yield Gemtext(txt="#title\n=> /href link text\nworld star hiphop", id="yo")
app = Test()
app.run()