Skip to content

Instantly share code, notes, and snippets.

@skanehira
Last active July 26, 2020 11:43
Show Gist options
  • Save skanehira/f2bdc6f408cfdf8bfe21cf10fc179aab to your computer and use it in GitHub Desktop.
Save skanehira/f2bdc6f408cfdf8bfe21cf10fc179aab to your computer and use it in GitHub Desktop.
function! s:comment(obj, timer) abort
let winid = popup_create(a:obj.text, #{
\ col: &columns - 40,
\ line: rand(srand()) % &lines,
\ minwidth: strlen(a:obj.text),
\ maxwidth: 40,
\ tabpage: -1,
\ zindex: 300,
\ })
call timer_start(100, function("s:move", [winid]), #{
\ repeat: -1,
\ })
endfunction
function! s:move(winid, timer) abort
let opt = popup_getpos(a:winid)
if opt.col is# 1
call timer_stop(a:timer)
call popup_close(a:winid)
return
endif
let opt.col -= 1
call popup_move(a:winid, opt)
redraw
endfunction
function! s:tweet(ch, msg) abort
let obj = json_decode(a:msg)
if obj.text is# ""
return
endif
let wait = rand(srand()) % 12
call timer_start(wait*800, function('s:comment', [obj]))
endfunction
function! s:onerr(ch, msg) abort
echohl ErrorMsg
echom a:msg
echohl None
endfunction
call job_start(["twty", "-S", "20s", "-json"], #{
\ out_cb: function('s:tweet'),
\ err_cb: function('s:onerr')
\ })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment