openzca 0.1.32 → 0.1.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +76 -12
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -706,30 +706,79 @@ function asThreadType(groupFlag) {
|
|
|
706
706
|
return groupFlag ? ThreadType.Group : ThreadType.User;
|
|
707
707
|
}
|
|
708
708
|
function parseTextStyles(input) {
|
|
709
|
-
const
|
|
709
|
+
const allStyles = [];
|
|
710
|
+
const lines = input.split("\n");
|
|
711
|
+
const lineStyles = [];
|
|
712
|
+
const processedLines = [];
|
|
713
|
+
for (let i = 0; i < lines.length; i++) {
|
|
714
|
+
const line = lines[i];
|
|
715
|
+
const headingMatch = line.match(/^(#{1,3})\s(.*)$/);
|
|
716
|
+
if (headingMatch) {
|
|
717
|
+
const level = headingMatch[1].length;
|
|
718
|
+
lineStyles.push({ lineIndex: i, style: TextStyle.Bold });
|
|
719
|
+
if (level === 1) lineStyles.push({ lineIndex: i, style: TextStyle.Big });
|
|
720
|
+
if (level === 3) lineStyles.push({ lineIndex: i, style: TextStyle.Small });
|
|
721
|
+
processedLines.push(headingMatch[2]);
|
|
722
|
+
continue;
|
|
723
|
+
}
|
|
724
|
+
const olMatch = line.match(/^(\d+)\.\s(.*)$/);
|
|
725
|
+
if (olMatch) {
|
|
726
|
+
lineStyles.push({ lineIndex: i, style: TextStyle.OrderedList });
|
|
727
|
+
processedLines.push(olMatch[2]);
|
|
728
|
+
continue;
|
|
729
|
+
}
|
|
730
|
+
const ulMatch = line.match(/^-\s(.*)$/);
|
|
731
|
+
if (ulMatch) {
|
|
732
|
+
lineStyles.push({ lineIndex: i, style: TextStyle.UnorderedList });
|
|
733
|
+
processedLines.push(ulMatch[1]);
|
|
734
|
+
continue;
|
|
735
|
+
}
|
|
736
|
+
const indentMatch = line.match(/^(>+)\s?(.*)$/);
|
|
737
|
+
if (indentMatch) {
|
|
738
|
+
lineStyles.push({ lineIndex: i, style: TextStyle.Indent, indentSize: indentMatch[1].length });
|
|
739
|
+
processedLines.push(indentMatch[2]);
|
|
740
|
+
continue;
|
|
741
|
+
}
|
|
742
|
+
processedLines.push(line);
|
|
743
|
+
}
|
|
744
|
+
const inlineInput = processedLines.join("\n");
|
|
745
|
+
const colorMap = {
|
|
746
|
+
red: TextStyle.Red,
|
|
747
|
+
orange: TextStyle.Orange,
|
|
748
|
+
yellow: TextStyle.Yellow,
|
|
749
|
+
green: TextStyle.Green,
|
|
750
|
+
small: TextStyle.Small,
|
|
751
|
+
big: TextStyle.Big
|
|
752
|
+
};
|
|
753
|
+
const tagNames = Object.keys(colorMap).join("|");
|
|
710
754
|
const markers = [
|
|
711
|
-
|
|
755
|
+
// Tags first so inner markdown markers are preserved for subsequent passes
|
|
756
|
+
{ pattern: new RegExp(`\\{(${tagNames})\\}(.+?)\\{/\\1\\}`, "g"), style: null },
|
|
757
|
+
{ pattern: /\*\*\*(.+?)\*\*\*/g, style: TextStyle.Bold, extraStyles: [TextStyle.Italic] },
|
|
712
758
|
{ pattern: /\*\*(.+?)\*\*/g, style: TextStyle.Bold },
|
|
713
759
|
{ pattern: /\*(.+?)\*/g, style: TextStyle.Italic },
|
|
714
760
|
{ pattern: /__(.+?)__/g, style: TextStyle.Underline },
|
|
715
761
|
{ pattern: /~~(.+?)~~/g, style: TextStyle.StrikeThrough }
|
|
716
762
|
];
|
|
717
|
-
let segments = [{ text:
|
|
718
|
-
for (const
|
|
763
|
+
let segments = [{ text: inlineInput, styles: [] }];
|
|
764
|
+
for (const marker of markers) {
|
|
719
765
|
const next = [];
|
|
720
766
|
for (const seg of segments) {
|
|
721
767
|
let lastIndex = 0;
|
|
722
|
-
const regex = new RegExp(pattern.source, pattern.flags);
|
|
768
|
+
const regex = new RegExp(marker.pattern.source, marker.pattern.flags);
|
|
723
769
|
let m;
|
|
724
770
|
while ((m = regex.exec(seg.text)) !== null) {
|
|
725
771
|
if (m.index > lastIndex) {
|
|
726
772
|
next.push({ text: seg.text.slice(lastIndex, m.index), styles: [...seg.styles] });
|
|
727
773
|
}
|
|
728
|
-
const
|
|
729
|
-
|
|
730
|
-
|
|
774
|
+
const isTagPattern = marker.style === null;
|
|
775
|
+
const innerText = isTagPattern ? m[2] : m[1];
|
|
776
|
+
const resolvedStyle = isTagPattern ? colorMap[m[1]] : marker.style;
|
|
777
|
+
const combined = [...seg.styles, resolvedStyle];
|
|
778
|
+
if (marker.extraStyles) {
|
|
779
|
+
combined.push(...marker.extraStyles);
|
|
731
780
|
}
|
|
732
|
-
next.push({ text:
|
|
781
|
+
next.push({ text: innerText, styles: combined });
|
|
733
782
|
lastIndex = regex.lastIndex;
|
|
734
783
|
}
|
|
735
784
|
if (lastIndex < seg.text.length) {
|
|
@@ -745,10 +794,25 @@ function parseTextStyles(input) {
|
|
|
745
794
|
const start = plainText.length;
|
|
746
795
|
plainText += seg.text;
|
|
747
796
|
for (const st of seg.styles) {
|
|
748
|
-
|
|
797
|
+
allStyles.push({ start, len: seg.text.length, st });
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
const finalLines = plainText.split("\n");
|
|
801
|
+
let offset = 0;
|
|
802
|
+
for (let i = 0; i < finalLines.length; i++) {
|
|
803
|
+
const lineLen = finalLines[i].length;
|
|
804
|
+
for (const ls of lineStyles) {
|
|
805
|
+
if (ls.lineIndex === i && lineLen > 0) {
|
|
806
|
+
if (ls.style === TextStyle.Indent) {
|
|
807
|
+
allStyles.push({ start: offset, len: lineLen, st: TextStyle.Indent, indentSize: ls.indentSize });
|
|
808
|
+
} else {
|
|
809
|
+
allStyles.push({ start: offset, len: lineLen, st: ls.style });
|
|
810
|
+
}
|
|
811
|
+
}
|
|
749
812
|
}
|
|
813
|
+
offset += lineLen + 1;
|
|
750
814
|
}
|
|
751
|
-
return { text: plainText, styles };
|
|
815
|
+
return { text: plainText, styles: allStyles };
|
|
752
816
|
}
|
|
753
817
|
function parseBooleanFromEnv(name, fallback) {
|
|
754
818
|
const raw = process.env[name]?.trim();
|
|
@@ -2933,7 +2997,7 @@ auth.command("cache-clear").description("Clear local cache").action(
|
|
|
2933
2997
|
})
|
|
2934
2998
|
);
|
|
2935
2999
|
var msg = program.command("msg").description("Messaging commands");
|
|
2936
|
-
msg.command("send <threadId> <message>").option("-g, --group", "Send to group").option("--raw", "Send raw text without parsing formatting markers").description("Send text message (
|
|
3000
|
+
msg.command("send <threadId> <message>").option("-g, --group", "Send to group").option("--raw", "Send raw text without parsing formatting markers").description("Send text message with formatting (**bold** *italic* __underline__ ~~strike~~ {red}color{/red} {big}size{/big} lists indents)").action(
|
|
2937
3001
|
wrapAction(async (threadId, message, opts, command) => {
|
|
2938
3002
|
const { api } = await requireApi(command);
|
|
2939
3003
|
if (opts.raw) {
|