Repos / mcross / dd33400ce9
commit dd33400ce9502f95047782b5f626404b5c80e800
Author: Bùi Thành Nhân <hi@imnhan.com>
Date:   Sun May 17 13:17:25 2020 +0700

    ctrl+a to select all

diff --git a/README.md b/README.md
index 558be81..41f4426 100644
--- a/README.md
+++ b/README.md
@@ -1,11 +1,13 @@
-McRoss is a WIP [gemini://](https://gemini.circumlunar.space/) browser
-written in python and tkinter, meaning it Just Works (tm) on any
-self-respecting desktop OS: Linux, Windows, Mac OS, maaaaybe the BSDs?
+McRoss is a minimal and usable [gemini://](https://gemini.circumlunar.space/)
+browser written in python and tkinter, meaning it Just Works (tm) on any
+self-respecting desktop OS: Linux, Windows, Mac OS, and maybe the BSDs?
 Never tried one of those.
 
 It currently looks like this:
 
-![](https://p.caophim.net/87.png)
+![](https://junk.imnhan.com/mcross.png)
+
+Or check out the demo video: https://junk.imnhan.com/mcross.mp4
 
 Surfing plaintext and gemini content is already working well.
 See feature checklist below for more details.
@@ -29,6 +31,7 @@ # Development
 - python3.7+
 - idlelib (it's supposed to be in the standard lib but Ubuntu for example
   splits it into a separate package)
+- curio - for async I/O so that it doesn't block the UI.
 
 To get started:
 
diff --git a/pyproject.toml b/pyproject.toml
index 7899a5f..2d8ebf7 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
 [tool.poetry]
 name = "mcross"
-version = "0.5.1"
+version = "0.5.2"
 description = "Do you remember www?"
 authors = ["nhanb <hi@imnhan.com>"]
 license = "MIT"
diff --git a/src/mcross/gui/view.py b/src/mcross/gui/view.py
index 6fae076..0eab0db 100644
--- a/src/mcross/gui/view.py
+++ b/src/mcross/gui/view.py
@@ -13,7 +13,7 @@
     TextNode,
 )
 from .model import Model
-from .widgets import ReadOnlyText
+from .widgets import McEntry, ReadOnlyText
 
 # OS-specific values
 if sys.platform == "win32":
@@ -106,7 +106,7 @@ def __init__(self, root: Tk, model: Model):
         address_prefix.pack(side="left")
 
         # Address bar
-        address_bar = ttk.Entry(row1)
+        address_bar = McEntry(row1)
         self.address_bar = address_bar
         address_bar.pack(side="left", fill="both", expand=True, padx=3, pady=3)
         address_bar.bind("<Return>", self._on_go)
@@ -211,6 +211,8 @@ def render_page(self):
         else:
             for node in self.model.gemini_nodes:
                 render_node(node, self.text)
+            # delete final trailing newline:
+            self.text.delete("insert-1c", "insert")
 
 
 def render_node(node: GeminiNode, widget: Text):
diff --git a/src/mcross/gui/widgets.py b/src/mcross/gui/widgets.py
index c9a8b5a..e5d63b8 100644
--- a/src/mcross/gui/widgets.py
+++ b/src/mcross/gui/widgets.py
@@ -1,5 +1,5 @@
 from idlelib.redirector import WidgetRedirector
-from tkinter import Text
+from tkinter import Text, ttk
 
 
 # Can't just use a Text widget with state='disabled' because that would
@@ -8,7 +8,29 @@
 # https://wiki.tcl-lang.org/page/Read%2Donly+text+widget
 class ReadOnlyText(Text):
     def __init__(self, *args, **kwargs):
-        Text.__init__(self, *args, **kwargs)
+        super().__init__(*args, **kwargs)
         self.redirector = WidgetRedirector(self)
         self.insert = self.redirector.register("insert", lambda *args, **kw: "break")
         self.delete = self.redirector.register("delete", lambda *args, **kw: "break")
+
+        self.bind("<Control-a>", self._on_ctrl_a)
+
+    def _on_ctrl_a(self, ev):
+        self.tag_add("sel", "1.0", "end")
+        return "break"
+
+
+class McEntry(ttk.Entry):
+    """
+    Entry widget with reasonable defaults
+    """
+
+    def __init__(self, *args, **kwargs):
+        super().__init__(*args, **kwargs)
+
+        self.bind("<Control-a>", self._on_ctrl_a)
+
+    def _on_ctrl_a(self, ev):
+        self.select_range(0, "end")
+        self.icursor("end")
+        return "break"