UNPKG

ink-task-list

Version:
2 lines (1 loc) 1.95 kB
import e,{useState as d,useEffect as v,Children as R,isValidElement as y}from"react";import{Box as l,Text as n}from"ink";import t from"process";const T=({children:r})=>e.createElement(l,{flexDirection:"column"},r);function w(){return t.platform!=="win32"?t.env.TERM!=="linux":Boolean(t.env.CI)||Boolean(t.env.WT_SESSION)||t.env.ConEmuTask==="{cmd::Cmder}"||t.env.TERM_PROGRAM==="vscode"||t.env.TERM==="xterm-256color"||t.env.TERM==="alacritty"||t.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}const S={arrowRight:"\u2192",tick:"\u2714",info:"\u2139",warning:"\u26A0",cross:"\u2716",squareSmallFilled:"\u25FC",pointer:"\u276F"},h={arrowRight:"\u2192",tick:"\u221A",info:"i",warning:"\u203C",cross:"\xD7",squareSmallFilled:"\u25A0",pointer:">"};var o=w()?S:h;const p=({spinner:r})=>{const[i,c]=d(0);return v(()=>{const a=setInterval(()=>{c(m=>m===r.frames.length-1?0:m+1)},r.interval);return()=>{clearInterval(a)}},[r]),e.createElement(n,null,r.frames[i])},x=r=>r==="warning"?e.createElement(n,{color:"yellow"},o.warning):r==="error"?e.createElement(n,{color:"red"},o.cross):r==="success"?e.createElement(n,{color:"green"},o.tick):r==="pending"?e.createElement(n,{color:"gray"},o.squareSmallFilled):" ",A=r=>e.createElement(n,{color:r==="error"?"red":"yellow"},o.pointer),C=({label:r,state:i="pending",status:c,output:a,spinner:m,isExpanded:s,children:f})=>{const u=R.toArray(f).filter(g=>y(g));let E=i==="loading"?e.createElement(n,{color:"yellow"},e.createElement(p,{spinner:m})):x(i);return s&&(E=A(i)),e.createElement(l,{flexDirection:"column"},e.createElement(l,null,e.createElement(l,{marginRight:1},e.createElement(n,null,E)),e.createElement(n,null,r),c?e.createElement(l,{marginLeft:1},e.createElement(n,{dimColor:!0},"[",c,"]")):void 0),a?e.createElement(l,{marginLeft:2},e.createElement(n,{color:"gray"},`${o.arrowRight} ${a}`)):void 0,s&&u.length>0&&e.createElement(l,{flexDirection:"column",marginLeft:2},u))};export{C as Task,T as TaskList};