aboutsummaryrefslogtreecommitdiff
path: root/src/core_modules/commands
diff options
context:
space:
mode:
authorGravatar jesopo2020-03-03 11:15:00 +0000
committerGravatar jesopo2020-03-03 11:16:39 +0000
commit7bf0b6edbffd45118c8a7f4f638bdd7f784a2598 (patch)
treef7fdd54439c3f673e51db6b447168a2837040a99 /src/core_modules/commands
parentrefactor perform.py (diff)
signature
rewrite command output truncation
Diffstat (limited to 'src/core_modules/commands')
-rw-r--r--src/core_modules/commands/__init__.py30
-rw-r--r--src/core_modules/commands/outs.py7
2 files changed, 20 insertions, 17 deletions
diff --git a/src/core_modules/commands/__init__.py b/src/core_modules/commands/__init__.py
index a5c5faa6..777cb692 100644
--- a/src/core_modules/commands/__init__.py
+++ b/src/core_modules/commands/__init__.py
@@ -8,8 +8,8 @@ COMMAND_METHOD = "command-method"
COMMAND_METHODS = ["PRIVMSG", "NOTICE"]
STR_MORE = " (more...)"
+STR_CONTINUED = "(...continued) "
STR_MORE_LEN = len(STR_MORE.encode("utf8"))
-STR_CONTINUED = "(...continued)"
WORD_BOUNDARIES = [" "]
NON_ALPHANUMERIC = [char for char in string.printable if not char.isalnum()]
@@ -237,29 +237,25 @@ class Module(ModuleManager.BaseModule):
color = utils.consts.RED
line_str = obj.pop()
+ prefix = ""
if obj.prefix:
- line_str = "[%s] %s" % (
- utils.irc.color(obj.prefix, color), line_str)
+ prefix = "[%s] " % utils.irc.color(obj.prefix, color)
+ if obj._overflowed:
+ prefix = "%s%s" % (prefix, STR_CONTINUED)
method = self._command_method(server, target, is_channel)
if not method in ["PRIVMSG", "NOTICE"]:
raise ValueError("Unknown command-method '%s'" % method)
- line = IRCLine.ParsedLine(method, [target_str, line_str],
- tags=tags)
- valid, trunc = line.truncate(server.hostmask(),
- margin=STR_MORE_LEN)
+ line = server.new_line(method, [target_str, prefix], tags=tags)
+
+ overflow = line.push_last(line_str, human_trunc=True,
+ extra_margin=STR_MORE_LEN)
+ if overflow:
+ line.push_last(STR_MORE)
+ obj.insert(overflow)
+ obj._overflowed = True
- if trunc:
- if not trunc[0] in WORD_BOUNDARIES:
- for boundary in WORD_BOUNDARIES:
- left, *right = valid.rsplit(boundary, 1)
- if right:
- valid = left
- trunc = right[0]+trunc
- obj.insert("%s %s" % (STR_CONTINUED, trunc))
- valid = valid+STR_MORE
- line = IRCLine.parse_line(valid)
if obj._assured:
line.assure()
server.send(line)
diff --git a/src/core_modules/commands/outs.py b/src/core_modules/commands/outs.py
index e82ceefd..c6b489ae 100644
--- a/src/core_modules/commands/outs.py
+++ b/src/core_modules/commands/outs.py
@@ -6,6 +6,13 @@ class StdOut(object):
self.prefix = prefix
self._lines = []
self._assured = False
+ self._overflowed = False
+
+ def copy_from(self, other):
+ self.prefix = other.prefix
+ self._lines = other._lines
+ self._assured = other._assured
+ self._overflowed = other._overflowed
def assure(self):
self._assured = True