[ADD] conf for archlinux, <init>
[arrow.git] / archlinux_conf / home / .vim / autoload / tlib / char.vim
blobd485c37ff473e21ca748c83ba8c9899b84d67dab
1 " char.vim
2 " @Author:      Thomas Link (micathom AT gmail com?subject=[vim])
3 " @Website:     http://www.vim.org/account/profile.php?user_id=4037
4 " @License:     GPL (see http://www.gnu.org/licenses/gpl.txt)
5 " @Created:     2007-06-30.
6 " @Last Change: 2007-10-21.
7 " @Revision:    0.0.29
9 if &cp || exists("loaded_tlib_char_autoload")
10     finish
11 endif
12 let loaded_tlib_char_autoload = 1
15 " :def: function! tlib#char#Get(?timeout=0)
16 " Get a character.
18 " EXAMPLES: >
19 "   echo tlib#char#Get()
20 "   echo tlib#char#Get(5)
21 function! tlib#char#Get(...) "{{{3
22     TVarArg ['timeout', 0], ['resolution', 0]
23     if timeout == 0 || !has('reltime')
24         return getchar()
25     else
26         return tlib#char#GetWithTimeout(timeout, resolution)
27     endif
28     return -1
29 endf
32 function! tlib#char#IsAvailable() "{{{3
33     let ch = getchar(1)
34     return type(ch) == 0 && ch != 0
35 endf
38 function! tlib#char#GetWithTimeout(timeout, ...) "{{{3
39     TVarArg ['resolution', 2]
40     " TLogVAR a:timeout, resolution
41     let start = tlib#time#MSecs()
42     while 1
43         let c = getchar(0)
44         if type(c) != 0 || c != 0
45             return c
46         else
47             let now = tlib#time#MSecs()
48             let diff = tlib#time#DiffMSecs(now, start, resolution)
49             " TLogVAR diff
50             if diff > a:timeout
51                 return -1
52             endif
53         endif
54     endwh
55     return -1
56 endf