From: Simon Tatham Date: Fri, 8 Dec 2023 07:43:55 +0000 (+0000) Subject: Get editor limits from the instance. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=5c0b9a90b8180e2051600b30b49c5be3f5ce950a;p=mastodonochrome.git Get editor limits from the instance. --- diff --git a/cursesclient.py b/cursesclient.py index d2e2a59..d684310 100644 --- a/cursesclient.py +++ b/cursesclient.py @@ -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