6 def channel_completer(window
, left
, right
, text
):
7 if isinstance(window
, windows
.ChannelWindow
):
10 for w
in windows
.get_with(wclass
=windows
.ChannelWindow
, network
=window
.network
):
14 for w
in windows
.get_with(wclass
=windows
.ChannelWindow
):
15 if w
.network
is not window
.network
:
18 # normal server commands
19 srv_commands
= ('ping', 'join', 'part', 'mode', 'server', 'kick',
20 'quit', 'nick', 'privmsg', 'notice', 'topic')
22 def command_completer(window
, left
, right
, text
):
23 for c
in srv_commands
:
26 if 'CMDS' in window
.network
.isupport
:
27 for c
in window
.network
.isupport
['CMDS'].split(','):
28 yield '/%s' % c
.lower()
30 for c
in events
.events
:
31 if c
.startswith('Command') and c
!= 'Command':
32 yield '/%s' % c
[7:].lower()
34 def nick_completer(window
, left
, right
, text
):
35 if type(window
) == windows
.QueryWindow
:
38 recent_speakers
= getattr(window
, 'recent_speakers', ())
40 for nick
in recent_speakers
:
41 if chaninfo
.ison(window
.network
, window
.id, nick
):
44 for nick
in chaninfo
.nicks(window
.network
, window
.id):
45 if nick
not in recent_speakers
:
48 def script_completer(window
, left
, right
, text
):
49 return events
.loaded
.iterkeys()
51 def network_completer(window
, left
, right
, text
):
52 return conf
.get('networks', {}).iterkeys()
54 def get_completer_for(window
):
57 left
, right
= input.text
[:input.cursor
], input.text
[input.cursor
:]
59 text
= left
.split(' ')[-1]
63 if text
and text
[0] in window
.network
.isupport
.get('CHANTYPES', '#&+'):
64 candidates
= channel_completer(window
, left
, right
, text
)
66 elif input.text
.startswith('/reload '):
67 candidates
= script_completer(window
, left
, right
, text
)
69 elif input.text
.startswith('/edit '):
70 candidates
= script_completer(window
, left
, right
, text
)
72 elif input.text
.startswith('/server '):
73 candidates
= network_completer(window
, left
, right
, text
)
75 elif text
.startswith('/'):
76 candidates
= command_completer(window
, left
, right
, text
)
80 candidates
= nick_completer(window
, left
, right
, text
)
88 before
= left
[:-len(text
)]
92 insert_text
= '%s%s%s%s' % (before
, '%s', suffix
, right
)
93 cursor_pos
= len(before
+ suffix
)
95 original
= window
.input.text
, window
.input.cursor
97 for cand
in candidates
:
98 if cand
.lower().startswith(text
.lower()):
99 window
.input.text
, window
.input.cursor
= insert_text
% cand
, cursor_pos
+ len(cand
)
102 window
.input.text
, window
.input.cursor
= original
105 # generator--use recent_completer.next() to continue cycling through whatever
106 recent_completer
= None
109 global recent_completer
112 if not recent_completer
:
113 recent_completer
= get_completer_for(e
.window
)
115 recent_completer
.next()
118 recent_completer
= None
121 global recent_completer
123 recent_completer
= None
126 if chaninfo
.ischan(e
.network
, e
.target
):
127 if not hasattr(e
.window
, 'recent_speakers'):
128 e
.window
.recent_speakers
= []
130 for nick
in e
.window
.recent_speakers
:
131 if nick
== e
.source
or not chaninfo
.ison(e
.network
, e
.target
, nick
):
132 e
.window
.recent_speakers
.remove(nick
)
134 e
.window
.recent_speakers
.insert(0, e
.source
)