mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-02 23:20:04 +08:00
Add spinners api (#1926)
This commit is contained in:
parent
27200eee8b
commit
aabe1674ca
52
autoload/SpaceVim/api/unicode/spinners.vim
Normal file
52
autoload/SpaceVim/api/unicode/spinners.vim
Normal file
@ -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
|
37
docs/api.md
37
docs/api.md
@ -7,7 +7,7 @@ description: "A list of available APIs in SpaceVim, provide compatible functions
|
||||
|
||||
<!-- vim-markdown-toc GFM -->
|
||||
|
||||
- [Introduction](#introduction)
|
||||
- [Introduction](#introduction)
|
||||
- [Available APIs](#available-apis)
|
||||
|
||||
<!-- vim-markdown-toc -->
|
||||
@ -34,25 +34,26 @@ echom s:file.pathSeparator
|
||||
|
||||
<!-- SpaceVim api list start -->
|
||||
|
||||
#### 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. |
|
||||
|
||||
<!-- SpaceVim api list end -->
|
||||
|
29
docs/api/unicode/spinners.md
Normal file
29
docs/api/unicode/spinners.md
Normal file
@ -0,0 +1,29 @@
|
||||
---
|
||||
title: "unicode#spinners api"
|
||||
description: "unicode#spinners API provides some basic functions for starting spinners timer"
|
||||
---
|
||||
|
||||
# [Available APIs](../../) >> unicode#spinners
|
||||
|
||||
<!-- vim-markdown-toc GFM -->
|
||||
|
||||
- [Intro](#intro)
|
||||
- [Functions](#functions)
|
||||
|
||||
<!-- vim-markdown-toc -->
|
||||
|
||||
## 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 |
|
@ -8,8 +8,8 @@ lang: cn
|
||||
|
||||
<!-- vim-markdown-toc GFM -->
|
||||
|
||||
- [简介](#简介)
|
||||
- [使用方法](#使用方法)
|
||||
- [简介](#简介)
|
||||
- [使用方法](#使用方法)
|
||||
- [可用 APIs](#可用-apis)
|
||||
|
||||
<!-- vim-markdown-toc -->
|
||||
@ -39,13 +39,14 @@ echom s:file.pathSeparator
|
||||
|
||||
<!-- SpaceVim api cn list start -->
|
||||
|
||||
#### 可用 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 高亮信息的基础函数。 |
|
||||
|
||||
<!-- SpaceVim api cn list end -->
|
||||
|
30
docs/cn/api/unicode/spinners.md
Normal file
30
docs/cn/api/unicode/spinners.md
Normal file
@ -0,0 +1,30 @@
|
||||
---
|
||||
title: "unicode#spinners api"
|
||||
description: "unicode#spinners API 可启用一个定时器,根据指定的名称定时更新进度条符号"
|
||||
lang: cn
|
||||
---
|
||||
|
||||
# [公共 API](../../) >> unicode#spinners
|
||||
|
||||
<!-- vim-markdown-toc GFM -->
|
||||
|
||||
- [简介](#简介)
|
||||
- [函数](#函数)
|
||||
|
||||
<!-- vim-markdown-toc -->
|
||||
|
||||
## 简介
|
||||
|
||||
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 的值 |
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user