Created
October 23, 2014 21:28
-
-
Save btipling/eb81e683cdb8d3bebe73 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from threading import Thread, Lock | |
| from time import sleep, strftime | |
| def msg(vim, msg): | |
| vim.command('echom "%s"' % (msg,)) | |
| class EventLoop(Thread): | |
| def __init__(self, vim): | |
| super(EventLoop, self).__init__() | |
| self.vim = vim | |
| self.lock = Lock() | |
| self.intervals = [] | |
| def setInterval(self, event): | |
| self.intervals.append(event) | |
| def run(self): | |
| while True: | |
| sleep(0.01) | |
| with self.lock: | |
| for interval in self.intervals: | |
| self.vim.session.post(interval) | |
| class NvimClock(object): | |
| def __init__(self, vim): | |
| self.vim = vim | |
| self.eventLoop = EventLoop(vim) | |
| self.msg('Initing NvimClock') | |
| vim.command('command! ClockStart call rpcrequest(%d, "clock_start")' % | |
| self.vim.channel_id) | |
| vim.command('command! ClockStop call rpcrequest(%d, "clock_stop")' % | |
| self.vim.channel_id) | |
| def clock_start(self): | |
| self.msg('Starting NvimClock') | |
| self.eventLoop.setInterval('tick') | |
| self.eventLoop.start() | |
| def clock_stop(self): | |
| self.msg('Stopping NvimClock') | |
| self.eventLoop.end() | |
| def on_tick(self): | |
| self.vim.command('set statusline=%s' % (self.get_clock(),)) | |
| def get_clock(self): | |
| return strftime("%H:%M:%S") | |
| def msg(self, newMsg): | |
| msg(self.vim, newMsg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment