mirror of
https://github.com/ZoiteChat/zoitechat.git
synced 2026-11-05 00:05:39 +00:00
add opt-in post-display print hooks
This commit is contained in:
1 parent
bf89691b3f
commit
d3f892e9a7
6 files changed
+91
No files matched your search
@@ -0,0 +1,21 @@
|
||||
"""Opt-in post-display print observers."""
|
||||
import _zoitechat as api
|
||||
from _zoitechat_embedded import ffi, lib
|
||||
|
||||
__all__ = ['hook_print_after']
|
||||
|
||||
|
||||
def hook_print_after(name, callback, userdata=None, priority=api.PRI_NORM):
|
||||
"""callback(word, word_eol, userdata, attrs); its return value is ignored."""
|
||||
if not callable(callback):
|
||||
raise TypeError('callback must be callable')
|
||||
plugin = api.__get_current_plugin()
|
||||
hook = plugin.add_hook(callback, userdata)
|
||||
handle = lib.zoitechat_hook_print_after(lib.ph, name.encode(), priority, 0,
|
||||
lib._on_print_attrs_hook, hook.handle)
|
||||
if handle == ffi.NULL:
|
||||
hook.is_unload = True
|
||||
plugin.remove_hook(id(hook))
|
||||
raise RuntimeError('unable to install post-display hook')
|
||||
hook.zoitechat_hook = handle
|
||||
return id(hook)
|
||||
Reference in new issue
Block a user