diff --git a/autoload/SpaceVim/api/unicode/spinners.vim b/autoload/SpaceVim/api/unicode/spinners.vim new file mode 100644 index 000000000..342b61aef --- /dev/null +++ b/autoload/SpaceVim/api/unicode/spinners.vim @@ -0,0 +1,52 @@ +"============================================================================= +" spinners.vim --- spinners API for SpaceVim +" Copyright (c) 2016-2017 Wang Shidong & Contributors +" Author: Wang Shidong < wsdjeg at 163.com > +" URL: https://spacevim.org +" License: GPLv3 +"============================================================================= +scriptencoding utf-8 +let s:self = {} +let s:self._data = { + \ 'dot1' : { + \ 'frames' : ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'], + \ 'strwidth' : 1, + \ 'timeout' : 80 + \ } + \ } + +let s:self._id = 0 + +function! s:self.Onframe(...) abort dict + if self.index < len(self.spinners) - 1 + let self.index += 1 + else + let self.index = 0 + endif + let self.str = self.spinners[self.index] + exe 'let ' . self.var . '= self.str' +endfunction + +" return timer id and strwidth +function! s:self.apply(name, var) abort dict + let time = self._data[a:name].timeout + let self.index = 0 + let self.var = a:var + let self.spinners = self._data[a:name].frames + exe 'let ' . self.var . '= self.spinners[self.index]' + let self.timer_id = timer_start(time, self.Onframe, {'repeat' : -1}) + return [self.timer_id, self._data[a:name].strwidth] +endfunction + + +function! s:self.get_str() abort + return self.str +endfunction + +function! s:self.get_info(name) abort + return get(self._data, a:name, {}) +endfunction + +function! SpaceVim#api#unicode#spinners#get() abort + return deepcopy(s:self) +endfunction diff --git a/docs/api.md b/docs/api.md index 3bf301126..63db7c79e 100644 --- a/docs/api.md +++ b/docs/api.md @@ -7,7 +7,7 @@ description: "A list of available APIs in SpaceVim, provide compatible functions -- [Introduction](#introduction) + - [Introduction](#introduction) - [Available APIs](#available-apis) @@ -34,25 +34,26 @@ echom s:file.pathSeparator -#### Available APIs +## Available APIs here is the list of all available APIs, and welcome to contribute to SpaceVim. -| Name | Description | -| ------------------------------- | -------------------------------------------------------------------------------------------------- | -| [data#base64](data/base64/) | data#base64 API provides base64 encode and decode functions | -| [data#dict](data/dict/) | data#dict API provides some basic functions and values for dict. | -| [data#string](data/string/) | data#string API provides some basic functions and values for string. | -| [data#toml](data/toml/) | data#toml API provides some basic functions and values for toml. | -| [file](file/) | file API provides some basic functions and values for current os. | -| [job](job/) | job API provides some basic functions for running a job | -| [logger](logger/) | logger API provides some basic functions for log message when create plugins | -| [messletters](messletters/) | messletters API provides some basic functions for generating messletters | -| [password](password/) | password API provides some basic functions for generating password | -| [system](system/) | system API provides some basic functions and values for current os. | -| [vim#highlight](vim/highlight/) | vim#highlight API provides some basic functions and values for getting and setting highlight info. | -| [web#html](web/html/) | web#html API provides some basic functions and values for parser html file. | -| [web#http](web/http/) | web#http API provides some basic functions and values for http request | -| [web#xml](web/xml/) | web#xml API provides some basic functions and values for parser xml file. | +| Name | Description | +| ------------------------------------- | -------------------------------------------------------------------------------------------------- | +| [data#base64](data/base64/) | data#base64 API provides base64 encode and decode functions | +| [data#dict](data/dict/) | data#dict API provides some basic functions and values for dict. | +| [data#string](data/string/) | data#string API provides some basic functions and values for string. | +| [data#toml](data/toml/) | data#toml API provides some basic functions and values for toml. | +| [file](file/) | file API provides some basic functions and values for current os. | +| [job](job/) | job API provides some basic functions for running a job | +| [logger](logger/) | logger API provides some basic functions for log message when create plugins | +| [messletters](messletters/) | messletters API provides some basic functions for generating messletters | +| [password](password/) | password API provides some basic functions for generating password | +| [system](system/) | system API provides some basic functions and values for current os. | +| [unicode#spinners](unicode/spinners/) | unicode#spinners API provides some basic functions for starting spinners timer | +| [vim#highlight](vim/highlight/) | vim#highlight API provides some basic functions and values for getting and setting highlight info. | +| [web#html](web/html/) | web#html API provides some basic functions and values for parser html file. | +| [web#http](web/http/) | web#http API provides some basic functions and values for http request | +| [web#xml](web/xml/) | web#xml API provides some basic functions and values for parser xml file. | diff --git a/docs/api/unicode/spinners.md b/docs/api/unicode/spinners.md new file mode 100644 index 000000000..21e731953 --- /dev/null +++ b/docs/api/unicode/spinners.md @@ -0,0 +1,29 @@ +--- +title: "unicode#spinners api" +description: "unicode#spinners API provides some basic functions for starting spinners timer" +--- + +# [Available APIs](../../) >> unicode#spinners + + + +- [Intro](#intro) +- [Functions](#functions) + + + +## Intro + +unicode#spinners API provides some basic functions for starting spinners timer + +```vim +let s:SPI = SpaceVim#api#import('unicode#spinners') +call s:SPI.apply('dot1', 'g:dotstr') +set statusline+=%{g:dotstr} +``` + +## Functions + +| function name | description | +| ------------------------ | ------------------------------ | +| `apply(name, time, var)` | start a job, return the job id | diff --git a/docs/cn/api.md b/docs/cn/api.md index 3fe8b1c1e..2c32e5c5d 100644 --- a/docs/cn/api.md +++ b/docs/cn/api.md @@ -8,8 +8,8 @@ lang: cn -- [简介](#简介) -- [使用方法](#使用方法) + - [简介](#简介) + - [使用方法](#使用方法) - [可用 APIs](#可用-apis) @@ -39,13 +39,14 @@ echom s:file.pathSeparator -#### 可用 APIs +## 可用 APIs -| 名称 | 描述 | -| ------------------------------- | -------------------------------------------------------------- | -| [file](file/) | can not find Description | -| [job](job/) | 兼容 neovim 和 vim 的异步协同 API,对于旧版 vim 采用非异步机制 | -| [system](system/) | can not find Description | -| [vim#highlight](vim/highlight/) | vim#highlight API 提供一些设置和获取 Vim 高亮信息的基础函数。 | +| 名称 | 描述 | +| ------------------------------------- | ----------------------------------------------------------------------- | +| [file](file/) | can not find Description | +| [job](job/) | 兼容 neovim 和 vim 的异步协同 API,对于旧版 vim 采用非异步机制 | +| [system](system/) | can not find Description | +| [unicode#spinners](unicode/spinners/) | unicode#spinners API 可启用一个定时器,根据指定的名称定时更新进度条符号 | +| [vim#highlight](vim/highlight/) | vim#highlight API 提供一些设置和获取 Vim 高亮信息的基础函数。 | diff --git a/docs/cn/api/unicode/spinners.md b/docs/cn/api/unicode/spinners.md new file mode 100644 index 000000000..96fa456da --- /dev/null +++ b/docs/cn/api/unicode/spinners.md @@ -0,0 +1,30 @@ +--- +title: "unicode#spinners api" +description: "unicode#spinners API 可启用一个定时器,根据指定的名称定时更新进度条符号" +lang: cn +--- + +# [公共 API](../../) >> unicode#spinners + + + +- [简介](#简介) +- [函数](#函数) + + + +## 简介 + +unicode#spinners API 主要提供一个 apply 函数,可根据名称定时更新某个变量的值,实现进度条效果: + +```vim +let s:SPI = SpaceVim#api#import('unicode#spinners') +call s:SPI.apply('dot1', 'g:dotstr') +set statusline+=%{g:dotstr} +``` + +## 函数 + +| 函数名称 | 描述 | +| ------------------ | ------------------------------------- | +| `apply(name, var)` | 启动一个定时器,定时更新变量 var 的值 | diff --git a/wiki/en/Following-HEAD.md b/wiki/en/Following-HEAD.md index 55e13d737..f96493ef3 100644 --- a/wiki/en/Following-HEAD.md +++ b/wiki/en/Following-HEAD.md @@ -6,6 +6,8 @@ The next release is v1.0.0. ### Added +- Add unicode#spinners api ([#1926](https://github.com/SpaceVim/SpaceVim/pull/1926)) + ### Improvement - Update runtime log for startup ([#2219](https://github.com/SpaceVim/SpaceVim/pull/2219))