summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--poezio/core/__init__.py5
-rw-r--r--poezio/core/commands.py10
-rw-r--r--poezio/core/completions.py6
-rw-r--r--poezio/core/core.py8
-rw-r--r--poezio/core/structs.py37
-rw-r--r--poezio/tabs/basetabs.py12
6 files changed, 46 insertions, 32 deletions
diff --git a/poezio/core/__init__.py b/poezio/core/__init__.py
index 6a82e2bb..fd3d0283 100644
--- a/poezio/core/__init__.py
+++ b/poezio/core/__init__.py
@@ -1,8 +1,7 @@
"""
-Core class, splitted into smaller chunks
+Core class, split into smaller chunks
"""
from . core import Core
-from . structs import Command, Status, possible_show, DEPRECATED_ERRORS, \
- ERROR_AND_STATUS_CODES
+from . structs import Command, Status
diff --git a/poezio/core/commands.py b/poezio/core/commands.py
index a0a636c1..7d9c0a92 100644
--- a/poezio/core/commands.py
+++ b/poezio/core/commands.py
@@ -27,7 +27,7 @@ from roster import roster
from theming import dump_tuple, get_theme
from decorators import command_args_parser
-from . structs import Command, possible_show
+from . structs import Command, POSSIBLE_SHOW
@command_args_parser.quoted(0, 1)
@@ -44,7 +44,7 @@ def command_help(self, args):
acc.append(' \x19%s}%s\x19o - %s' % (
color,
command,
- self.commands[command].short))
+ self.commands[command].short_desc))
else:
acc.append(' \x19%s}%s\x19o' % (color, command))
acc = sorted(acc)
@@ -57,7 +57,7 @@ def command_help(self, args):
acc.append(' \x19%s}%s\x19o - %s' % (
color,
command,
- commands[command].short))
+ commands[command].short_desc))
else:
acc.append(' \x19%s}%s\x19o' % (color, command))
acc = sorted(acc)
@@ -111,10 +111,10 @@ def command_status(self, args):
if args is None:
return self.command_help('status')
- if not args[0] in possible_show.keys():
+ if not args[0] in POSSIBLE_SHOW.keys():
return self.command_help('status')
- show = possible_show[args[0]]
+ show = POSSIBLE_SHOW[args[0]]
msg = args[1]
pres = self.xmpp.make_presence()
diff --git a/poezio/core/completions.py b/poezio/core/completions.py
index 9fd44f1b..2f7b9e65 100644
--- a/poezio/core/completions.py
+++ b/poezio/core/completions.py
@@ -15,7 +15,7 @@ from common import safeJID
from config import config
from roster import roster
-from . structs import possible_show
+from . structs import POSSIBLE_SHOW
def completion_help(self, the_input):
@@ -29,7 +29,7 @@ def completion_status(self, the_input):
Completion of /status
"""
if the_input.get_argument_position() == 1:
- return the_input.new_completion([status for status in possible_show], 1, ' ', quotify=False)
+ return the_input.new_completion([status for status in POSSIBLE_SHOW], 1, ' ', quotify=False)
def completion_presence(self, the_input):
@@ -40,7 +40,7 @@ def completion_presence(self, the_input):
if arg == 1:
return the_input.auto_completion([jid for jid in roster.jids()], '', quotify=True)
elif arg == 2:
- return the_input.auto_completion([status for status in possible_show], '', quotify=True)
+ return the_input.auto_completion([status for status in POSSIBLE_SHOW], '', quotify=True)
def completion_theme(self, the_input):
diff --git a/poezio/core/core.py b/poezio/core/core.py
index ab234367..089454ec 100644
--- a/poezio/core/core.py
+++ b/poezio/core/core.py
@@ -45,7 +45,7 @@ import keyboard
from . import completions
from . import commands
from . import handlers
-from . structs import possible_show, DEPRECATED_ERRORS, \
+from . structs import POSSIBLE_SHOW, DEPRECATED_ERRORS, \
ERROR_AND_STATUS_CODES, Command, Status
@@ -61,7 +61,7 @@ class Core(object):
self.connection_time = time.time()
self.stdscr = None
status = config.get('status')
- status = possible_show.get(status, None)
+ status = POSSIBLE_SHOW.get(status, None)
self.status = Status(show=status,
message=config.get('status_message'))
self.running = True
@@ -716,11 +716,11 @@ class Core(object):
if line == "":
return
if line.startswith('/'):
- command = line.strip()[:].split()[0][1:]
+ command = line.strip().split()[0][1:]
arg = line[2+len(command):] # jump the '/' and the ' '
# example. on "/link 0 open", command = "link" and arg = "0 open"
if command in self.commands:
- func = self.commands[command][0]
+ func = self.commands[command].func
func(arg)
return
else:
diff --git a/poezio/core/structs.py b/poezio/core/structs.py
index 4ce0ef43..82effd48 100644
--- a/poezio/core/structs.py
+++ b/poezio/core/structs.py
@@ -1,7 +1,9 @@
"""
Module defining structures useful to the core class and related methods
"""
-import collections
+
+__all__ = ['ERROR_AND_STATUS_CODES', 'DEPRECATED_ERRORS', 'POSSIBLE_SHOW',
+ 'Status', 'Command']
# http://xmpp.org/extensions/xep-0045.html#errorstatus
ERROR_AND_STATUS_CODES = {
@@ -36,14 +38,27 @@ DEPRECATED_ERRORS = {
'510': 'Disconnected',
}
-possible_show = {'available':None,
- 'chat':'chat',
- 'away':'away',
- 'afk':'away',
- 'dnd':'dnd',
- 'busy':'dnd',
- 'xa':'xa'
- }
+POSSIBLE_SHOW = {
+ 'available': None,
+ 'chat': 'chat',
+ 'away': 'away',
+ 'afk': 'away',
+ 'dnd': 'dnd',
+ 'busy': 'dnd',
+ 'xa': 'xa'
+}
+
+class Status:
+ __slots__ = ('show', 'message')
+ def __init__(self, show, message):
+ self.show = show
+ self.message = message
-Status = collections.namedtuple('Status', 'show message')
-Command = collections.namedtuple('Command', 'func desc comp short usage')
+class Command:
+ __slots__ = ('func', 'desc', 'comp', 'short_desc', 'usage')
+ def __init__(self, func, desc, comp, short_desc, usage):
+ self.func = func
+ self.desc = desc
+ self.comp = comp
+ self.short_desc = short_desc
+ self.usage = usage
diff --git a/poezio/tabs/basetabs.py b/poezio/tabs/basetabs.py
index bb0c0ea4..5f0bc138 100644
--- a/poezio/tabs/basetabs.py
+++ b/poezio/tabs/basetabs.py
@@ -252,10 +252,10 @@ class Tab(object):
command = self.core.commands[command_name]
else: # Unknown command, cannot complete
return False
- if command[2] is None:
+ if command.comp is None:
return False # There's no completion function
else:
- return command[2](the_input)
+ return command.comp(the_input)
return False
def execute_command(self, provided_text):
@@ -270,15 +270,15 @@ class Tab(object):
arg = txt[2+len(command):] # jump the '/' and the ' '
func = None
if command in self.commands: # check tab-specific commands
- func = self.commands[command][0]
+ func = self.commands[command].func
elif command in self.core.commands: # check global commands
- func = self.core.commands[command][0]
+ func = self.core.commands[command].func
else:
low = command.lower()
if low in self.commands:
- func = self.commands[low][0]
+ func = self.commands[low].func
elif low in self.core.commands:
- func = self.core.commands[low][0]
+ func = self.core.commands[low].func
else:
if self.missing_command_callback is not None:
error_handled = self.missing_command_callback(low)