-
Notifications
You must be signed in to change notification settings - Fork 9
/
CmdLineOutput.vbs
105 lines (87 loc) · 2.96 KB
/
CmdLineOutput.vbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
option explicit
' Print
' (c) 2019 qiuqiu
' Called by Directory Opus to initialize the script
Const clRed = "#FF0000"
Const clBule = "#0000FF"
Const clGreen = "#00B200"
Const clBlack = "#000000"
Const clWrite = "#FFFFFF"
Const clPurple = "#8000FF"
Const O_text = "<Font Color={0}>{1}: {2}</Font>"
Function OnInit(initData)
With initData
.name = "Output messages."
.version = "1.0"
.copyright = "(c) 2019 qiuqiu"
.desc = "Displays messages in log window." & vbCRLF & "Example: debug type=test color=red text=hello world!"
.url = "http://script.dopus.net/"
.default_enable = true
.min_version = "11.0"
Dim cmd
Set cmd = .AddCommand
With .AddCommand 'cmd
.name = "ECHO"
.method = "OnECHO"
.desc = initData.desc
.label = "Debug"
.template = "TYPE/K[Debug,Error,Info,Test],COLOR/O[Red,Bule,Green,Black,Write,Purple,#123456],TEXT/R[Output debug messages.]"
.hide = false
.icon = "Logs"
End With
End With
End Function
' Implement the Print command
Function OnECHO(scriptCmdData)
Dim Cmd_Args, Arg_Color, Arg_Type, Out_Type, Out_Text, Out_Color
Out_Color = clBlack
Set Cmd_Args = scriptCmdData.Func.Args.got_arg
If Cmd_Args.Type And Cmd_Args.Text Then
Arg_Type = scriptCmdData.Func.Args.Type
Out_Text = scriptCmdData.Func.Args.Text
Select Case UCase(Arg_Type)
Case "DEBUG", "D"
Out_Color = clBule
Out_Type = "Debug"
Case "ERROR", "E"
Out_Color = clRed
Out_Type = "Error"
Case "INFO", "I"
Out_Color = clGreen
Out_Type = "Info"
Case Else
If Cmd_Args.Color Then
Arg_Color = scriptCmdData.Func.Args.Color
select case UCase(Arg_Color)
case "RED" : Out_Color = clRed
case "BULE" : Out_Color = clBule
case "GREEN" : Out_Color = clGreen
case "BLACK" : Out_Color = clBlack
case "WRITE" : Out_Color = clWrite
case "PURPLE" : Out_Color = clPurple
case else
if (Left(Arg_Color, 1) = "#") And (Len(Arg_Color) = 7)Then
Out_Color = scriptCmdData.Func.Args.Color
end if
end select
Else
Out_Color = clBlack
End If
Out_Type = Arg_Type
End Select
DOpus.Output StringFormat(O_text, array(Out_Color, Out_Type, Out_Text))
End If
End Function
Function StringFormat(ByVal SourceString, Arguments)
Dim objRegEx ' regular expression object
Dim objMatch ' regular expression match object
Dim strReturn ' the string that will be returned
Set objRegEx = New RegExp
objRegEx.Global = True
objRegEx.Pattern = "(\{)(\d)(\})"
strReturn = SourceString
For Each objMatch In objRegEx.Execute(SourceString)
strReturn = Replace(strReturn, objMatch.Value, Arguments(CInt(objMatch.SubMatches(1))))
Next
StringFormat = strReturn
End Function