summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--browset.py11
-rw-r--r--gemtext.py19
2 files changed, 18 insertions, 12 deletions
diff --git a/browset.py b/browset.py
index a396768..7ea57c6 100644
--- a/browset.py
+++ b/browset.py
@@ -1,9 +1,9 @@
 from textual.app import App, ComposeResult
-from textual.widgets import Input, Button, Static
+from textual.widgets import Input, Button, Static, Footer
 from textual.containers import Container
 from rich.markdown import Markdown
 from textual.binding import Binding
-
+from gemtext import Gemtext
 
 class Browset(App):
     CSS_PATH = "browset.css"
@@ -11,8 +11,9 @@ class Browset(App):
         Binding("ctrl+c,ctrl+q", "app.quit", "Quit", show=True),
     ]
 
-    content = "## Hello\n* Bullet points\n*OH Yeah!"
+    content = "## Hello\n* Bullet points\n*OH Yeah!\n=>URI some link"
     def compose(self) -> ComposeResult:
+        yield Footer()
         yield Container(
             Button("🔙"), # ⏪
             Button("🔝"), # ⏫
@@ -22,10 +23,10 @@ class Browset(App):
             Input(placeholder="Enter URI"),
             id="toolbar"
         )
-        yield Static(Markdown(self.content), id="content")
+        yield Gemtext(txt=self.content, id="content")
     async def on_input_submitted(self, message: Input.Submitted) -> None:
         self.content = "## new stuff\n"+message.value
-        self.query_one("#content", Static).update(Markdown(self.content))
+        self.query_one("#content", Gemtext).update(self.content)
 
 if __name__ == "__main__":
     app = Browset()
diff --git a/gemtext.py b/gemtext.py
index df8402c..62640a3 100644
--- a/gemtext.py
+++ b/gemtext.py
@@ -5,23 +5,28 @@ from textual.containers import Container
 class Gemtext(Static):
     """Gemtext widget."""
     items = []
-    def compose(self) -> ComposeResult:
-        yield Container(*self.items)
+    #def compose(self) -> ComposeResult:
+    #    yield Container(id="content")
 
-    def __init__(self, txt):
-        super().__init__()
+    def __init__(self, txt, id):
+        super().__init__(id=id)
+        self.update(txt)
+    def update(self, txt):
+        #S = self.query("Static")
+        #if S:
+        #    S.last().remove()
         for line in txt.split('\n'):
             if line.startswith("=>"):
                 path = line[2:].lstrip().split(' ')[0]
                 text = ' '.join(line[2:].lstrip().split(' ')[1:])
-                self.items.append(Button(text or path, name=path))
+                self.mount(Button(text or path, name=path))
             else:
-                self.items.append(Static(line))
+                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")
+            yield Gemtext(txt="#title\n=> /href link text\nworld star hiphop", id="yo")
     app = Test()
     app.run()