This repository was archived by the owner on Mar 11, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
69 lines (52 loc) · 1.76 KB
/
main.cpp
File metadata and controls
69 lines (52 loc) · 1.76 KB
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
import std;
import ConsoleHandler;
import BasicColors;
import UI;
import InputHandler;
import FileHandler;
import ClipboardHandler;
import SettingMap;
import String;
import ConsoleArgumentsAnalyzer;
import Exceptions;
import StringEncoder;
using namespace std;
using namespace NylteJ;
int main(int argc, char** argv)
{
ConsoleArguments arguments{ argc, argv };
if (arguments.HelpMode())
{
const auto exeName = arguments.ExePath().filename().replace_extension().string();
println("本程序可以通过命令行调用, 参数详解如下:"sv);
println("1. \"-o\" / \"--open\" 表示打开, 后接要打开的文件路径"sv);
println("2. \"-e\" / \"--encoding\" 表示编码, 后接编码名称"sv);
println(" - 有容错设计, 比如 \"utf-8\", \"UTF-8\", \"UTF 8\", \"utf8\" 都能定位到 UTF-8"sv);
println("3. \"-h\" / \"--help\" / \"/?\" 可以输出帮助, 会覆盖其它一切参数"sv);
println("4. 只需要指定打开文件路径时, 可以直接作为参数附加, 无需带 \"-o\" / \"--open\""sv);
println("5. 示例: "sv);
println(" 1. {} 1.txt"sv, exeName);
println(" 2. {} -o 1.txt -e UTF-8"sv, exeName);
println(" 3. {} --encoding \"gb 2312\" -o 1.txt"sv, exeName);
println(" 4. {} /?"sv, exeName);
return 0;
}
ConsoleHandler console;
FileHandler file;
String str;
InputHandler inputHandler;
ClipboardHandler clipboardHandler;
SettingMap settings{};
if (arguments.OpenFilePath().has_value())
{
if (arguments.GetEncoding().has_value())
file.nowEncoding = arguments.GetEncoding().value();
try
{
file.OpenFile(arguments.OpenFilePath().value());
}
catch (FileOpenFailedException&) {}
}
UI ui{ console,str,inputHandler,file,clipboardHandler,settings };
console.MonitorInput(inputHandler);
}