diff --git a/index.js b/index.js index ebd6158..af30320 100755 --- a/index.js +++ b/index.js @@ -4,5 +4,5 @@ var a2=Object.create;var Y=Object.defineProperty,l2=Object.defineProperties,c2=O `)+n,o=r+1,r=e.indexOf(` `,o)}while(r!==-1);return s+=e.substr(o),s};L0.exports={stringReplaceAll:R2,stringEncaseCRLFWithFirstIndex:S2}});var $0=w((se,P0)=>{"use strict";var A2=/(?:\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi,I0=/(?:^|\.)(\w+)(?:\(([^)]*)\))?/g,_2=/^(['"])((?:\\.|(?!\1)[^\\])*)\1$/,T2=/\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.)|([^\\])/gi,B2=new Map([["n",` `],["r","\r"],["t"," "],["b","\b"],["f","\f"],["v","\v"],["0","\0"],["\\","\\"],["e",""],["a","\x07"]]);function F0(e){let t=e[0]==="u",n=e[1]==="{";return t&&!n&&e.length===5||e[0]==="x"&&e.length===3?String.fromCharCode(parseInt(e.slice(1),16)):t&&n?String.fromCodePoint(parseInt(e.slice(2,-1),16)):B2.get(e)||e}function L2(e,t){let n=[],r=t.trim().split(/\s*,\s*/g),o;for(let s of r){let a=Number(s);if(!Number.isNaN(a))n.push(a);else if(o=s.match(_2))n.push(o[2].replace(T2,(c,l,u)=>l?F0(l):u));else throw new Error(`Invalid Chalk template style argument: ${s} (in style '${e}')`)}return n}function j2(e){I0.lastIndex=0;let t=[],n;for(;(n=I0.exec(e))!==null;){let r=n[1];if(n[2]){let o=L2(r,n[2]);t.push([r].concat(o))}else t.push([r])}return t}function N0(e,t){let n={};for(let o of t)for(let s of o.styles)n[s[0]]=o.inverse?null:s.slice(1);let r=e;for(let[o,s]of Object.entries(n))if(!!Array.isArray(s)){if(!(o in r))throw new Error(`Unknown Chalk style: ${o}`);r=s.length>0?r[o](...s):r[o]}return r}P0.exports=(e,t)=>{let n=[],r=[],o=[];if(t.replace(A2,(s,a,c,l,u,b)=>{if(a)o.push(F0(a));else if(l){let f=o.join("");o=[],r.push(n.length===0?f:N0(e,n)(f)),n.push({inverse:c,styles:j2(l)})}else if(u){if(n.length===0)throw new Error("Found extraneous } in Chalk template literal");r.push(N0(e,n)(o.join(""))),o=[],n.pop()}else o.push(b)}),r.push(o.join("")),n.length>0){let s=`Chalk template literal is missing ${n.length} closing bracket${n.length===1?"":"s"} (\`}\`)`;throw new Error(s)}return r.join("")}});var n0=w((ae,U0)=>{"use strict";var j=R0(),{stdout:Z,stderr:Q}=B0(),{stringReplaceAll:I2,stringEncaseCRLFWithFirstIndex:F2}=j0(),Y0=["ansi","ansi","ansi256","ansi16m"],T=Object.create(null),N2=(e,t={})=>{if(t.level>3||t.level<0)throw new Error("The `level` option should be an integer from 0 to 3");let n=Z?Z.level:0;e.level=t.level===void 0?n:t.level},D0=class{constructor(t){return q0(t)}},q0=e=>{let t={};return N2(t,e),t.template=(...n)=>Y2(t.template,...n),Object.setPrototypeOf(t,H.prototype),Object.setPrototypeOf(t.template,t),t.template.constructor=()=>{throw new Error("`chalk.constructor()` is deprecated. Use `new chalk.Instance()` instead.")},t.template.Instance=D0,t.template};function H(e){return q0(e)}for(let[e,t]of Object.entries(j))T[e]={get(){let n=U(this,e0(t.open,t.close,this._styler),this._isEmpty);return Object.defineProperty(this,e,{value:n}),n}};T.visible={get(){let e=U(this,this._styler,!0);return Object.defineProperty(this,"visible",{value:e}),e}};var H0=["rgb","hex","keyword","hsl","hsv","hwb","ansi","ansi256"];for(let e of H0)T[e]={get(){let{level:t}=this;return function(...n){let r=e0(j.color[Y0[t]][e](...n),j.color.close,this._styler);return U(this,r,this._isEmpty)}}};for(let e of H0){let t="bg"+e[0].toUpperCase()+e.slice(1);T[t]={get(){let{level:n}=this;return function(...r){let o=e0(j.bgColor[Y0[n]][e](...r),j.bgColor.close,this._styler);return U(this,o,this._isEmpty)}}}}var P2=Object.defineProperties(()=>{},d0(h0({},T),{level:{enumerable:!0,get(){return this._generator.level},set(e){this._generator.level=e}}})),e0=(e,t,n)=>{let r,o;return n===void 0?(r=e,o=t):(r=n.openAll+e,o=t+n.closeAll),{open:e,close:t,openAll:r,closeAll:o,parent:n}},U=(e,t,n)=>{let r=(...o)=>$2(r,o.length===1?""+o[0]:o.join(" "));return r.__proto__=P2,r._generator=e,r._styler=t,r._isEmpty=n,r},$2=(e,t)=>{if(e.level<=0||!t)return e._isEmpty?"":t;let n=e._styler;if(n===void 0)return t;let{openAll:r,closeAll:o}=n;if(t.indexOf("")!==-1)for(;n!==void 0;)t=I2(t,n.close,n.open),n=n.parent;let s=t.indexOf(` -`);return s!==-1&&(t=F2(t,o,r,s)),r+t+o},t0,Y2=(e,...t)=>{let[n]=t;if(!Array.isArray(n))return t.join(" ");let r=t.slice(1),o=[n.raw[0]];for(let s=1;s2100)return l;for(let f=1900;f<=2100;f++){let d=D2(f);if(s-=d,s<=0){l.year=f,s+=d;break}}a=Q0(l.year),c=s0(l.year);for(let f=0;f0&&f>=c&&(l.leap=f===c,l.month-=1);break}if(l.custom=Z0[b]||"",u){let f=u.slice(t*4,(t+1)*4);+f.slice(0,2)===n?l.solarTerms=r0[t*2]:+f.slice(2)===n&&(l.solarTerms=r0[t*2+1])}return l.festival=J0[`${t+1}.${n}`]||"",l.leap||(l.month===11&&l.day===a.pop()?(l.festival=F["12.30"],l.lunarFestival=F["12.30"]):(l.festival=F[`${l.month+1}.${l.day}`]||l.festival,l.lunarFestival=F[`${l.month+1}.${l.day}`]||"")),l.yearCN=a0(l.year),l.monthCN=(l.leap>0?"\u95F0":"")+G0[l.month]+"\u6708",l.day<11?l.dayCN=v[0]+v[l.day]:l.day<20?l.dayCN=v[10]+v[l.day-10]:l.day===20?l.dayCN=v[2]+v[10]:l.day<30?l.dayCN=v[20]+v[l.day-20]:l.day===30&&(l.dayCN=v[3]+v[10]),l.short=l.festival?l.festival:l.solarTerms?l.solarTerms:l.day===1?l.monthCN:l.dayCN,l}function D2(e){var t=Q0(e);return t.reduce((n,r)=>n+=r,0)}function s0(e){var t=V[e-1900];return t&15}function q2(e){var t=V[e-1900],n=s0(e);return n>0?t&983040?30:29:0}function Q0(e){var t=V[e-1900],n=s0(e),r=q2(e),o=[];for(let s=32768;s>8;s>>=1)o.push(t&s?30:29);return n>0&&o.splice(n,0,r),o}function a0(e){var t=(e-3)%10,n=(e-3)%12;return t=t===0?10:t,n=n===0?12:n,K0[t-1]+W0[n-1]+z0[(e-4)%12]+"\u5E74"}var H2=["\u65E5","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D"].map((e,t)=>(e="\u661F\u671F"+e,(t===0||t===6)&&(e=h.default.red(e))," "+e+" "+h.default.grey("|"))),P=h.default.grey("|"),fe=h.default.grey("|"+(" ".repeat(10)+"|").repeat(7));function e2(e="",t=" "){return h.default.grey(e+(t.repeat(10)+"|").repeat(7))}function t2(){var e=new Date;return[e.getFullYear(),e.getMonth()]}function n2(e,t){return new Date(e,t+1,0).getDate()}function r2(e,t,n){return new Date(e,t,n||1).getDay()}function U2({year:e,month:t,day:n},r){return r.year===e&&r.month===t&&r.day===n}function V2(){var e=new Date;return{year:e.getFullYear(),month:e.getMonth(),day:e.getDate()}}function G2(e,t){var n=n2(e,t-1),r=n2(e,t),o=1-r2(e,t),s=0,a=V2(),c=[],l,u,b,f;o<1&&(l=e,u=t-1,u<0&&(u=11,l--));for(let d=o;d<=r;d++){let k={day:d<1?n- -d:(d+"").padStart(2,"0")},R;if(d>0){let c0=r2(e,t,d);R=G(e,t,d),k.weekend=c0===0||c0===6,k.picked=!!U2({year:e,month:t,day:d},a),k.highlight=!!R.festival||!!R.solarTerms}else R=G(l,u,n+d),k.grey=1;k.lunar=R.short,k.custom=R.custom,c.push(k)}s=c.length%7,s=s>0?7-s:0,s>0&&(b=e,f=t+1,f>11&&(f=0,b++));for(let d=1;d<=s;d++){let k=G(b,f,d);c.push({day:(d+"").padStart(2,"0"),lunar:k.short,custom:k.custom,grey:1})}return c}function z2(e,t){var n=`${e}\u5E74${t+1}\u6708${" ".repeat(10)}${a0(e,t)}`;n=h.default.grey("| ")+h.default.cyan(n)+" ".repeat(71-n.length-2)+h.default.grey("|"),console.log(h.default.grey(" "+"_".repeat(76))),console.log(h.default.grey("|"+" ".repeat(76)+"|")),console.log(n),console.log(h.default.grey("|"+"_".repeat(76)+"|")),console.log(e2("|")),console.log(h.default.grey("|")+H2.join("")),console.log(e2("|","_"))}function K2(e,t){var n=G2(e,t),r=0;for(let o=0;o<3*Math.ceil(n.length/7)+1;o++){let s="";for(let a=0;a<7;a++){let c=n[r+a];if(!c)break;switch(a===0&&(s+=P),o%3){case 0:o===0?s+=h.default.grey(" ".repeat(10)+"|"):(s+=h.default.grey("-".repeat(a===6?10:11)+(a===6?"|":"")),a===6&&(r+=7));break;case 1:let l=" ";c.custom&&(l=h.default.blue(c.custom)),c.picked?s+=" "+h.default.bgBlue.whiteBright.bold(" "+c.day+" ")+l+P:(c.grey?c.day=h.default.grey(c.day):c.weekend?c.day=h.default.redBright.bold(c.day):c.day=h.default.whiteBright.bold(c.day),s+=" ".repeat(4)+c.day+" "+l+P);break;case 2:let u=5;c.lunar&&(u=(10-c.lunar.length*2)/2-2),c.picked?s+=" "+h.default.bgBlue.white.bold(" ".repeat(u)+c.lunar+" ".repeat(u))+" "+P:(c.lunar&&(c.lunar=c.highlight?h.default.cyan.dim(c.lunar):c.weekend?h.default.red.dim(c.lunar):h.default.grey(c.lunar)),s+=" ".repeat(u+2)+c.lunar+" ".repeat(u+2)+P);break}}console.log(s)}console.log("")}function M(e,t){z2(e,t),K2(e,t)}var s2="1.2.0",E=process.argv.slice(2),$=E.shift(),[y,p]=t2();function l0(e){for(let t=0;t<12;t++)M(e,t)}function g(...e){e[0]=e[0].padEnd(20," "),e.length>1&&e.splice(1,0," - "),console.log.apply(null,e)}function W2(){g("=".repeat(64)),g(`\u7EC8\u7AEF\u7248\u4E07\u5E74\u5386 v${s2}, \u4F5C\u8005: \u5B87\u5929`),g("=".repeat(64)),g("\u7528\u6CD5: cal [command] args..."),g("Commands:"),g(" -y {year}","\u6253\u5370\u6307\u5B9A\u5E74\u4EFD\u7684\u65E5\u5386"),g(" -m","\u6253\u5370\u6307\u5B9A\u6708\u4EFD\u7684\u65E5\u5386"),g(" -c","\u5BFC\u5165\u81EA\u5B9A\u4E49\u4F11\u5047\u65E5, \u5FC5\u987B\u662F\u6807\u51C6json\u683C\u5F0F, \u8BED\u6CD5\u770B\u4E0B\u9762\u7684\u793A\u4F8B"),g(" -h","\u67E5\u770B\u5E2E\u52A9\u6587\u6863"),g(" -v",`\u67E5\u770B\u7A0B\u5E8F\u7684\u7248\u672C +`);return s!==-1&&(t=F2(t,o,r,s)),r+t+o},t0,Y2=(e,...t)=>{let[n]=t;if(!Array.isArray(n))return t.join(" ");let r=t.slice(1),o=[n.raw[0]];for(let s=1;s2100)return l;for(let f=1900;f<=2100;f++){let d=D2(f);if(s-=d,s<=0){l.year=f,s+=d;break}}a=Q0(l.year),c=s0(l.year);for(let f=0;f0&&f>=c&&(l.leap=f===c,l.month-=1);break}if(l.custom=Z0[b]||"",u){let f=u.slice(t*4,(t+1)*4);+f.slice(0,2)===n?l.solarTerms=r0[t*2]:+f.slice(2)===n&&(l.solarTerms=r0[t*2+1])}return l.festival=J0[`${t+1}.${n}`]||"",l.leap||(l.month===11&&l.day===a.pop()?(l.festival=F["12.30"],l.lunarFestival=F["12.30"]):(l.festival=F[`${l.month+1}.${l.day}`]||l.festival,l.lunarFestival=F[`${l.month+1}.${l.day}`]||"")),l.yearCN=a0(l.year),l.monthCN=(l.leap>0?"\u95F0":"")+G0[l.month]+"\u6708",l.day<11?l.dayCN=v[0]+v[l.day]:l.day<20?l.dayCN=v[10]+v[l.day-10]:l.day===20?l.dayCN=v[2]+v[10]:l.day<30?l.dayCN=v[20]+v[l.day-20]:l.day===30&&(l.dayCN=v[3]+v[10]),l.short=l.festival?l.festival:l.solarTerms?l.solarTerms:l.day===1?l.monthCN:l.dayCN,l}function D2(e){var t=Q0(e);return t.reduce((n,r)=>n+=r,0)}function s0(e){var t=V[e-1900];return t&15}function q2(e){var t=V[e-1900],n=s0(e);return n>0?t&983040?30:29:0}function Q0(e){var t=V[e-1900],n=s0(e),r=q2(e),o=[];for(let s=32768;s>8;s>>=1)o.push(t&s?30:29);return n>0&&o.splice(n,0,r),o}function a0(e){var t=(e-3)%10,n=(e-3)%12;return t=t===0?10:t,n=n===0?12:n,K0[t-1]+W0[n-1]+z0[(e-4)%12]+"\u5E74"}var H2=["\u65E5","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D"].map((e,t)=>(e="\u661F\u671F"+e,(t===0||t===6)&&(e=h.default.red(e))," "+e+" "+h.default.grey("|"))),P=h.default.grey("|"),fe=h.default.grey("|"+(" ".repeat(10)+"|").repeat(7));function e2(e="",t=" "){return h.default.grey(e+(t.repeat(10)+"|").repeat(7))}function t2(){var e=new Date;return[e.getFullYear(),e.getMonth()]}function n2(e,t){return new Date(e,t+1,0).getDate()}function r2(e,t,n){return new Date(e,t,n||1).getDay()}function U2({year:e,month:t,day:n},r){return r.year===e&&r.month===t&&r.day===n}function V2(){var e=new Date;return{year:e.getFullYear(),month:e.getMonth(),day:e.getDate()}}function G2(e,t){var n=n2(e,t-1),r=n2(e,t),o=1-r2(e,t),s=0,a=V2(),c=[],l,u,b,f;o<1&&(l=e,u=t-1,u<0&&(u=11,l--));for(let d=o;d<=r;d++){let k={day:d<1?n- -d:(d+"").padStart(2,"0")},R;if(d>0){let c0=r2(e,t,d);R=G(e,t,d),k.weekend=c0===0||c0===6,k.picked=!!U2({year:e,month:t,day:d},a),k.highlight=!!R.festival||!!R.solarTerms}else R=G(l,u,n+d),k.grey=1;k.lunar=R.short,k.custom=R.custom,c.push(k)}s=c.length%7,s=s>0?7-s:0,s>0&&(b=e,f=t+1,f>11&&(f=0,b++));for(let d=1;d<=s;d++){let k=G(b,f,d);c.push({day:(d+"").padStart(2,"0"),lunar:k.short,custom:k.custom,grey:1})}return c}function z2(e,t){var n=`${e}\u5E74${t+1}\u6708${" ".repeat(10)}${a0(e,t)}`;n=h.default.grey("| ")+h.default.cyan(n)+" ".repeat(71-n.length-2)+h.default.grey("|"),console.log(h.default.grey(" "+"_".repeat(76))),console.log(h.default.grey("|"+" ".repeat(76)+"|")),console.log(n),console.log(h.default.grey("|"+"_".repeat(76)+"|")),console.log(e2("|")),console.log(h.default.grey("|")+H2.join("")),console.log(e2("|","_"))}function K2(e,t){var n=G2(e,t),r=0;for(let o=0;o<3*Math.ceil(n.length/7)+1;o++){let s="";for(let a=0;a<7;a++){let c=n[r+a];if(!c)break;switch(a===0&&(s+=P),o%3){case 0:o===0?s+=h.default.grey(" ".repeat(10)+"|"):(s+=h.default.grey("-".repeat(a===6?10:11)+(a===6?"|":"")),a===6&&(r+=7));break;case 1:let l=" ";c.custom&&(c.custom==="\u73ED"?l=h.default.red(c.custom):l=h.default.green.dim(c.custom)),c.picked?s+=" "+h.default.bgBlue.whiteBright.bold(" "+c.day+" ")+l+P:(c.grey?c.day=h.default.grey(c.day):c.weekend?c.day=h.default.redBright.bold(c.day):c.day=h.default.whiteBright.bold(c.day),s+=" ".repeat(4)+c.day+" "+l+P);break;case 2:let u=5;c.lunar&&(u=(10-c.lunar.length*2)/2-2),c.picked?s+=" "+h.default.bgBlue.white.bold(" ".repeat(u)+c.lunar+" ".repeat(u))+" "+P:(c.lunar&&(c.lunar=c.highlight?h.default.cyan.dim(c.lunar):c.weekend?h.default.red.dim(c.lunar):h.default.grey(c.lunar)),s+=" ".repeat(u+2)+c.lunar+" ".repeat(u+2)+P);break}}console.log(s)}console.log("")}function M(e,t){z2(e,t),K2(e,t)}var s2="1.2.0",E=process.argv.slice(2),$=E.shift(),[y,p]=t2();function l0(e){for(let t=0;t<12;t++)M(e,t)}function g(...e){e[0]=e[0].padEnd(20," "),e.length>1&&e.splice(1,0," - "),console.log.apply(null,e)}function W2(){g("=".repeat(64)),g(`\u7EC8\u7AEF\u7248\u4E07\u5E74\u5386 v${s2}, \u4F5C\u8005: \u5B87\u5929`),g("=".repeat(64)),g("\u7528\u6CD5: cal [command] args..."),g("Commands:"),g(" -y {year}","\u6253\u5370\u6307\u5B9A\u5E74\u4EFD\u7684\u65E5\u5386"),g(" -m","\u6253\u5370\u6307\u5B9A\u6708\u4EFD\u7684\u65E5\u5386"),g(" -c","\u5BFC\u5165\u81EA\u5B9A\u4E49\u4F11\u5047\u65E5, \u5FC5\u987B\u662F\u6807\u51C6json\u683C\u5F0F, \u8BED\u6CD5\u770B\u4E0B\u9762\u7684\u793A\u4F8B"),g(" -h","\u67E5\u770B\u5E2E\u52A9\u6587\u6863"),g(" -v",`\u67E5\u770B\u7A0B\u5E8F\u7684\u7248\u672C `),g("\u793A\u4F8B: "),g(" cal "+O.default.grey("# \u4E0D\u5E26\u53C2\u6570\u6253\u5370\u5F53\u524D\u5E74\u6708")),g(" cal -y "+O.default.grey("# -y \u4E0D\u63A5\u53C2\u6570, \u6253\u5370\u5F53\u524D\u5E74\u7684\u6240\u6709\u6708\u4EFD")),g(" cal -y 2000 "+O.default.grey("# \u6253\u5370\u6307\u5B9A\u5E74\u4EFD\u7684\u6240\u6709\u6708\u4EFD")),g(" cal -y 2021 5 "+O.default.grey("# \u6253\u5370\u6307\u5B9A\u5E74\u4EFD, \u6307\u5B9A\u6708\u4EFD")),g(" cal -y 2000 -m 3 "+O.default.grey("# \u540C\u4E0A")),g(" cal -m 5 "+O.default.grey("# \u6253\u5370\u5F53\u524D\u5E74\u4EFD\u7684 \u6307\u5B9A\u6708\u4EFD")),g(' cal -c {"2021.12.11":"\u73ED","2021.12.12":"\u4F11"} '+O.default.grey("# \u5BFC\u5165\u81EA\u5B9A\u4E49\u4F11\u5047\u65E5")),process.exit()}switch($){case"-y":switch(E.length){case 0:l0(y);break;case 1:case 2:y=+E.shift(),p=+E.shift(),y===y?p<13&&p>0?M(y,p-1):l0(y):console.log("-y \u53C2\u6570\u5F02\u5E38");break;case 3:$=E.shift(),p=+E.shift(),$==="-m"&&p<13&&p>0?M(y,p-1):console.log("-m \u53C2\u6570\u5F02\u5E38");break;default:console.log("-y \u53C2\u6570\u5F02\u5E38");break}break;case"-m":p=+E.shift(),p<13&&p>0?M(y,p-1):console.log("-m \u53C2\u6570\u5F02\u5E38");break;case"-v":g(s2);break;case"-h":W2();break;case"-c":let e=E.shift();if(e)try{JSON.parse(e),o2.default.writeFileSync(N,e),console.log("\u5BFC\u5165\u6210\u529F")}catch{console.log("\u9519\u8BEF\u7684json\u6570\u636E")}else console.log("\u5BFC\u5165\u7684\u6570\u636E\u4E3A\u7A7A");break;default:$?(y=+$,p=+E.shift(),y===y?p<13&&p>0?M(y,p-1):l0(y):console.log("\u53C2\u6570\u5F02\u5E38")):M(y,p);break}process.exit(); diff --git a/package.json b/package.json index 5512776..39e627e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "bash-calendar", "description": "终端版万年历", - "version": "1.2.0", + "version": "1.2.1", "author": "yutent ", "bin": { "calendar": "index.js", diff --git a/src/calendar.js b/src/calendar.js index 18d9ae8..95ae401 100644 --- a/src/calendar.js +++ b/src/calendar.js @@ -164,7 +164,11 @@ function drawTbody(year, month) { case 1: let right = ' ' if (tmp.custom) { - right = chalk.blue(tmp.custom) + if (tmp.custom === '班') { + right = chalk.red(tmp.custom) + } else { + right = chalk.green.dim(tmp.custom) + } } if (tmp.picked) { tr += ' ' + chalk.bgBlue.whiteBright.bold(' ' + tmp.day + ' ') + right + VLINE