chiark / gitweb /
Get editor limits from the instance.
authorSimon Tatham <anakin@pobox.com>
Fri, 8 Dec 2023 07:43:55 +0000 (07:43 +0000)
committerSimon Tatham <anakin@pobox.com>
Fri, 8 Dec 2023 07:43:55 +0000 (07:43 +0000)
cursesclient.py

index d2e2a597896b19b35733d152ec41ee76f7fdf151..d684310525cc8c1a4d7da193f0bcb74363d96bbe 100644 (file)
@@ -691,10 +691,9 @@ class Composer:
 
                 pos = mend
 
-        def colourise(self):
+        def colourise(self, char_limit, url_cost):
             self.cs = text.ColouredString("")
             nchars = 0
-            url_cost, char_limit = 23, 500 # FIXME: get this from the instance
             for start, end, desc in self.regions:
                 region_len = end - start
                 if desc == 'u':
@@ -756,8 +755,8 @@ class Composer:
                 y += 1
             return y
 
-        def layout(self, width):
-            self.colourise()
+        def layout(self, width, char_limit, url_cost):
+            self.colourise(char_limit, url_cost)
             self.yx = [None] * (len(self.text) + 1)
             self.yx[0] = 0, 0 # in case there's no text at all
             self.lines = []
@@ -796,6 +795,18 @@ class Composer:
         self.goal_column = None
         self.mode = 'normal'
 
+        instance_data = self.cc.get("instance")
+        try:
+            self.char_limit = instance_data[
+                "configuration"]["statuses"]["max_characters"]
+        except KeyError:
+            self.char_limit = 500
+        try:
+            self.url_cost = instance_data[
+                "configuration"]["statuses"]["characters_reserved_per_url"]
+        except KeyError:
+            self.url_cost = 23
+
     def render(self):
         y = 0
 
@@ -820,7 +831,7 @@ class Composer:
             y += 1
 
         self.dtext = self.DisplayText(self.text)
-        self.dtext.layout(self.cc.scr_w - 1)
+        self.dtext.layout(self.cc.scr_w - 1, self.char_limit, self.url_cost)
 
         ytop = y