代码拉取完成,页面将自动刷新
同步操作将从 fisher/logsets 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
/**
import createLogger from "coloredLogger"
import tasklistPlugin from "logsets/plugins/progressbar""
const logger = createLogger({...})
logger.use(tasklistPlugin)
const tasks = logger.tasklist({
})
tasks.add("准备复制文件")
task.complete()
task.error()
task.skip()
task.doing()
downloads.forEach(download=>{
tasks.add(download.name)
try{
...await http.download(url)
}catch(e){
tasks.error(e.message)
}
tasks.complete() // 可选,如果没有指定,则add会自动完成当前任务
tasks.error()
tasks.skip()
})
// 进入下一个任务
tasks.next()
开始构建列表:
√ 准备复制文件....................................OK
× 构建列表列表....................................ERROR
● 编译列表........................................CANCEL
- 渲染列表........................................OK
- 渲染列表........................................ERROR
- 渲染列表........................................| / \ ──
*/
import deepmerge from 'deepmerge'
import { consoleOutput, getStringWidth,hideCursor,showCursor,newline, paddingEnd } from './utils.js'
const DefaultTaskListOptions = {
indent : " ", // 列表缩进
style : "bright", // 标题样式
width : 60, // 列表总宽度
refInterval:200, // 列表项渲染间隔
progressbar:{
style:"darkGray", // 进度条样式
char:".", // 进度条字符
},
status:{
running:{
style:"white",
symbol:"-",
note:""
},
complete:{
style:"green",
symbol:"√",
note:"OK"
},
error:{
style:"red",
symbol:"×",
note:"ERROR"
},
fail:{
style:"red",
symbol:"×",
note:"FAIL"
},
skip:{
style:"yellow",
symbol:"○",
note:"SKIP"
},
stop:{
style:"red",
symbol:"●",
note:"STOP"
},
todo:{
style:"lightCyan",
symbol:"□",
note:"TODO"
}
}
}
function createTaskList(context,options){
const logger = this
if(typeof(options)=="string") options = {title:options}
const opts = deepmerge(DefaultTaskListOptions,options)
// 显示任务标题 ? bright
if(opts.title){
let titleColorizer = logger.getColorizer(opts.style)
console.log(titleColorizer(logger.getColorizedTemplate(opts.title)))
}
let curTask = null
const spinnerChars = ["|","/","-","\\","|","/","-","\\"]
const getColorizer = logger.getColorizer
function createTask(title){
const self = this
let status = "running" // 0-进行中,1-完成,2-错误,3-跳过,4-停止
let spinnerIndex = 0 // 动态旋转序号
let spinnerDir = 0 // 动态旋转方向
let progressValue = 0 // 进度值
let timer = null
let listNote = null
self.isEnd = ()=>status!=="running"
self.render = ()=>{
// 显示列表项符号
const symbolOptions = opts.status[status]
let symbol = symbolOptions.symbol
if(status==="running"){
symbol = spinnerChars[spinnerIndex++]
if(spinnerIndex>=spinnerChars.length) {
spinnerIndex = 0
}
symbol = getColorizer(symbolOptions.style)(symbol)
}else{
symbol = getColorizer(symbolOptions.style)(symbolOptions.symbol)
}
// 文本内容
//title = getColorizer(opts.style)(title)
title = logger.getColorizedTemplate(...(Array.isArray(title) ? title : [title]))
// 显示进度条
let progressbarWidth = opts.width - getStringWidth(title)
let progressbar = ""
if(progressbarWidth<1) progressbarWidth = 0
if(opts.progressbar.char.length>0 && progressbarWidth>0){
progressValue ++
if(progressValue>progressbarWidth) progressValue = 0
if(status!=="running"){
progressValue = progressbarWidth
}
progressbar = new Array(progressValue).fill(opts.progressbar.char).join("")
progressbar = paddingEnd(progressbar,progressbarWidth," ")
progressbar = getColorizer(opts.progressbar.style)(progressbar)
}
// 显示note
let note =listNote || opts.status[status].note
note = getColorizer(opts.status[status].style)(note)
consoleOutput(`${opts.indent}${symbol} ${title}${progressbar}${note}`,{end:"\r"})
}
self.start = function(){
timer = setInterval(()=>{
if(status!=="running") clearInterval(timer) // 停止任务
self.render() // 反复渲染任务
},opts.refInterval)
}
self.end=()=>{
clearInterval(timer)
self.render()
newline()
showCursor()
}
Object.entries(opts.status).forEach(([key,state])=>{
self[key] = (note)=>{
let finalNote = note
if(typeof(note)==="function") finalNote = note()
if(finalNote instanceof Error) finalNote = note.error
listNote = note || state.note
status = key
self.end()
}
})
}
let tasklistObj = {
add(title){
if(curTask && !curTask.isEnd()){
curTask.complete()
}
curTask = new createTask(title)
curTask.start()
hideCursor()
return curTask
}
}
Object.entries(opts.status).forEach(([key,state])=>{
tasklistObj[key] = note=>{
if(curTask){
curTask[key](note)
}
}
})
return tasklistObj
}
/**
*
* @param {*} log
* @param {*} context 当前表格的上下文配置参数
*/
export default function(logger,context){
logger.tasklist = (opts={})=>createTaskList.call(logger,context,opts)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。