summaryrefslogtreecommitdiff
path: root/src/windows/funcs.py
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2014-05-05 23:16:33 +0200
committermathieui <mathieui@mathieui.net>2014-05-05 23:16:33 +0200
commit2f629ee68675c097bf8c8d80f8a2712e6518d1b0 (patch)
treed3d3a8fdff41a0ec6f9c8d976fea760df6fb4df8 /src/windows/funcs.py
parent109e86cbabf6b294b6b7235dee2aeb8afd582459 (diff)
downloadpoezio-2f629ee68675c097bf8c8d80f8a2712e6518d1b0.tar.gz
poezio-2f629ee68675c097bf8c8d80f8a2712e6518d1b0.tar.bz2
poezio-2f629ee68675c097bf8c8d80f8a2712e6518d1b0.tar.xz
poezio-2f629ee68675c097bf8c8d80f8a2712e6518d1b0.zip
Split the windows.py module into a subdirectory
Diffstat (limited to 'src/windows/funcs.py')
-rw-r--r--src/windows/funcs.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/windows/funcs.py b/src/windows/funcs.py
new file mode 100644
index 00000000..47011faf
--- /dev/null
+++ b/src/windows/funcs.py
@@ -0,0 +1,56 @@
+"""
+Standalone functions used by the modules
+"""
+
+import string
+
+from config import config
+from . base_wins import FORMAT_CHAR, format_chars
+
+def find_first_format_char(text, chars=None):
+ if chars is None:
+ chars = format_chars
+ pos = -1
+ for char in chars:
+ p = text.find(char)
+ if p == -1:
+ continue
+ if pos == -1 or p < pos:
+ pos = p
+ return pos
+
+def truncate_nick(nick, size=None):
+ size = size or config.get('max_nick_length', 25)
+ if size < 1:
+ size = 1
+ if nick and len(nick) > size:
+ return nick[:size]+'…'
+ return nick
+
+def parse_attrs(text, previous=None):
+ next_attr_char = text.find(FORMAT_CHAR)
+ if previous:
+ attrs = previous
+ else:
+ attrs = []
+ while next_attr_char != -1 and text:
+ if next_attr_char + 1 < len(text):
+ attr_char = text[next_attr_char+1].lower()
+ else:
+ attr_char = str()
+ if attr_char == 'o':
+ attrs = []
+ elif attr_char == 'u':
+ attrs.append('u')
+ elif attr_char == 'b':
+ attrs.append('b')
+ if attr_char in string.digits and attr_char != '':
+ color_str = text[next_attr_char+1:text.find('}', next_attr_char)]
+ if color_str:
+ attrs.append(color_str + '}')
+ text = text[next_attr_char+len(color_str)+2:]
+ else:
+ text = text[next_attr_char+2:]
+ next_attr_char = text.find(FORMAT_CHAR)
+ return attrs
+