poezio/core/completions: Use Config from Core

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2022-08-31 16:03:09 +02:00
parent b53d99044f
commit b889b3329f
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2

View file

@ -12,7 +12,6 @@ from slixmpp import JID, InvalidJID
from poezio import common
from poezio import tabs
from poezio.libpoezio import XDG
from poezio.config import config
from poezio.roster import roster
from poezio.core.structs import POSSIBLE_SHOW, Completion
@ -80,7 +79,7 @@ class CompletionCore:
def theme(self, the_input):
""" Completion for /theme"""
themes_dir = config.getstr('themes_dir')
themes_dir = self.core.config.getstr('themes_dir')
themes_dir = Path(themes_dir).expanduser(
) if themes_dir else XDG.data_dir / 'themes'
try:
@ -221,7 +220,7 @@ class CompletionCore:
nicks = [tab.own_nick] if tab else []
default = os.environ.get('USER') if os.environ.get(
'USER') else 'poezio'
nick = config.getstr('default_nick')
nick = self.core.config.getstr('default_nick')
if not nick:
if default not in nicks:
nicks.append(default)
@ -358,8 +357,8 @@ class CompletionCore:
for section in plugin.config.sections()
]
else:
end_list = set(config.options('Poezio'))
end_list.update(config.default.get('Poezio', {}))
end_list = set(self.core.config.options('Poezio'))
end_list.update(self.core.config.default.get('Poezio', {}))
end_list = list(end_list)
end_list.sort()
elif n == 2:
@ -375,14 +374,14 @@ class CompletionCore:
plugin.config.default.get(section or plugin_name, {}))
end_list = list(end_list)
end_list.sort()
elif not config.has_option('Poezio', args[1]):
if config.has_section(args[1]):
end_list = config.options(args[1])
elif not self.core.config.has_option('Poezio', args[1]):
if self.core.config.has_section(args[1]):
end_list = self.core.config.options(args[1])
end_list.append('')
else:
end_list = []
else:
end_list = [str(config.get(args[1], '')), '']
end_list = [str(self.core.config.get(args[1], '')), '']
elif n == 3:
if '|' in args[1]:
plugin_name, section = args[1].split('|')[:2]
@ -396,10 +395,10 @@ class CompletionCore:
or plugin_name)), ''
]
else:
if not config.has_section(args[1]):
if not self.core.config.has_section(args[1]):
end_list = ['']
else:
end_list = [str(config.get(args[2], '', args[1])), '']
end_list = [str(self.core.config.get(args[2], '', args[1])), '']
else:
return False
return Completion(the_input.new_completion, end_list, n, quotify=True)
@ -411,7 +410,7 @@ class CompletionCore:
n = the_input.get_argument_position(quoted=True)
if n >= len(args):
args.append('')
if n == 1 or (n == 2 and config.has_section(args[1])):
if n == 1 or (n == 2 and self.core.config.has_section(args[1])):
return Completion(self.set, the_input)
return False
@ -419,7 +418,7 @@ class CompletionCore:
"Completion for /toggle"
return Completion(
the_input.new_completion,
config.options('Poezio'),
self.core.config.options('Poezio'),
1,
quotify=False)
@ -438,7 +437,7 @@ class CompletionCore:
nicks = [tab.own_nick] if tab else []
default = os.environ.get('USER') if os.environ.get(
'USER') else 'poezio'
nick = config.getstr('default_nick')
nick = self.core.config.getstr('default_nick')
if not nick:
if default not in nicks:
nicks.append(default)