├── .github
└── workflows
│ ├── build.yml
│ └── release.yml
├── .gitignore
├── .gitmodules
├── .golangci.yml
├── .goreleaser.yml
├── .pre-commit-config.yaml
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── app
├── gen.go
└── helper.go
├── build
├── termux-armv6.json
├── termux-armv7.json
├── termux-armv8.json
└── termux-build.sh
├── config-example.json
├── config-example.yaml
├── go.mod
├── go.sum
├── lua-api
└── lua.go
├── main.go
├── mud
├── iac.go
├── mud.go
└── scan.go
└── ui
├── console_stub.go
├── console_win.go
├── readline.go
└── ui.go
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | # vim: set softtabstop=2 tabstop=2 shiftwidth=2:
2 | name: Build
3 | on: [push, pull_request]
4 | jobs:
5 |
6 | build:
7 | name: Build
8 | runs-on: ubuntu-latest
9 | steps:
10 |
11 | - name: Set up Go
12 | uses: actions/setup-go@v1
13 | with:
14 | go-version: 1.13.6
15 |
16 | - name: Check out code into the Go module directory
17 | uses: actions/checkout@v1
18 |
19 | - name: Get dependencies
20 | run: |
21 | go get -v -t -d ./...
22 |
23 | - name: Generate code automatically
24 | run: go generate -v ./...
25 |
26 | - name: Build
27 | run: go build -v .
28 |
29 | - name: Set up Python
30 | uses: actions/setup-python@v2
31 |
32 | - name: Routine style checks
33 | uses: pre-commit/action@v2.0.0
34 | env:
35 | SKIP: golangci-lint
36 |
37 | - name: GolangCI-Lint
38 | uses: golangci/golangci-lint-action@v2
39 | with:
40 | version: v1.31
41 |
--------------------------------------------------------------------------------
/.github/workflows/release.yml:
--------------------------------------------------------------------------------
1 | # vim: set softtabstop=2 tabstop=2 shiftwidth=2:
2 | name: Release
3 | on:
4 | push:
5 | tags:
6 | - v*
7 |
8 | jobs:
9 | release:
10 | name: Release on GitHub
11 | runs-on: ubuntu-latest
12 | steps:
13 | - name: Set up Go
14 | uses: actions/setup-go@v1
15 | with:
16 | go-version: 1.13.6
17 |
18 | - name: Check out code
19 | uses: actions/checkout@v1
20 |
21 | - name: Set env via git describe
22 | run: echo GIT_DESCRIBE=$(git describe --always --tags --dirty) >> $GITHUB_ENV
23 |
24 | - name: Validates Goreleaser config
25 | uses: goreleaser/goreleaser-action@v1
26 | with:
27 | args: check
28 |
29 | - name: Set up Python ${{ matrix.python-version }}
30 | uses: actions/setup-python@v1
31 | with:
32 | python-version: ${{ matrix.python-version }}
33 |
34 | - name: Install termux-create-package
35 | run: pip3 install termux-create-package
36 |
37 | - name: Install jq
38 | run: sudo apt-get install jq
39 |
40 | - name: Create release on GitHub
41 | uses: goreleaser/goreleaser-action@v1
42 | with:
43 | args: release
44 | env:
45 | GITHUB_TOKEN: ${{secrets.GORELEASER_GITHUB_TOKEN}}
46 |
47 | - name: Upload termux package to GitHub
48 | run: bash build/termux-build.sh
49 | env:
50 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
51 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | go-mud*
2 | dist/
3 | config.yaml
4 | config.json
5 | log/*
6 | out*
7 | *.log
8 | tmp/*
9 |
10 | app/version.go
11 |
12 | .DS_Store
13 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "lua"]
2 | path = lua
3 | url = https://github.com/dzpao/lua-mud-robots.git
4 |
--------------------------------------------------------------------------------
/.golangci.yml:
--------------------------------------------------------------------------------
1 | linters:
2 | enable-all: true
3 | disable:
4 | # 因为只有两行语句的 case 语句里面强制要求 return 语句换行会让整个 switch 很分裂。
5 | - wsl
6 | - nlreturn
7 | # 因为连 1 都算 magic number 的话,许多循环就没法写了。
8 | # https://github.com/tommy-muehle/go-mnd/issues/3
9 | - gomnd
10 | # 有些情况下错误不可避免:
11 | # https://github.com/alexkohler/dogsled/issues/2
12 | - dogsled
13 | # V1.0 之前有 TODO/FIXME 很正常吧。
14 | - godox
15 | # 有些情况下错误不可避免:
16 | # https://github.com/mvdan/unparam/issues/43
17 | - unparam
18 | # 下面这两个 checker 太过激进,并不认同。
19 | - gochecknoglobals
20 | - gochecknoinits
21 | # godot 要求注释必须以句号结尾,然而并不支持中文句号,放弃。
22 | - godot
23 |
24 | linters-settings:
25 | errcheck:
26 | check-type-assertions: true
27 | ignore: '[FS]?[Pp]rint(|f|ln)|Write'
28 | exhaustive:
29 | default-signifies-exhaustive: true
30 | gci:
31 | local-prefixes: github.com/mudclient/go-mud
32 |
--------------------------------------------------------------------------------
/.goreleaser.yml:
--------------------------------------------------------------------------------
1 | # vim: set softtabstop=2 tabstop=2 shiftwidth=2:
2 | before:
3 | hooks:
4 | - go generate ./...
5 |
6 | builds:
7 | - env:
8 | - CGO_ENABLED=0
9 | flags:
10 | - -trimpath
11 | ldflags:
12 | - -s -w
13 | goos:
14 | - linux
15 | - darwin
16 | - windows
17 | goarch:
18 | - 386
19 | - amd64
20 | - arm
21 | - arm64
22 | goarm:
23 | - 6
24 | - 7
25 | ignore:
26 | - goos: darwin
27 | goarch: 386
28 |
29 | archives:
30 | - files:
31 | - LICENSE
32 | - README.md
33 | - config-example.json
34 | - config-example.yaml
35 | name_template: "{{ .ProjectName }}_{{ .Env.GIT_DESCRIBE }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
36 | wrap_in_directory: true
37 | format: tar.gz
38 | format_overrides:
39 | - goos: windows
40 | format: zip
41 | replacements:
42 | darwin: Darwin
43 | linux: Linux
44 | windows: Windows
45 | 386: i386
46 | amd64: x86_64
47 | arm: ARM
48 | arm64: ARMv8
49 |
50 | checksum:
51 | name_template: 'checksums.txt'
52 |
53 | snapshot:
54 | name_template: "snapshot-{{ .Env.GIT_DESCRIBE }}"
55 |
56 | release:
57 | prerelease: auto
58 | name_template: "{{ .Env.GIT_DESCRIBE }}"
59 |
60 | changelog:
61 | filters:
62 | exclude:
63 | - '^Docs:'
64 | - '^Test:'
65 | - '^(?i)WIP:'
66 | - typo
67 | - Merge pull request
68 | - Merge branch
69 |
70 | brews:
71 | - tap:
72 | owner: mudclient
73 | name: homebrew-tap
74 | folder: Formula
75 | commit_author:
76 | name: goreleaserbot
77 | email: goreleaser@carlosbecker.com
78 | description: "一个用 Go 语言开发的 MUD 客户端"
79 | homepage: "https://github.com/mudclient/go-mud"
80 | skip_upload: false
81 | install: |
82 | bin.install "go-mud"
83 |
--------------------------------------------------------------------------------
/.pre-commit-config.yaml:
--------------------------------------------------------------------------------
1 | repos:
2 | - repo: https://github.com/pre-commit/pre-commit-hooks
3 | rev: v3.2.0
4 | hooks:
5 | - id: check-case-conflict
6 | - id: check-byte-order-marker
7 | - id: check-added-large-files
8 | - id: check-symlinks
9 | - id: check-executables-have-shebangs
10 | - id: end-of-file-fixer
11 | - id: mixed-line-ending
12 | - id: trailing-whitespace
13 | - id: check-merge-conflict
14 | - id: detect-private-key
15 | - id: check-yaml
16 | - id: check-json
17 | - id: pretty-format-json
18 | args: [--no-sort-keys]
19 | - repo: https://github.com/dnephin/pre-commit-golang
20 | rev: v0.3.5
21 | hooks:
22 | - id: go-fmt
23 | - id: go-vet
24 | - id: go-build
25 | - id: golangci-lint
26 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # 贡献指南
2 |
3 | * 请为你的代码[签名](https://help.github.com/en/articles/signing-commits),
4 | 本仓库设置了**未签名的代码会阻止合并**。
5 | * 本项目的发起者偏好遵照 [Angular 规范](https://www.angular-gantt.com/contribute/)
6 | 来书写 git commit message,这也是最流行的规范,如果你不介意的话请参考一下。
7 | 如果前面网址无法访问,也可参考
8 | [这篇文章](http://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html)。
9 | * 发 PR 前请通过 `git rebase` 指令来将分支基础变更到最新的上游分支,并精简历史。
10 | * 发 PR 时请说明你的提交**修改了什么,以及为什么**要做这些修改。
11 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
GoMud
3 | Go 语言写的,支持 UTF-8 的中文 MUD 客户端
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 | 本项目实现目标是一个 MUD 客户端,主要采用 Go 语言实现。
30 |
31 | 本项目基于中国知名 MUD 游戏《[北大侠客行](http://www.pkuxkx.com)》开发,但也应该可以适用于其它 MUD 服务。
32 |
33 | ## 什么是 MUD
34 |
35 | MUD(/mʌd/, 参见[维基百科](https://zh.wikipedia.org/zh-cn/MUD)),原指多用户地牢(Multi-User Dungeon),
36 | 通常将缩写直译为“网络泥巴”或是简称“泥巴”(英文 **mud** 的意思为泥巴)。
37 |
38 | MUD 是一种多人即时的虚拟世界,通常以文字描述为基础。其中结合了**角色扮演**、**江湖**、**互动小说**与**在线聊天**等元素,玩家可以阅读或查看房间、物品、其他玩家、非玩家角色的描述,并在虚拟世界中做特定动作。玩家通常会透过输入类似自然语言的指令(如`drink`, `eat`, `bow`)来与虚拟世界中的物品或其他玩家交互。
39 |
40 | MUD 一般认为是最早的网络游戏,历史悠久,内涵丰富。在古朴的终端界面下,通过阅读文字展开想象,来构筑一个庞大的虚拟世界,因此富有独特的魅力。
41 |
42 | ## 什么是北大侠客行
43 |
44 | 北大侠客行(以下称**北侠**)于 1996 年开服,至今仍在运营,算是国内运行非常长的网络游戏了。
45 | 而且这些年一直都有更新,实属难能可贵。
46 |
47 | 基于 MUD 特有的文化,挂机在北侠也是被允许的,而在 MUD 下开发挂机程序也是一种别有风味的玩法。
48 |
49 | ## GoMud 有什么用
50 |
51 | GoMud 是一个 MUD 客户端,可以用来连接 MUD 服务器,提供纯文本的用户界面,以供玩家与 MUD 服务器交互。
52 |
53 | **GoMud 目前仍在开发当中,并不完善。** 但已经能够提供必要的功能来连接 MUD 服务器。且有许多亮点:
54 |
55 | * [X] 全程使用 UTF-8,天生免疫乱码
56 | * [X] 支持运行有 GB2312/GBK/GB18030/BIG5/UTF-16/UTF-8 编码的 MUD 服务器
57 | * [X] 纯文本界面,通过命令行和快捷键来操作
58 | * [X] 支持 macOS、Linux、Windows、安卓四大平台
59 | * [X] 支持**路由器**、**树莓派**、**群晖**、**电视机**等小众平台
60 | * [X] 支持 32 位和 64 位操作系统
61 | * [X] 支持 [Lua 机器人](https://github.com/dzpao/lua-mud-robots)
62 |
63 | ## GoMud 不能做什么
64 |
65 | * 不支持图形界面,没有丰富的代码编辑框或诸如此类的其它 UI 元素来帮助你写触发和机器人
66 | * 没有庞大的用户群,没有大量开箱即用的机器人,对伸手党不友好
67 | * 不能帮助没有丰富的计算机操作经验,特别是 *nix 命令行操作经验的人熟悉 *nix
68 | * 不能帮助没有编程经验或者没有学习过 Go 语言的人学会编程、学会 Go 语言
69 |
70 | ## 如何使用 GoMud
71 |
72 | ### 运行环境
73 |
74 | * GoMud 可在 Linux、macOS 及 Windows 上运行。运行时不依赖其它软件。
75 | * 通过 [Termux](https://termux.com/) 的帮助,GoMud 也可以在安卓下运行。你可以在运行安卓系统的手机或者电视机上使用 GoMud。
76 | * GoMud 也可以在群晖 NAS、运行有 OpenWRT 等 Linux 系统的智能路由器,或者树莓派上运行。
77 |
78 | ### 安装指南
79 |
80 | 本项目的[发布页面](https://github.com/mudclient/go-mud/releases)
81 | 中包含了所有支持平台的预编译安装包,你可以根据自己的需要选择下载。
82 |
83 | #### macOS 快速安装
84 |
85 | macOS 用户推荐使用 [Homebrew](https://brew.sh) 来安装。如果你没用过它,不如趁此机会安装体验一下。
86 |
87 | ```sh
88 | brew tap mudclient/tap
89 | brew install go-mud
90 | ```
91 |
92 | #### Termux 快速安装
93 |
94 | 运行了安卓系统的手机、平板电脑、电视机通过 Termux 也可以使用 GoMud,安装方法如下:
95 |
96 | ```sh
97 | wget https://github.com/mudclient/go-mud/releases/download/v0.6.1/go-mud_v0.6.1_Termux_ARMv7.deb
98 | apt install ./go-mud_v0.6.1_Termux_ARMv7.deb
99 | ```
100 |
101 | 以上命令以 ARMv7 架构上 v0.6.1 版本的为例,
102 | 其它版本及架构请前往发布页面选择相应的预编译安装包。
103 | 如果你不知道自己设备的 CPU 架构,可以通过 `uname -m` 命令获知。
104 |
105 | #### 手动安装
106 |
107 | 本项目的发布页面中包含了所有支持平台的预编译可执行文件。
108 | 各平台的可执行文件名称略有不同,你可以下载和你的运行环境相对应的版本。
109 | GoMud 支持的平台非常丰富,限于篇幅,此处不再赘述。
110 | 更多内容请查看[支持平台与安装指南](https://github.com/mudclient/go-mud/wiki/支持平台与安装指南)。
111 |
112 | #### 通过源码安装
113 |
114 | GoMud 采用 Go 语言实现,如果你要通过源码安装,则需要自行准备 Golang 开发环境。
115 | 推荐使用 Go 1.13 或以上的版本。Golang 安装完毕后,通过如下命令序列即可安装:
116 |
117 | ```
118 | git clone https://github.com/mudclient/go-mud.git
119 | cd go-mud
120 | go generate ./...
121 | go build
122 | ```
123 |
124 | ### 启动并进入北侠
125 |
126 | 下述示例中的程序文件名假定为 `go-mud`,如果你采用的是预编译的可执行文件,
127 | 你可能需要下载后改名或者将下述命令中的程序文件名替换为真实的程序文件名称。
128 |
129 | ```
130 | $ go-mud
131 | 初始化 Lua 环境...
132 | Lua 环境初始化完成。
133 | 连接到服务器 mud.pkuxkx.net:8080...连接成功。
134 | ...
135 | ```
136 |
137 | ### 配置 GoMud
138 |
139 | GoMud 支持通过配置文件或者命令行选项的方式来指定程序运行参数,
140 | 目前已有的命令行选项如下:
141 |
142 | ```
143 | $ go-mud --help # 可以获得使用帮助
144 | GoMud(version v0.6.1)
145 |
146 | Usage:
147 | go-mud [flags]
148 |
149 | Flags:
150 | -c, --config FILENAME config FILENAME, default to `config.yaml` or `config.json`
151 | --version just print version number only
152 | -h, --help show this message
153 | --gen-yaml generate config.yaml
154 | --gen-json generate config.json
155 | --ui.ambiguouswidth string 二义性字符宽度,可选值: auto/single/double/space (default "auto")
156 | --ui.historylines int 历史记录保留行数 (default 100000)
157 | --ui.rttvheight int 历史查看模式下实时文本区域高度 (default 10)
158 | -H, --mud.host IP/Domain 服务器 IP/Domain (default "mud.pkuxkx.net")
159 | -P, --mud.port Port 服务器 Port (default 8080)
160 | --mud.encodings Encodings 服务器的 Encodings,允许指定多个,用逗号分隔 (default "UTF-8,GB18030,GBK,GB2312")
161 | --lua.enable 是否加载 Lua 机器人 (default true)
162 | -p, --lua.path path Lua 插件路径 path (default "lua")
163 | ```
164 |
165 | 配置文件同时支持 [YAML](https://yaml.org/) 和 [JSON](https://json.org/) 两种格式,
166 | 两种配置文件效果是一样的,用户可根据个人偏好选择使用,下面分别给出示例。
167 | 配置项的说明参见[配置与运行](https://github.com/mudclient/go-mud/wiki/配置与运行)。
168 |
169 | #### config.yaml 示例
170 |
171 | 默认的 YAML 配置文件名为 `config.yaml`,如果省略配置文件,等同默认内容如下:
172 |
173 | ```yaml
174 | UI:
175 | AmbiguousWidth: auto
176 | HistoryLines: 100000
177 | RTTVHeight: 10
178 | MUD:
179 | Host: mud.pkuxkx.net
180 | Port: 8080
181 | Encodings: UTF-8,GB18030,GBK,GB2312
182 | Lua:
183 | Enable: true
184 | Path: lua
185 | ```
186 |
187 | #### config.json 示例
188 |
189 | 默认的 JSON 配置文件名为 `config.json`,如果省略配置文件,等同默认内容如下:
190 |
191 | ```json
192 | {
193 | "UI": {
194 | "AmbiguousWidth": "auto",
195 | "HistoryLines": 100000,
196 | "RTTVHeight": 10
197 | },
198 | "Mud": {
199 | "Host": "mud.pkuxkx.net",
200 | "Port": 8080,
201 | "Encodings": "UTF-8,GB18030,GBK,GB2312"
202 | },
203 | "Lua": {
204 | "Enable": true,
205 | "Path": "lua"
206 | }
207 | }
208 | ```
209 |
210 | ### 通过 Docker 来启动
211 |
212 | GoMud 也可支持通过 Docker 来运行,推荐使用 Docker 来挂机。
213 |
214 | ```
215 | 待完善
216 | ```
217 |
218 | ## 如何贡献
219 |
220 | * 体验并向周围的人分享你的体验结果
221 | * 通过[提交 issue](https://github.com/mudclient/go-mud/issues/new) 来反馈意见
222 | * 通过 PR 来贡献代码,贡献代码时请先阅读[贡献指南](CONTRIBUTING.md)
223 |
--------------------------------------------------------------------------------
/app/gen.go:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | // 本程序用来生成 app/contributors.go,无需编译
4 | package main
5 |
6 | import (
7 | "log"
8 | "os"
9 | "os/exec"
10 | "regexp"
11 | "sort"
12 | "strconv"
13 | "strings"
14 | "text/template"
15 | "time"
16 | )
17 |
18 | type Contributor struct {
19 | Name string
20 | Lines int
21 | }
22 |
23 | func main() {
24 | authorList := parseContributors(RunCommand(`git log --stat`))
25 | appVersion := RunCommand(`git describe --always --tags --dirty`)
26 | buildHost := RunCommand(`hostname`)
27 | goVersion := RunCommand(`go version`)
28 |
29 | file, err := os.Create("version.go")
30 | if err != nil {
31 | log.Fatal(`os.Create("version.go"): `, err)
32 | return
33 | }
34 |
35 | now := time.Now()
36 | fileTemplate.Execute(file, struct {
37 | Timestamp time.Time
38 | Carls []Contributor
39 | Version string
40 | BuildGoVersion string
41 | BuildHost string
42 | GoVersion string
43 | }{
44 | Timestamp: now,
45 | Carls: authorList,
46 | Version: appVersion,
47 | BuildHost: buildHost,
48 | GoVersion: goVersion,
49 | })
50 | }
51 |
52 | func parseContributors(gitLog string) []Contributor {
53 | var author string
54 |
55 | authorDict := make(map[string]int)
56 | lines := strings.Split(gitLog, "\n")
57 |
58 | for _, line := range lines {
59 | fields := strings.SplitN(line, " ", 2)
60 | if fields[0] == "Author:" {
61 | author = fields[1]
62 | continue
63 | }
64 |
65 | re := regexp.MustCompile(` (\d+) insertion`)
66 | subs := re.FindStringSubmatch(line)
67 | if subs != nil {
68 | lines, _ := strconv.Atoi(subs[1])
69 | authorDict[author] += lines
70 | }
71 | }
72 |
73 | var authorList []Contributor
74 |
75 | for k, v := range authorDict {
76 | authorList = append(authorList, Contributor{
77 | Name: k,
78 | Lines: v,
79 | })
80 | }
81 |
82 | sort.SliceStable(authorList, func(i, j int) bool {
83 | return authorList[i].Lines > authorList[j].Lines
84 | })
85 |
86 | return authorList
87 | }
88 |
89 | func RunCommand(cmdLine string) string {
90 | args := regexp.MustCompile(`\s+`).Split(cmdLine, -1)
91 | cmd := exec.Command(args[0], args[1:]...)
92 | output, err := cmd.Output()
93 |
94 | if err != nil {
95 | log.Fatal(cmdLine, ": ", err)
96 | }
97 |
98 | return strings.Trim(string(output), "\r\n\t ")
99 | }
100 |
101 | var fileTemplate = template.Must(template.New("").Parse(`// Code generated by go generate; DO NOT EDIT.
102 | // This file was generated by robots at {{ .Timestamp }}
103 | package app
104 |
105 | var Contributors = []struct{
106 | Name string
107 | Lines int
108 | } {
109 | {{- range .Carls }}
110 | {{ printf "{%q, %d}" .Name .Lines }},
111 | {{- end }}
112 | }
113 |
114 | var (
115 | AppName = "GoMud"
116 | Version = {{ printf "%q" .Version }}
117 | BuildTime = {{.Timestamp.Format "2006-01-02 15:04:05 MST" | printf "%q"}}
118 | BuildGoVersion = {{ printf "%q" .GoVersion }}
119 | BuildHost = {{ printf "%q" .BuildHost }}
120 | )
121 | `))
122 |
--------------------------------------------------------------------------------
/app/helper.go:
--------------------------------------------------------------------------------
1 | package app
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | //go:generate go run gen.go
8 |
9 | func VersionDetail() string {
10 | info := fmt.Sprintf("版本信息如下:\n程序版本: %s\n编译时间: %s\n编译环境: %s\n编译设备: %s\n其中:\n",
11 | Version, BuildTime, BuildGoVersion, BuildHost)
12 | for _, contributor := range Contributors {
13 | info += fmt.Sprintf(" %s 贡献了 %d 行代码\n", contributor.Name, contributor.Lines)
14 | }
15 |
16 | return info
17 | }
18 |
--------------------------------------------------------------------------------
/build/termux-armv6.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "go-mud",
3 | "version": "VAR-VERSION",
4 | "homepage": "https://github.com/mudclient/go-mud",
5 | "maintainer": "@dzpao",
6 | "description": "A mud client written in Go",
7 | "arch": "arm",
8 | "depends": [],
9 | "files": {
10 | "README.md": "README.md",
11 | "LICENSE": "LICENSE",
12 | "dist/CHANGELOG.md": "CHANGELOG.md",
13 | "dist/go-mud_linux_arm_6/go-mud": "bin/go-mud"
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/build/termux-armv7.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "go-mud",
3 | "version": "VAR-VERSION",
4 | "homepage": "https://github.com/mudclient/go-mud",
5 | "maintainer": "@dzpao",
6 | "description": "A mud client written in Go",
7 | "arch": "arm",
8 | "depends": [],
9 | "files": {
10 | "README.md": "README.md",
11 | "LICENSE": "LICENSE",
12 | "dist/CHANGELOG.md": "CHANGELOG.md",
13 | "dist/go-mud_linux_arm_7/go-mud": "bin/go-mud"
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/build/termux-armv8.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "go-mud",
3 | "version": "VAR-VERSION",
4 | "homepage": "https://github.com/mudclient/go-mud",
5 | "maintainer": "@dzpao",
6 | "description": "A mud client written in Go",
7 | "arch": "aarch64",
8 | "depends": [],
9 | "files": {
10 | "README.md": "README.md",
11 | "LICENSE": "LICENSE",
12 | "dist/CHANGELOG.md": "CHANGELOG.md",
13 | "dist/go-mud_linux_arm64/go-mud": "bin/go-mud"
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/build/termux-build.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | PATH=$PATH:~/.local/bin
4 | export PATH
5 |
6 | DEB_VERSION=$(echo $GIT_DESCRIBE | cut -c2-)
7 |
8 | APP_NAME=go-mud
9 |
10 | sed -i 's/VAR-VERSION/'$DEB_VERSION'/' build/termux-armv6.json
11 | termux-create-package build/termux-armv6.json
12 | test -f ${APP_NAME}_${DEB_VERSION}_arm.deb || exit 1
13 | mv ${APP_NAME}_*_arm.deb dist/${APP_NAME}_v${DEB_VERSION}_Termux_ARMv6.deb
14 |
15 | sed -i 's/VAR-VERSION/'$DEB_VERSION'/' build/termux-armv7.json
16 | termux-create-package build/termux-armv7.json
17 | test -f ${APP_NAME}_${DEB_VERSION}_arm.deb || exit 1
18 | mv ${APP_NAME}_*_arm.deb dist/${APP_NAME}_v${DEB_VERSION}_Termux_ARMv7.deb
19 |
20 | sed -i 's/VAR-VERSION/'$DEB_VERSION'/' build/termux-armv8.json
21 | termux-create-package build/termux-armv8.json
22 | test -f ${APP_NAME}_${DEB_VERSION}_aarch64.deb || exit 1
23 | mv ${APP_NAME}_*_aarch64.deb dist/${APP_NAME}_v${DEB_VERSION}_Termux_ARMv8.deb
24 |
25 | (
26 | cd dist;
27 | rm -f checksums.txt
28 | (
29 | echo SHA256SUM:
30 | sha256sum ${APP_NAME}_*.{tar.gz,zip,deb}
31 | echo; echo MD5SUM:
32 | md5sum ${APP_NAME}_*.{tar.gz,zip,deb}
33 | ) > checksums.txt
34 | )
35 |
36 | GH_TAGS=https://api.github.com/repos/$GITHUB_REPOSITORY/releases/tags
37 | curl -s $GH_TAGS/$GIT_DESCRIBE > out.json
38 | URL=$(jq -r '.upload_url' out.json | sed 's/{.*}//')
39 | RELEASE_ID=$(jq -r '.id' out.json)
40 |
41 | if [[ $URL != http* ]]; then
42 | echo Cant get URL for $GIT_DESCRIBE
43 | exit 1
44 | fi
45 |
46 | echo "Delete checksums.txt ..."
47 |
48 | CHECKSUMS_URL=$(jq -r '.assets[] | select(.name == "checksums.txt") | .url' out.json)
49 | if [[ $CHECKSUMS_URL != http* ]]; then
50 | echo Cant get URL for checksums.txt
51 | exit 1
52 | fi
53 |
54 | curl --silent -X DELETE -H "Authorization: token $GITHUB_TOKEN" $CHECKSUMS_URL
55 |
56 | echo "Uploading asset ..."
57 |
58 | for file in dist/checksums.txt dist/${APP_NAME}_*.deb; do
59 | echo " Uploading $file"
60 | GH_ASSET="$URL?name=$(basename $file)"
61 | HTTP_CODE=$(curl --silent --output out.json -w '%{http_code}' \
62 | -H "Authorization: token $GITHUB_TOKEN" \
63 | -H "Content-Type: application/octet-stream" \
64 | --data-binary @"$file" \
65 | $GH_ASSET
66 | )
67 | if [[ $HTTP_CODE != 2* ]]; then
68 | jq --monochrome-output '' out.json
69 | URL=https://api.github.com/repos/$GITHUB_REPOSITORY/releases/$RELEASE_ID
70 | curl --silent -X DELETE -H "Authorization: token $GITHUB_TOKEN" $URL
71 | exit 1
72 | fi
73 | done
74 |
--------------------------------------------------------------------------------
/config-example.json:
--------------------------------------------------------------------------------
1 | {
2 | "UI": {
3 | "AmbiguousWidth": "auto",
4 | "HistoryLines": 100000,
5 | "RTTVHeight": 10
6 | },
7 | "Mud": {
8 | "Host": "mud.pkuxkx.net",
9 | "Port": 8080,
10 | "Encodings": "UTF-8,GB18030,GBK,GB2312"
11 | },
12 | "Lua": {
13 | "Enable": true,
14 | "Path": "lua"
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/config-example.yaml:
--------------------------------------------------------------------------------
1 | UI:
2 | AmbiguousWidth: auto
3 | HistoryLines: 100000
4 | RTTVHeight: 10
5 | MUD:
6 | Host: mud.pkuxkx.net
7 | Port: 8080
8 | Encodings: UTF-8,GB18030,GBK,GB2312
9 | Lua:
10 | Enable: true
11 | Path: lua
12 |
--------------------------------------------------------------------------------
/go.mod:
--------------------------------------------------------------------------------
1 | module github.com/mudclient/go-mud
2 |
3 | go 1.13
4 |
5 | require (
6 | github.com/flw-cn/go-smartConfig v1.1.3
7 | github.com/flw-cn/printer v0.0.0-20190906044932-ecdb12812e08
8 | github.com/gdamore/tcell v1.3.0
9 | github.com/mattn/go-runewidth v0.0.4
10 | github.com/rivo/tview v0.0.0-20190829161255-f8bc69b90341
11 | github.com/spf13/cobra v0.0.5
12 | github.com/yuin/gopher-lua v0.0.0-20190514113301-1cd887cd7036
13 | golang.org/x/text v0.3.2
14 | )
15 |
16 | replace github.com/rivo/tview v0.0.0-20190829161255-f8bc69b90341 => github.com/dzpao/tview v0.0.0-20200122091015-7e3eb050fe6b
17 |
--------------------------------------------------------------------------------
/go.sum:
--------------------------------------------------------------------------------
1 | cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
2 | github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
3 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
4 | github.com/DATA-DOG/go-sqlmock v1.3.3 h1:CWUqKXe0s8A2z6qCgkP4Kru7wC11YoAnoupUKFDnH08=
5 | github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
6 | github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
7 | github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
8 | github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
9 | github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
10 | github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
11 | github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
12 | github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
13 | github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
14 | github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
15 | github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
16 | github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
17 | github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
18 | github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
19 | github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
20 | github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
21 | github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
22 | github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
23 | github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
24 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
25 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
26 | github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
27 | github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
28 | github.com/dzpao/tview v0.0.0-20200122091015-7e3eb050fe6b h1:EgU8jjOaqu3f1UcpWaX6slE6TghVq1eNPLYsc53CWzQ=
29 | github.com/dzpao/tview v0.0.0-20200122091015-7e3eb050fe6b/go.mod h1:/rBeY22VG2QprWnEqG57IBC8biVu3i0DOIjRLc9I8H0=
30 | github.com/flw-cn/go-smartConfig v1.1.3 h1:eyyjVFr3Jcpu/WS1J3dVE6y0dYgTVXZFvMkIqHkkTOQ=
31 | github.com/flw-cn/go-smartConfig v1.1.3/go.mod h1:sKE0iGnTaJe8XcVwxFMTptN0CCiUTlPQCWSnIqjVGBk=
32 | github.com/flw-cn/printer v0.0.0-20190906044932-ecdb12812e08 h1:jnmiuamX/MW+N63FBFuitjA87rbBto+RCEz8PsbexOo=
33 | github.com/flw-cn/printer v0.0.0-20190906044932-ecdb12812e08/go.mod h1:DVfmMjyMU7s2D5RBJ+fKWvQEcrQq86g9xJbpykJYBtQ=
34 | github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
35 | github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
36 | github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
37 | github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
38 | github.com/gdamore/tcell v1.3.0 h1:r35w0JBADPZCVQijYebl6YMWWtHRqVEGt7kL2eBADRM=
39 | github.com/gdamore/tcell v1.3.0/go.mod h1:Hjvr+Ofd+gLglo7RYKxxnzCBmev3BzsS67MebKS4zMM=
40 | github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
41 | github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
42 | github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
43 | github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
44 | github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
45 | github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
46 | github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
47 | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
48 | github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
49 | github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
50 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
51 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
52 | github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
53 | github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
54 | github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
55 | github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
56 | github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
57 | github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
58 | github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
59 | github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
60 | github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
61 | github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
62 | github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
63 | github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
64 | github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
65 | github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
66 | github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
67 | github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
68 | github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
69 | github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
70 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
71 | github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
72 | github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
73 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
74 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
75 | github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
76 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
77 | github.com/lucasb-eyer/go-colorful v1.0.2 h1:mCMFu6PgSozg9tDNMMK3g18oJBX7oYGrC09mS6CXfO4=
78 | github.com/lucasb-eyer/go-colorful v1.0.2/go.mod h1:0MS4r+7BZKSJ5mw4/S5MPN+qHFF1fYclkSPilDOKW0s=
79 | github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY=
80 | github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
81 | github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4=
82 | github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
83 | github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
84 | github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
85 | github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
86 | github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
87 | github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
88 | github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
89 | github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
90 | github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
91 | github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
92 | github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
93 | github.com/pelletier/go-toml v1.6.0 h1:aetoXYr0Tv7xRU/V4B4IZJ2QcbtMUFoNb3ORp7TzIK4=
94 | github.com/pelletier/go-toml v1.6.0/go.mod h1:5N711Q9dKgbdkxHL+MEfF31hpT7l0S0s/t2kKREewys=
95 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
96 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
97 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
98 | github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
99 | github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
100 | github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
101 | github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
102 | github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
103 | github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
104 | github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
105 | github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
106 | github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
107 | github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY=
108 | github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
109 | github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
110 | github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
111 | github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
112 | github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
113 | github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
114 | github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
115 | github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
116 | github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
117 | github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
118 | github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI=
119 | github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
120 | github.com/spf13/afero v1.2.2 h1:5jhuqJyZCZf2JRofRvN/nIFgIWNzPa3/Vz8mYylgbWc=
121 | github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
122 | github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8=
123 | github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
124 | github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
125 | github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
126 | github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s=
127 | github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
128 | github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk=
129 | github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
130 | github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk=
131 | github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
132 | github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
133 | github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
134 | github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
135 | github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
136 | github.com/spf13/viper v1.3.2 h1:VUFqw5KcqRf7i70GOzW7N+Q7+gxVBkSSqiXB12+JQ4M=
137 | github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
138 | github.com/spf13/viper v1.6.2 h1:7aKfF+e8/k68gda3LOjo5RxiUqddoFxVq4BKBPrxk5E=
139 | github.com/spf13/viper v1.6.2/go.mod h1:t3iDnF5Jlj76alVNuyFBk5oUMCvsrkbvZK0WQdfDi5k=
140 | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
141 | github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
142 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
143 | github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
144 | github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
145 | github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
146 | github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
147 | github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
148 | github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
149 | github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
150 | github.com/yuin/gopher-lua v0.0.0-20190514113301-1cd887cd7036 h1:1b6PAtenNyhsmo/NKXVe34h7JEZKva1YB/ne7K7mqKM=
151 | github.com/yuin/gopher-lua v0.0.0-20190514113301-1cd887cd7036/go.mod h1:gqRgreBUhTSL0GeU64rtZ3Uq3wtjOa/TB2YfrtkCbVQ=
152 | go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
153 | go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
154 | go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
155 | go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
156 | golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
157 | golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
158 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
159 | golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
160 | golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
161 | golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
162 | golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
163 | golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
164 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
165 | golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
166 | golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
167 | golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
168 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
169 | golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
170 | golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
171 | golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
172 | golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
173 | golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
174 | golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
175 | golang.org/x/sys v0.0.0-20190204203706-41f3e6584952/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
176 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
177 | golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
178 | golang.org/x/sys v0.0.0-20191018095205-727590c5006e h1:ZtoklVMHQy6BFRHkbG6JzK+S6rX82//Yeok1vMlizfQ=
179 | golang.org/x/sys v0.0.0-20191018095205-727590c5006e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
180 | golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9 h1:1/DFK4b7JH8DmkqhUk48onnSfrPzImPoVxuomtbT2nk=
181 | golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
182 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
183 | golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
184 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
185 | golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
186 | golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
187 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
188 | golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
189 | golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
190 | golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
191 | google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
192 | google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
193 | google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
194 | google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
195 | gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
196 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
197 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
198 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
199 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
200 | gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno=
201 | gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
202 | gopkg.in/ini.v1 v1.51.1 h1:GyboHr4UqMiLUybYjd22ZjQIKEJEpgtLXtuGbR21Oho=
203 | gopkg.in/ini.v1 v1.51.1/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
204 | gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
205 | gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
206 | gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
207 | gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
208 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
209 | gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
210 | gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
211 | gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
212 | honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
213 |
--------------------------------------------------------------------------------
/lua-api/lua.go:
--------------------------------------------------------------------------------
1 | package lua
2 |
3 | import (
4 | "errors"
5 | "fmt"
6 | "io"
7 | "os"
8 | "path"
9 | "regexp"
10 | "sync"
11 | "time"
12 |
13 | "github.com/flw-cn/printer"
14 | lua "github.com/yuin/gopher-lua"
15 | )
16 |
17 | var errPanic = errors.New("LUA Panic")
18 |
19 | type Config struct {
20 | Enable bool `flag:"|true|是否加载 Lua 机器人"`
21 | Path string `flag:"p|lua|Lua 插件路径 {path}"`
22 | }
23 |
24 | type API struct {
25 | config Config
26 |
27 | screen printer.Printer
28 | mud io.Writer
29 |
30 | lstate *lua.LState
31 | onReceive lua.P
32 | onSend lua.P
33 |
34 | timer sync.Map
35 | }
36 |
37 | func NewAPI(config Config) *API {
38 | return &API{
39 | config: config,
40 | screen: printer.NewSimplePrinter(os.Stdout),
41 | }
42 | }
43 |
44 | func (api *API) Init() {
45 | if !api.config.Enable {
46 | return
47 | }
48 |
49 | _ = api.Reload()
50 | }
51 |
52 | func (api *API) SetScreen(w printer.Printer) {
53 | api.screen = w
54 | }
55 |
56 | func (api *API) SetMud(w io.Writer) {
57 | api.mud = w
58 | }
59 |
60 | func (api *API) Reload() error {
61 | mainFile := path.Join(api.config.Path, "main.lua")
62 | if _, err := os.Open(mainFile); err != nil {
63 | api.screen.Printf("Load error: %v\n", err)
64 | api.screen.Println("无法打开 lua 主程序,请检查你的配置。")
65 | return err
66 | }
67 |
68 | if api.lstate != nil {
69 | api.lstate.Close()
70 | api.screen.Println("Lua 环境已关闭。")
71 | }
72 |
73 | api.screen.Println("初始化 Lua 环境...")
74 |
75 | luaPath := path.Join(api.config.Path, "?.lua")
76 | os.Setenv(lua.LuaPath, luaPath+";;")
77 |
78 | api.lstate = lua.NewState()
79 |
80 | // 为 Lua 环境提供 API
81 | api.register()
82 |
83 | l := api.lstate
84 |
85 | l.Panic = func(*lua.LState) {
86 | api.Panic(errPanic)
87 | }
88 |
89 | if err := l.DoFile(mainFile); err != nil {
90 | l.Close()
91 | api.screen.Printf("Lua 初始化失败:%v\n", err)
92 | api.lstate = nil
93 | return err
94 | }
95 |
96 | // 和 Lua 环境中的钩子相连接
97 | api.hookOn()
98 |
99 | api.screen.Println("Lua 环境初始化完成。")
100 |
101 | return nil
102 | }
103 |
104 | func (api *API) register() {
105 | l := api.lstate
106 |
107 | l.SetGlobal("RegEx", l.NewFunction(api.LuaRegEx))
108 | l.SetGlobal("Echo", l.NewFunction(api.LuaEcho))
109 | l.SetGlobal("Print", l.NewFunction(api.LuaPrint))
110 | l.SetGlobal("Run", l.NewFunction(api.LuaRun))
111 | l.SetGlobal("Send", l.NewFunction(api.LuaSend))
112 | l.SetGlobal("AddTimer", l.NewFunction(api.LuaAddTimer))
113 | l.SetGlobal("AddMSTimer", l.NewFunction(api.LuaAddTimer))
114 | l.SetGlobal("DelTimer", l.NewFunction(api.LuaDelTimer))
115 | l.SetGlobal("DelMSTimer", l.NewFunction(api.LuaDelTimer))
116 | }
117 |
118 | func (api *API) hookOn() {
119 | l := api.lstate
120 |
121 | if v := l.GetGlobal("OnReceive"); v.Type() == lua.LTFunction {
122 | api.onReceive = lua.P{
123 | Fn: v,
124 | NRet: 0,
125 | Protect: true,
126 | }
127 | } else {
128 | api.screen.Println("Lua 环境中未定义 OnReceive 函数,将无法接收游戏数据。")
129 | }
130 |
131 | if v := l.GetGlobal("OnSend"); v.Type() == lua.LTFunction {
132 | api.onSend = lua.P{
133 | Fn: v,
134 | NRet: 1,
135 | Protect: true,
136 | }
137 | } else {
138 | api.screen.Println("Lua 环境中未定义 OnSend 函数,将无法获知向游戏发送的数据。")
139 | }
140 | }
141 |
142 | func (api *API) OnReceive(raw, input string) {
143 | if api.lstate == nil ||
144 | api.onReceive.Fn == nil ||
145 | api.onReceive.Fn.Type() != lua.LTFunction {
146 | return
147 | }
148 |
149 | l := api.lstate
150 | err := l.CallByParam(api.onReceive, lua.LString(raw), lua.LString(input))
151 | if err != nil {
152 | api.Panic(err)
153 | }
154 | }
155 |
156 | func (api *API) OnSend(cmd string) bool {
157 | if api.lstate == nil ||
158 | api.onSend.Fn == nil ||
159 | api.onSend.Fn.Type() != lua.LTFunction {
160 | return true
161 | }
162 |
163 | l := api.lstate
164 | err := l.CallByParam(api.onSend, lua.LString(cmd))
165 | if err != nil {
166 | api.Panic(err)
167 | }
168 |
169 | ret := l.Get(-1)
170 | l.Pop(1)
171 |
172 | return ret != lua.LFalse
173 | }
174 |
175 | func (api *API) Panic(err error) {
176 | api.screen.Printf("Lua error: %v\n", err)
177 | }
178 |
179 | func (api *API) LuaRegEx(l *lua.LState) int {
180 | text := l.ToString(1)
181 | regex := l.ToString(2)
182 |
183 | re, err := regexp.Compile(regex)
184 | if err != nil {
185 | l.Push(lua.LString("0"))
186 | return 1
187 | }
188 |
189 | matchs := re.FindAllStringSubmatch(text, -1)
190 | if matchs == nil {
191 | l.Push(lua.LString("0"))
192 | return 1
193 | }
194 |
195 | subs := matchs[0]
196 | length := len(subs)
197 | if length == 1 {
198 | l.Push(lua.LString("-1"))
199 | return 1
200 | }
201 |
202 | l.Push(lua.LString(fmt.Sprintf("%d", length-1)))
203 |
204 | for i := 1; i < length; i++ {
205 | l.Push(lua.LString(subs[i]))
206 | }
207 |
208 | return length
209 | }
210 |
211 | func (api *API) LuaPrint(l *lua.LState) int {
212 | text := l.ToString(1)
213 | api.screen.Println(text)
214 | return 0
215 | }
216 |
217 | func (api *API) LuaEcho(l *lua.LState) int {
218 | text := l.ToString(1)
219 |
220 | codes := map[string]string{
221 | "$BLK$": "[black::]",
222 | "$NOR$": "[-:-:-]",
223 | "$RED$": "[red::]",
224 | "$HIR$": "[red::b]",
225 | "$GRN$": "[green::]",
226 | "$HIG$": "[green::b]",
227 | "$YEL$": "[yellow::]",
228 | "$HIY$": "[yellow::b]",
229 | "$BLU$": "[blue::]",
230 | "$HIB$": "[blue::b]",
231 | "$MAG$": "[darkmagenta::]",
232 | "$HIM$": "[#ff00ff::]",
233 | "$CYN$": "[dardcyan::]",
234 | "$HIC$": "[#00ffff::]",
235 | "$WHT$": "[white::]",
236 | "$HIW$": "[#ffffff::]",
237 | "$BNK$": "[::l]",
238 | "$REV$": "[::7]",
239 | "$U$": "[::u]",
240 | }
241 |
242 | re := regexp.MustCompile(`\$(BLK|NOR|RED|HIR|GRN|HIG|YEL|HIY|BLU|HIB|MAG|HIM|CYN|HIC|WHT|HIW|BNK|REV|U)\$`)
243 | text = re.ReplaceAllStringFunc(text, func(code string) string {
244 | code, ok := codes[code]
245 | if ok {
246 | return code
247 | }
248 | api.screen.Printf("Find Unknown Color Code: %s\n", code)
249 | return ""
250 | })
251 |
252 | api.screen.Println(text)
253 |
254 | // TODO: 这里暂时不支持 ANSI 到 PLAIN 的转换
255 | api.OnReceive(text, text)
256 |
257 | return 0
258 | }
259 |
260 | func (api *API) LuaRun(l *lua.LState) int {
261 | text := l.ToString(1)
262 | api.screen.Println(text)
263 | return 0
264 | }
265 |
266 | func (api *API) LuaSend(l *lua.LState) int {
267 | text := l.ToString(1)
268 | fmt.Fprintln(api.mud, text)
269 | return 0
270 | }
271 |
272 | func (api *API) LuaAddTimer(l *lua.LState) int {
273 | id := l.ToString(1)
274 | code := l.ToString(2)
275 | delay := l.ToInt(3)
276 | times := l.ToInt(4)
277 |
278 | go func() {
279 | count := 0
280 | quit := make(chan bool, 1)
281 | timer := Timer{
282 | id: id,
283 | code: code,
284 | delay: delay,
285 | maxTimes: times,
286 | times: 0,
287 | quit: quit,
288 | }
289 | v, exists := api.timer.LoadOrStore(id, timer)
290 | if exists {
291 | v.(Timer).quit <- true
292 | api.timer.Store(id, timer)
293 | }
294 |
295 | for {
296 | select {
297 | case <-quit:
298 | return
299 | case <-time.After(time.Millisecond * time.Duration(delay)):
300 | timer.Emit(api)
301 | count++
302 | if times > 0 && times >= count {
303 | return
304 | }
305 | }
306 | }
307 | }()
308 |
309 | return 0
310 | }
311 |
312 | func (api *API) LuaDelTimer(l *lua.LState) int {
313 | id := l.ToString(1)
314 | v, ok := api.timer.Load(id)
315 | if ok {
316 | v.(Timer).quit <- true
317 | }
318 | api.timer.Delete(id)
319 | return 0
320 | }
321 |
322 | type Timer struct {
323 | id string
324 | code string
325 | delay int
326 | maxTimes int
327 | times int
328 | quit chan<- bool
329 | }
330 |
331 | func (t *Timer) Emit(l *API) {
332 | err := l.lstate.DoString(`call_timer_actions("` + t.id + `")`)
333 | if err != nil {
334 | l.screen.Printf("Lua Error: %v\n", err)
335 | }
336 | }
337 |
--------------------------------------------------------------------------------
/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "log"
6 | "regexp"
7 | "runtime"
8 | "strings"
9 | "time"
10 |
11 | "github.com/flw-cn/go-smartConfig"
12 | "github.com/mattn/go-runewidth"
13 | "github.com/rivo/tview"
14 | "github.com/spf13/cobra"
15 | "golang.org/x/text/width"
16 |
17 | "github.com/mudclient/go-mud/app"
18 | "github.com/mudclient/go-mud/lua-api"
19 | "github.com/mudclient/go-mud/mud"
20 | "github.com/mudclient/go-mud/ui"
21 | )
22 |
23 | type ClientConfig struct {
24 | UI ui.Config
25 | Mud mud.Config
26 | Lua lua.Config
27 | }
28 |
29 | type Client struct {
30 | config ClientConfig
31 | ui *ui.UI
32 | lua *lua.API
33 | mud *mud.Server
34 | quit chan bool
35 |
36 | debug bool
37 | }
38 |
39 | func main() {
40 | cobra.MousetrapHelpText = "" // 允许在 Windows(R) 下直接双击运行
41 | config := ClientConfig{}
42 | smartConfig.VersionDetail = app.VersionDetail()
43 | smartConfig.LoadConfig(app.AppName, app.Version, &config)
44 |
45 | client := NewClient(config)
46 | client.Run()
47 | }
48 |
49 | func NewClient(config ClientConfig) *Client {
50 | return &Client{
51 | config: config,
52 | ui: ui.NewUI(config.UI),
53 | lua: lua.NewAPI(config.Lua),
54 | mud: mud.NewServer(config.Mud),
55 | quit: make(chan bool, 1),
56 | }
57 | }
58 |
59 | func (c *Client) Run() {
60 | ansiRe := regexp.MustCompile("\x1b" + `\[\d*(?:;\d*(?:;\d*)?)?(?:A|D|K|m)`)
61 |
62 | title := fmt.Sprintf("%s(%s), server = %s:%d",
63 | app.AppName, app.Version,
64 | c.config.Mud.Host, c.config.Mud.Port)
65 | c.ui.Create(title)
66 | go c.ui.Run()
67 | c.lua.SetScreen(c.ui)
68 | c.lua.SetMud(c.mud)
69 | c.lua.Init()
70 | c.mud.SetScreen(c.ui)
71 | go c.mud.Run()
72 |
73 | beautify := ambiWidthAdjuster(c.config.UI.AmbiguousWidth)
74 |
75 | LOOP:
76 | for {
77 | select {
78 | case <-c.quit:
79 | break LOOP
80 | case rawLine, ok := <-c.mud.Input():
81 | if ok {
82 | showLine := beautify(rawLine)
83 | plainLine := ansiRe.ReplaceAllString(rawLine, "")
84 | if c.debug {
85 | line := showLine
86 | line = strings.ReplaceAll(line, "\x1b[", "")
87 | line = strings.ReplaceAll(line, "\t", "")
88 | c.ui.Println(line)
89 | line = tview.TranslateANSI(showLine)
90 | line = tview.Escape(line)
91 | c.ui.Println(line)
92 | }
93 | c.ui.Println(showLine)
94 | c.lua.OnReceive(rawLine, plainLine)
95 | } else {
96 | defer log.Printf("连接已断开。")
97 | break LOOP
98 | }
99 | case cmd := <-c.ui.Input():
100 | c.DoCmd(cmd)
101 | }
102 | }
103 |
104 | c.ui.Stop()
105 | c.mud.Stop()
106 | }
107 |
108 | func (c *Client) DoCmd(cmd string) {
109 | switch cmd {
110 | case "exit", "quit":
111 | c.quit <- true
112 | return
113 | case "/version":
114 | c.ui.Print(app.VersionDetail())
115 | return
116 | case "/reload-lua":
117 | _ = c.lua.Reload()
118 | return
119 | case "/debug":
120 | c.debug = !c.debug
121 | return
122 | case "/lines":
123 | for i := 0; i < 100000; i++ {
124 | c.ui.Printf("%d %s\n", i, time.Now())
125 | }
126 | c.ui.Println("测试内容填充完毕")
127 | return
128 | }
129 |
130 | if len(cmd) > 0 {
131 | switch cmd[0] {
132 | case '\'':
133 | cmd = "say " + cmd[1:]
134 | case '"':
135 | cmd = "chat " + cmd[1:]
136 | case '*':
137 | cmd = "chat* " + cmd[1:]
138 | case ';':
139 | cmd = "rumor " + cmd[1:]
140 | }
141 | }
142 |
143 | c.ui.Println(cmd)
144 | needSend := c.lua.OnSend(cmd)
145 | if needSend {
146 | c.mud.Println(cmd)
147 | }
148 | }
149 |
150 | func ambiWidthAdjuster(option string) func(string) string {
151 | singleAmbiguousWidth := func(str string) string {
152 | return str
153 | }
154 | spaceAmbiguousWidth := func(str string) string {
155 | newStr := ""
156 | for _, c := range str {
157 | newStr += string(c)
158 | p := width.LookupRune(c)
159 | if p.Kind() == width.EastAsianAmbiguous {
160 | newStr += " "
161 | }
162 | }
163 | return newStr
164 | }
165 | option = strings.ToLower(option)
166 | switch option {
167 | case "double":
168 | return doubleAmbiguousWidth
169 | case "single":
170 | return singleAmbiguousWidth
171 | case "space":
172 | return spaceAmbiguousWidth
173 | case "auto":
174 | if runtime.GOOS == "windows" {
175 | return singleAmbiguousWidth
176 | }
177 | return doubleAmbiguousWidth
178 | default:
179 | return singleAmbiguousWidth
180 | }
181 | }
182 |
183 | func doubleAmbiguousWidth(str string) string {
184 | newStr := ""
185 | for _, c := range str {
186 | newStr += string(c)
187 | switch c {
188 | case '┌', '┎', '└', '┖', '─',
189 | '┬', '┭', '┰', '┱', '├', '┞', '┟', '┠', '┴', '┵', '┸', '┹',
190 | '┼', '╁', '╀', '╂', '┽', '╃', '╅', '╉',
191 | '╓', '╙', '╥', '╟', '╨', '╫', '╭', '╰':
192 | newStr += "─"
193 | case '┏', '┍', '┗', '┕', '━',
194 | '┳', '┲', '┯', '┮', '┣', '┢', '┡', '┝', '┻', '┺', '┷', '┶',
195 | '╋', '╇', '╈', '┿', '╊', '╆', '╄', '┾':
196 | newStr += "━"
197 | case '╔', '╦', '╠', '╬', '╚', '╩', '═',
198 | '╒', '╤', '╞', '╪', '╘', '╧':
199 | newStr += "═"
200 | // 上述三类字符的共同点就是右侧有水平线线头,因此以相应的线条来延伸它们。
201 | case '█', '▇', '▆', '▅', '▄', '▃', '▂', '▁', '▀',
202 | '▔', '┄', '┅', '┈', '┉':
203 | // 这几个字符从语义上讲宽度是含糊的,
204 | // 且实际显示效果占一个拉丁字母宽度,并且充斥了整个宽度,因此双写以延伸它们
205 | newStr += string(c)
206 | case '▕', '▒', '▓':
207 | // 这几个字符虽然从语义上讲宽度是含糊的,
208 | // 但在某些字体中显示效果已经是两个拉丁字母宽度了,
209 | // 因此仅用空格来调整宽度,不再重复,以免重叠
210 | newStr += " "
211 | case '╌', '╍', '╶', '╺', '╾', '╼', '░', '▗', '▙', '▚', '▜', '▟', '▝', '▛', '▞', '▐':
212 | // 这些字符的 East_Assia_Width 属性都是 single,语义上就只占一个拉丁字母的宽度,因此什么也不做
213 | default:
214 | // U+2500 ~ U+259F 区间除了本函数列出来的字符之外,其余字符从外观上看只能是通过空格来扩展
215 | p := width.LookupRune(c)
216 | if p.Kind() == width.EastAsianAmbiguous && runewidth.RuneWidth(c) == 1 {
217 | newStr += " "
218 | }
219 | }
220 | }
221 |
222 | return newStr
223 | }
224 |
--------------------------------------------------------------------------------
/mud/iac.go:
--------------------------------------------------------------------------------
1 | package mud
2 |
3 | import (
4 | "bytes"
5 | "fmt"
6 | )
7 |
8 | // IANA 管理的 Telnet 选项分配情况:
9 | // https://www.iana.org/assignments/telnet-options/telnet-options.xhtml
10 |
11 | // Standard Telnet Commands ,参见 https://tools.ietf.org/html/rfc854
12 | const (
13 | IAC = 255 // 0xFF Interpret as Command
14 | DONT = 254 // 0xFE Don't do something
15 | DO = 253 // 0xFD Do something
16 | WONT = 252 // 0xFC Won't do something
17 | WILL = 251 // 0xFB Will do something
18 | SB = 250 // 0xFA Subnegotiation Begin
19 | GA = 249 // 0xF9 Go Ahead
20 | EL = 248 // 0xF8 Erase Line
21 | EC = 247 // 0xF7 Erase Character
22 | AYT = 246 // 0xF6 Are You Here?
23 | AO = 245 // 0xF5 Abort Output
24 | IP = 244 // 0xF4 Interrupt Process
25 | BREAK = 243 // 0xF3 NVT character BRK
26 | DM = 242 // 0xF2 Data Mark
27 | NOP = 241 // 0xF1 No Operation
28 | SE = 240 // 0xF0 Subnegotiation End
29 | )
30 |
31 | // Standard Telnet Commands: https://tools.ietf.org/html/rfc854
32 | const (
33 | EOR = 239 // 0xEF End Of Record
34 | OptEOR = 25 // 0x19 Negotiate About EOR
35 | )
36 |
37 | // Telnet Linemode Option: https://tools.ietf.org/html/rfc1116
38 | const (
39 | LMABORT = 238 // 0xEE (Linemode) Abort
40 | LMSUSP = 237 // 0xED (Linemode) Suspend
41 | LMEOF = 236 // 0xEC (Linemode) End Of File
42 |
43 | OptLINEMODE = 34 // 0x22 Linemode Option
44 | )
45 |
46 | const (
47 | OptBINARY = 0 // 0x00 [RFC856] Binary Transmission
48 | OptECHO = 1 // 0x01 [RFC857] Echo
49 | OptRCP = 2 // 0x02 [NIC5005] Telnet Reconnection Option
50 | OptNAOL = 8 // 0x08 [NIC5005] Negotiate About Output Line Width
51 | OptNAOP = 9 // 0x09 [NIC5005] Negotiate About Output Page Size
52 | OptSGA = 3 // 0x03 [RFC858] Suppress GA (Go Ahead)
53 | OptNAMS = 4 // 0x04 [ ] Negotiate About Message Size
54 | OptSTATUS = 5 // 0x05 [RFC859] Status
55 | OptTM = 6 // 0x06 [RFC860] Timing Mark
56 | OptRCTE = 7 // 0x07 [RFC726] Remote Controlled Transmssion and Echoing
57 | OptNAOCRD = 10 // 0x0A [RFC652] Negotiate About Output Carriage-Return Disposition
58 | OptNAOHTS = 11 // 0x0B [RFC653] Negotiate About Output Horizontal Tab Stops
59 | OptNAOHTD = 12 // 0x0C [RFC654] Negotiate About Output Horizontal Tab Disposition
60 | OptNAOFFD = 13 // 0x0D [RFC655] Negotiate About Output Formfeed Disposition
61 | OptNAOVTS = 14 // 0x0E [RFC656] Negotiate About Output Vertical Tabstops
62 | OptNAOVTD = 15 // 0x0F [RFC657] Negotiate About Output Vertical Tab Disposition
63 | OptNAOLFD = 16 // 0x10 [RFC658] Negotiate About Output Linefeed Disposition
64 | OptXASCII = 17 // 0x11 [RFC698] Extended ASCII
65 | OptLOGOUT = 18 // 0x12 [RFC727] Logout
66 | OptBM = 19 // 0x13 [RFC735] Byte Macro
67 | OptDET = 20 // 0x14 [RFC1043] Data Entry Terminal
68 | OptSUPDUP = 21 // 0x15 [RFC736] SUPDUP Display Protocol
69 | OptSUPDUPOUT = 22 // 0x16 [RFC749] SUPDUP OUTPUT
70 | OptSNDLOC = 23 // 0x17 [RFC779] Send Location
71 | OptTTYPE = 24 // 0x18 [RFC1091] Terminal Type
72 | OptTUID = 26 // 0x1A [RFC927] TACACS User Identification
73 | OptOUTMRK = 27 // 0x1B [RFC933] Output Marking
74 | OptTTYLOC = 28 // 0x1C [RFC946] Terminal Location Number
75 | Opt3270 = 29 // 0x1D [RFC1041] Telnet 3270 Regime
76 | OptX3PAD = 30 // 0x1E [RFC1053] X.3 PAD
77 | OptNAWS = 31 // 0x1F [RFC1073] Negotiate About Window Size
78 | OptTSPEED = 32 // 0x20 [RFC1079] Terminal Speed
79 | OptLFLOW = 33 // 0x21 [RFC1372] Remote Flow Control
80 | OptXDISPLOC = 35 // 0x23 [RFC1096] X Display Location
81 | OptENVIRON = 36 // 0x24 [RFC1408] Environment Option
82 | OptAUTH = 37 // 0x25 [RFC2941] Authentication Option
83 | OptENCRYPT = 38 // 0x26 [RFC2946] Encryption Option
84 | OptNENV = 39 // 0x27 [RFC1572] New Environment
85 | OptTN3270E = 40 // 0x28 [RFC2355] TN3270 Enhancements
86 | OptXAUTH = 41 // 0x29
87 | OptCHARSET = 42 // 0x30 [RFC2066] Charset Option
88 | OptCOMPORT = 44 // 0x32 [RFC2217] Com Port Control Option
89 | OptKERMIT = 47 // 0x35 [RFC2840] KERMIT Option
90 |
91 | OptMSSP = 70 // 0x46 MUD Server Status Protocol
92 | OptMCCP = 85 // 0x55 MUD Client Compression Protocol
93 | OptMCCP2 = 86 // 0x56 MUD Client Compression Protocol 2.0
94 | OptMXP = 91 // 0x5B MUD eXtension Protocol
95 | OptZMP = 93 // 0x5D Zenith MUD Protocol
96 | OptGMCP = 201 // 0xC9 Generic MUD Communication Protocol
97 | OptEXOPL = 255 // 0xFF Extended Options List
98 | )
99 |
100 | var codeName = map[byte]string{
101 | IAC: "IAC",
102 | DONT: "DONT",
103 | DO: "DO",
104 | WONT: "WONT",
105 | WILL: "WILL",
106 | SB: "SB",
107 | GA: "GA",
108 | EL: "EL",
109 | EC: "EC",
110 | AYT: "AYT",
111 | AO: "AO",
112 | IP: "IP",
113 | BREAK: "BREAK",
114 | DM: "DM",
115 | NOP: "NOP",
116 | SE: "SE",
117 | EOR: "EOR",
118 | LMABORT: "ABORT",
119 | LMSUSP: "SUSP",
120 | LMEOF: "EOF",
121 | OptBINARY: "BINARY",
122 | OptECHO: "ECHO",
123 | OptRCP: "RCP",
124 | OptSGA: "SGA",
125 | OptNAMS: "NAMS",
126 | OptSTATUS: "STATUS",
127 | OptTM: "TM",
128 | OptRCTE: "RCTE",
129 | OptNAOL: "NAOL",
130 | OptNAOP: "NAOP",
131 | OptNAOCRD: "NAOCRD",
132 | OptNAOHTS: "NAOHTS",
133 | OptNAOHTD: "NAOHTD",
134 | OptNAOFFD: "NAOFFD",
135 | OptNAOVTS: "NAOVTS",
136 | OptNAOVTD: "NAOVTD",
137 | OptNAOLFD: "NAOLFD",
138 | OptXASCII: "XASCII",
139 | OptLOGOUT: "LOGOUT",
140 | OptBM: "BM",
141 | OptDET: "DET",
142 | OptSUPDUP: "SUP",
143 | OptSUPDUPOUT: "SUPOUT",
144 | OptSNDLOC: "SNDLOC",
145 | OptTTYPE: "TTYPE",
146 | OptEOR: "EOR",
147 | OptTUID: "TUID",
148 | OptOUTMRK: "OUTMRK",
149 | OptTTYLOC: "TTYLOC",
150 | Opt3270: "3270",
151 | OptX3PAD: "X3PAD",
152 | OptNAWS: "NAWS",
153 | OptTSPEED: "TSPEED",
154 | OptLFLOW: "LFLOW",
155 | OptLINEMODE: "LINEMODE",
156 | OptXDISPLOC: "XDISPLOC",
157 | OptENVIRON: "ENVIRON",
158 | OptAUTH: "AUTH",
159 | OptENCRYPT: "ENCRYPT",
160 | OptNENV: "NENV",
161 | OptTN3270E: "TN3270E",
162 | OptXAUTH: "XAUTH",
163 | OptCHARSET: "CHARSET",
164 | OptCOMPORT: "COMPORT",
165 | OptKERMIT: "KERMIT",
166 | OptMSSP: "MSSP",
167 | OptMCCP: "MCCP",
168 | OptMCCP2: "MCCP2",
169 | OptMXP: "MXP",
170 | OptZMP: "ZMP",
171 | OptGMCP: "GMCP",
172 | }
173 |
174 | type iacStage int
175 |
176 | const (
177 | stCmd iacStage = iota
178 | stArg
179 | stSuboption
180 | stDone
181 | )
182 |
183 | type IACMessage struct {
184 | state iacStage
185 | Command byte
186 | Args []byte
187 | }
188 |
189 | func NewIACMessage() *IACMessage {
190 | iac := &IACMessage{}
191 | iac.Reset()
192 | return iac
193 | }
194 |
195 | func (IACMessage) IsMessage() {}
196 |
197 | func (iac *IACMessage) Reset() {
198 | iac.state = stCmd
199 | iac.Args = make([]byte, 0, 128)
200 | }
201 |
202 | func (iac IACMessage) String() string {
203 | cmdName := codeName[iac.Command]
204 | if cmdName == "" {
205 | cmdName = fmt.Sprintf("%d", iac.Command)
206 | }
207 | argName := fmt.Sprintf("%v", iac.Args[:len(iac.Args)])
208 | if (iac.Command == WILL ||
209 | iac.Command == WONT ||
210 | iac.Command == DO ||
211 | iac.Command == DONT ||
212 | iac.Command == SB) &&
213 | codeName[iac.Args[0]] != "" {
214 | argName = codeName[iac.Args[0]]
215 | }
216 |
217 | return fmt.Sprintf("IAC %s %s", cmdName, argName)
218 | }
219 |
220 | func (iac IACMessage) Eq(command byte, args ...byte) bool {
221 | if iac.Command != command {
222 | return false
223 | }
224 |
225 | return bytes.Equal(iac.Args, args)
226 | }
227 |
228 | func (iac *IACMessage) Scan(b byte) (completed bool) {
229 | switch iac.state {
230 | case stCmd:
231 | switch b {
232 | case WILL, WONT, DO, DONT:
233 | iac.Command = b
234 | iac.state = stArg
235 | return false
236 | case SB:
237 | iac.Command = SB
238 | iac.state = stSuboption
239 | return false
240 | case SE:
241 | iac.Command = SE
242 | iac.state = stDone
243 | return true
244 | case GA:
245 | iac.Command = GA
246 | iac.state = stDone
247 | return true
248 | default:
249 | // TODO: 需要处理未知 IAC 指令
250 | iac.state = stDone
251 | return true
252 | }
253 | case stArg:
254 | iac.Args = append(iac.Args, b)
255 | iac.state = stDone
256 | return true
257 | case stSuboption:
258 | iac.Args = append(iac.Args, b)
259 | return false
260 | default:
261 | iac.state = stDone
262 | // TODO: 需要处理未知 IAC 指令
263 | return true
264 | }
265 | }
266 |
--------------------------------------------------------------------------------
/mud/mud.go:
--------------------------------------------------------------------------------
1 | package mud
2 |
3 | import (
4 | "bytes"
5 | "fmt"
6 | "io"
7 | "io/ioutil"
8 | "net"
9 | "os"
10 | "strings"
11 | "time"
12 | "unicode"
13 | "unicode/utf8"
14 |
15 | "github.com/flw-cn/printer"
16 | "golang.org/x/text/encoding"
17 | "golang.org/x/text/encoding/simplifiedchinese"
18 | "golang.org/x/text/encoding/traditionalchinese"
19 | "golang.org/x/text/transform"
20 | )
21 |
22 | type Config struct {
23 | IACDebug bool
24 | Host string `flag:"H|mud.pkuxkx.net|服务器 {IP/Domain}"`
25 | Port int `flag:"P|8080|服务器 {Port}"`
26 | Encodings string `flag:"|UTF-8,GB18030,GBK,GB2312|服务器的 {Encodings},允许指定多个,用逗号分隔"`
27 | }
28 |
29 | type Server struct {
30 | printer.SimplePrinter
31 |
32 | config Config
33 |
34 | screen printer.Printer
35 | server printer.WritePrinter
36 |
37 | conn net.Conn
38 | input chan string
39 |
40 | encodings []encoding.Encoding
41 | decoder *encoding.Decoder
42 | encoder *encoding.Encoder
43 | }
44 |
45 | func NewServer(config Config) *Server {
46 | mud := &Server{
47 | config: config,
48 | screen: printer.NewSimplePrinter(os.Stdout),
49 | server: printer.NewSimplePrinter(ioutil.Discard),
50 | input: make(chan string, 1024),
51 | }
52 |
53 | encodings := strings.Split(config.Encodings, ",")
54 | for _, enc := range encodings {
55 | mud.encodings = append(mud.encodings, resolveEncoding(enc))
56 | }
57 |
58 | if len(mud.encodings) == 0 {
59 | mud.encodings = []encoding.Encoding{encoding.Nop}
60 | }
61 |
62 | mud.decoder = mud.encodings[0].NewDecoder()
63 | mud.encoder = mud.encodings[0].NewEncoder()
64 |
65 | mud.SetOutput(mud.server)
66 |
67 | return mud
68 | }
69 |
70 | func (mud *Server) SetScreen(w printer.Printer) {
71 | mud.screen = w
72 | }
73 |
74 | func (mud *Server) Run() {
75 | serverAddress := fmt.Sprintf("%s:%d", mud.config.Host, mud.config.Port)
76 | mud.screen.Printf("连接到服务器 %s...", serverAddress)
77 |
78 | var err error
79 | mud.conn, err = net.DialTimeout("tcp", serverAddress, 4*time.Second)
80 |
81 | if err != nil {
82 | mud.screen.Println("连接失败。")
83 | mud.screen.Printf("失败原因: %v\n", err)
84 | close(mud.input)
85 | return
86 | }
87 |
88 | mud.screen.Println("连接成功。")
89 |
90 | netWriter := transform.NewWriter(mud.conn, mud.encoder)
91 | mud.server.SetOutput(netWriter)
92 |
93 | scanner := NewScanner(mud.conn)
94 |
95 | mud.conn.Write([]byte{IAC, DONT, OptSGA})
96 |
97 | LOOP:
98 | for {
99 | msg := scanner.Scan()
100 |
101 | switch m := msg.(type) {
102 | case EOF:
103 | break LOOP
104 | case IncompleteLine:
105 | str := mud.tryDecode(m)
106 | mud.input <- str
107 | case Line:
108 | str := mud.tryDecode(m)
109 | mud.input <- str
110 | case IACMessage:
111 | mud.telnetNegotiate(m)
112 | }
113 | }
114 |
115 | mud.server.SetOutput(ioutil.Discard)
116 |
117 | mud.screen.Println("连接已断开。")
118 | mud.screen.Println("TODO: 这里需要实现自动重连。")
119 |
120 | close(mud.input)
121 | }
122 |
123 | func (mud *Server) tryDecode(r io.Reader) string {
124 | rawBuf, _ := ioutil.ReadAll(r)
125 |
126 | buf, _ := mud.decoder.Bytes(rawBuf)
127 | if utf8.Valid(buf) && !bytes.ContainsRune(buf, unicode.ReplacementChar) {
128 | return string(buf)
129 | }
130 |
131 | for _, enc := range mud.encodings {
132 | decoder := enc.NewDecoder()
133 | buf, _ := decoder.Bytes(rawBuf)
134 | if utf8.Valid(buf) && !bytes.ContainsRune(buf, unicode.ReplacementChar) {
135 | mud.decoder = decoder
136 | mud.encoder = enc.NewEncoder()
137 | return string(buf)
138 | }
139 | }
140 |
141 | buf, _ = mud.decoder.Bytes(rawBuf)
142 | return string(buf)
143 | }
144 |
145 | func (mud *Server) telnetNegotiate(m IACMessage) {
146 | switch {
147 | case m.Eq(WILL, OptZMP):
148 | mud.conn.Write([]byte{IAC, DO, OptZMP})
149 | go func() {
150 | for {
151 | time.Sleep(10 * time.Second)
152 | mud.conn.Write([]byte{IAC, SB, OptZMP})
153 | mud.conn.Write([]byte("zmp.ping"))
154 | mud.conn.Write([]byte{0, IAC, SE})
155 | }
156 | }()
157 | case m.Eq(DO, OptTTYPE):
158 | mud.conn.Write([]byte{IAC, WILL, OptTTYPE})
159 | case m.Eq(SB, OptTTYPE, 0x01):
160 | mud.conn.Write(append([]byte{IAC, SB, OptTTYPE, 0x00}, []byte("GoMud")...))
161 | mud.conn.Write([]byte{IAC, SE})
162 | case m.Eq(WILL):
163 | mud.conn.Write([]byte{IAC, DONT, m.Args[0]})
164 | case m.Eq(DO):
165 | mud.conn.Write([]byte{IAC, WONT, m.Args[0]})
166 | case m.Eq(GA):
167 | // FIXME: 接收到 GA 后,应当强制完成当前的不完整的行。
168 | // TODO: 更进一步地,应当在 GA 收到前,阻止用户发送命令。
169 | // 为了不影响用户体验,可以允许输入,但不允许回车发送,等到收到 GA 后再发送。
170 | // TODO: 此功能应当仅当 GA 可用时打开,且允许用户通过配置文件关闭。
171 | }
172 | // TODO: IAC 不继续传递给 UI
173 | if mud.config.IACDebug {
174 | mud.input <- m.String()
175 | }
176 | }
177 |
178 | func (mud *Server) Stop() {
179 | if mud.conn != nil {
180 | mud.conn.Close()
181 | }
182 | }
183 |
184 | func (mud *Server) Input() <-chan string {
185 | return mud.input
186 | }
187 |
188 | func resolveEncoding(e string) encoding.Encoding {
189 | e = strings.ToUpper(e)
190 | switch e {
191 | case "GB2312", "HZ-GB-2312", "HZGB2312", "EUC-CN", "EUCCN":
192 | return simplifiedchinese.HZGB2312
193 | case "GBK", "CP936":
194 | return simplifiedchinese.GBK
195 | case "GB18030":
196 | return simplifiedchinese.GB18030
197 | case "BIG5", "BIG-5", "BIG-FIVE":
198 | return traditionalchinese.Big5
199 | case "UTF8", "UTF-8":
200 | return encoding.Nop
201 | }
202 |
203 | return encoding.Nop
204 | }
205 |
--------------------------------------------------------------------------------
/mud/scan.go:
--------------------------------------------------------------------------------
1 | package mud
2 |
3 | import (
4 | "bytes"
5 | "io"
6 | "net"
7 | "time"
8 | )
9 |
10 | type Message interface {
11 | IsMessage()
12 | }
13 |
14 | type CSIMessage struct {
15 | Parameter bytes.Buffer
16 | Intermediate bytes.Buffer
17 | Command byte
18 | }
19 |
20 | type Line struct{ *bytes.Buffer }
21 |
22 | type IncompleteLine struct{ *bytes.Buffer }
23 |
24 | type EOF bool
25 |
26 | func (CSIMessage) IsMessage() {}
27 | func (Line) IsMessage() {}
28 | func (IncompleteLine) IsMessage() {}
29 | func (EOF) IsMessage() {}
30 |
31 | type ReaderWithDeadline interface {
32 | io.Reader
33 | SetReadDeadline(t time.Time) error
34 | }
35 |
36 | type Scanner struct {
37 | r ReaderWithDeadline
38 | buf bytes.Buffer
39 | state ScannerStatus
40 | // msg Message
41 | done bool
42 | }
43 |
44 | type ScannerStatus int
45 |
46 | const (
47 | stText ScannerStatus = iota
48 | stIACCommand
49 | // stANSICodes
50 | )
51 |
52 | func NewScanner(r ReaderWithDeadline) *Scanner {
53 | return &Scanner{
54 | r: r,
55 | }
56 | }
57 |
58 | func (s *Scanner) Scan() Message {
59 | if s.done {
60 | return EOF(true)
61 | }
62 |
63 | iacCmd := NewIACMessage()
64 | line := new(bytes.Buffer)
65 |
66 | for {
67 | b, err := s.readByte()
68 | if err == io.EOF {
69 | s.done = true
70 | return EOF(true)
71 | } else if err != nil {
72 | if line.Len() == 0 {
73 | continue
74 | } else {
75 | return IncompleteLine{line}
76 | }
77 | }
78 |
79 | switch s.state {
80 | case stText:
81 | switch b {
82 | case IAC:
83 | s.state = stIACCommand
84 | if line.Len() > 0 {
85 | return IncompleteLine{line}
86 | }
87 | case '\r': // 忽略
88 | case '\n':
89 | return Line{line}
90 | default:
91 | line.WriteByte(b)
92 | }
93 |
94 | case stIACCommand:
95 | if b == IAC {
96 | return *iacCmd
97 | } else if iacCmd.Scan(b) {
98 | s.state = stText
99 | return *iacCmd
100 | }
101 | }
102 | }
103 | }
104 |
105 | // readByte 努力读取一个字节,并返回成功(nil)或两种错误之一:
106 | // timeout: 超时
107 | // io.EOF: 连接已经不可用
108 | // 优先从 s.buf 中读取,如果 s.buf 为空,则从 s.r 中读取。
109 | func (s *Scanner) readByte() (byte, error) {
110 | b, err := s.buf.ReadByte()
111 | if err != io.EOF {
112 | return b, err
113 | }
114 |
115 | _ = s.r.SetReadDeadline(time.Now().Add(1 * time.Second))
116 | bytes := make([]byte, 1024)
117 | n, err := s.r.Read(bytes)
118 | if err == nil && n > 0 {
119 | s.buf.Write(bytes[:n])
120 | return s.buf.ReadByte()
121 | }
122 |
123 | e, ok := err.(net.Error)
124 | if ok && (e.Timeout() || e.Temporary()) {
125 | return 0, err
126 | }
127 |
128 | return 0, io.EOF
129 | }
130 |
--------------------------------------------------------------------------------
/ui/console_stub.go:
--------------------------------------------------------------------------------
1 | // +build !windows
2 |
3 | // Copyright 2015 The TCell Authors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use file except in compliance with the License.
7 | // You may obtain a copy of the license at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 |
17 | package ui
18 |
19 | // InitConsole initializes the Windows(R) console. This platform
20 | // doesn't need to do anything.
21 | func InitConsole(title string) {
22 | }
23 |
--------------------------------------------------------------------------------
/ui/console_win.go:
--------------------------------------------------------------------------------
1 | // +build windows
2 |
3 | package ui
4 |
5 | import (
6 | "syscall"
7 | "unsafe"
8 | )
9 |
10 | var k32 = syscall.NewLazyDLL("kernel32.dll")
11 | var u32 = syscall.NewLazyDLL("user32.dll")
12 |
13 | var (
14 | consoleStdout syscall.Handle
15 | procGetConsoleScreenBufferInfo = k32.NewProc("GetConsoleScreenBufferInfo")
16 | procSetConsoleScreenBufferSize = k32.NewProc("SetConsoleScreenBufferSize")
17 | procSetConsoleWindowInfo = k32.NewProc("SetConsoleWindowInfo")
18 | procGetConsoleWindow = k32.NewProc("GetConsoleWindow")
19 | procShowWindow = u32.NewProc("ShowWindow")
20 | procSetWindowPos = u32.NewProc("SetWindowPos")
21 | procSetConsoleTitle = k32.NewProc("SetConsoleTitleW")
22 | )
23 |
24 | const (
25 | SW_MAXIMIZE = 3
26 | SW_RESTORE = 9
27 | )
28 |
29 | func InitConsole(title string) {
30 | maximizeConsole()
31 | setConsoleTitle(title)
32 | }
33 |
34 | type coord struct {
35 | x int16
36 | y int16
37 | }
38 |
39 | func (c coord) uintptr() uintptr {
40 | // little endian, put x first
41 | return uintptr(c.x) | (uintptr(c.y) << 16)
42 | }
43 |
44 | type rect struct {
45 | left int16
46 | top int16
47 | right int16
48 | bottom int16
49 | }
50 |
51 | type consoleInfo struct {
52 | size coord
53 | pos coord
54 | attrs uint16
55 | win rect
56 | maxsz coord
57 | }
58 |
59 | func getConsoleInfo(info *consoleInfo) {
60 | procGetConsoleScreenBufferInfo.Call(
61 | uintptr(consoleStdout),
62 | uintptr(unsafe.Pointer(info)))
63 | }
64 |
65 | func setBufferSize(x, y int) {
66 | procSetConsoleScreenBufferSize.Call(
67 | uintptr(consoleStdout),
68 | coord{int16(x), int16(y)}.uintptr())
69 | }
70 |
71 | func setConsoleInfo(rc *rect) {
72 | procSetConsoleWindowInfo.Call(
73 | uintptr(consoleStdout),
74 | uintptr(1),
75 | uintptr(unsafe.Pointer(rc)))
76 | }
77 |
78 | func getConsoleWindow() uintptr {
79 | consoleWindow, _, _ := procGetConsoleWindow.Call()
80 | return consoleWindow
81 | }
82 |
83 | func setConsoleTitle(title string) {
84 | procSetConsoleTitle.Call(uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(title))))
85 | }
86 |
87 | func maximizeConsole() {
88 | consoleStdout, _ = syscall.Open("CONOUT$", syscall.O_RDWR, 0)
89 | info := consoleInfo{}
90 | getConsoleInfo(&info)
91 | setBufferSize(10000, 1000)
92 | win := getConsoleWindow()
93 | procShowWindow.Call(uintptr(win), uintptr(SW_MAXIMIZE))
94 | getConsoleInfo(&info)
95 | procShowWindow.Call(uintptr(win), uintptr(SW_RESTORE))
96 | rc := rect{top: 0, left: 0, right: info.win.right + 1, bottom: info.win.bottom + 1}
97 | setConsoleInfo(&rc)
98 | procSetWindowPos.Call(
99 | uintptr(win),
100 | uintptr(0), // HWND_TOP,
101 | uintptr(1), // x,
102 | uintptr(1), // y,
103 | uintptr(0), // cx (ignore by SWP_NOSIZE),
104 | uintptr(0), // cy (ignore by SWP_NOSIZE),
105 | uintptr(1), // SWP_NOSIZE
106 | )
107 | }
108 |
--------------------------------------------------------------------------------
/ui/readline.go:
--------------------------------------------------------------------------------
1 | package ui
2 |
3 | import (
4 | "strings"
5 |
6 | "github.com/gdamore/tcell"
7 | "github.com/rivo/tview"
8 | )
9 |
10 | const defaultHistorySize = 10000
11 |
12 | type Readline struct {
13 | *tview.InputField
14 |
15 | history []string
16 | curSel int
17 | historySize int
18 |
19 | repeat bool
20 | autoTrim bool
21 | }
22 |
23 | func NewReadline() *Readline {
24 | return &Readline{
25 | InputField: tview.NewInputField(),
26 | history: make([]string, 0, 32),
27 | curSel: 0,
28 | historySize: defaultHistorySize,
29 | }
30 | }
31 |
32 | func (r *Readline) SetRepeat(b bool) *Readline {
33 | r.repeat = b
34 | return r
35 | }
36 |
37 | func (r *Readline) SetAutoTrim(b bool) *Readline {
38 | r.autoTrim = b
39 | return r
40 | }
41 |
42 | func (r *Readline) InputCapture(event *tcell.EventKey) *tcell.EventKey {
43 | switch event.Key() {
44 | case tcell.KeyCtrlC:
45 | r.InputField.SetText("")
46 | return nil
47 | case tcell.KeyUp:
48 | if r.curSel > 0 {
49 | r.curSel--
50 | r.InputField.SetText(r.history[r.curSel])
51 | }
52 | return nil
53 | case tcell.KeyDown:
54 | if r.curSel == len(r.history)-1 {
55 | r.curSel++
56 | r.InputField.SetText("")
57 | }
58 | if r.curSel < len(r.history)-1 {
59 | r.curSel++
60 | r.InputField.SetText(r.history[r.curSel])
61 | }
62 | return nil
63 | default:
64 | }
65 |
66 | return event
67 | }
68 |
69 | func (r *Readline) Enter() string {
70 | text := r.InputField.GetText()
71 |
72 | if text != "" && r.autoTrim {
73 | text = strings.TrimSpace(text)
74 | // 如果 trim 之后变成了空串,则至少保留一个空格,以免用户发不出空格
75 | if text == "" {
76 | text = " "
77 | }
78 | }
79 |
80 | last := ""
81 | if len(r.history) > 0 {
82 | last = r.history[len(r.history)-1]
83 | }
84 |
85 | if text == "" && r.repeat && last != "" {
86 | text = last
87 | } else if text != " " && text != last {
88 | if len(r.history) >= r.historySize {
89 | r.history = r.history[1 : len(r.history)-1]
90 | }
91 | r.history = append(r.history, text)
92 | r.curSel = len(r.history)
93 | }
94 |
95 | r.InputField.SetText("")
96 |
97 | return text
98 | }
99 |
--------------------------------------------------------------------------------
/ui/ui.go:
--------------------------------------------------------------------------------
1 | package ui
2 |
3 | import (
4 | "fmt"
5 | "io"
6 | "runtime"
7 | "strings"
8 | "sync"
9 |
10 | "github.com/flw-cn/printer"
11 | "github.com/gdamore/tcell"
12 | "github.com/rivo/tview"
13 | )
14 |
15 | type Config struct {
16 | AmbiguousWidth string `flag:"|auto|二义性字符宽度,可选值: auto/single/double/space"`
17 | HistoryLines int `flag:"|100000|历史记录保留行数"`
18 | RTTVHeight int `flag:"|10|历史查看模式下实时文本区域高度"`
19 | }
20 |
21 | type UI struct {
22 | printer.Printer
23 | sync.Mutex
24 |
25 | config Config
26 | app *tview.Application
27 |
28 | ansiWriter io.Writer
29 | pages *tview.Pages
30 | historyTV *tview.TextView
31 | sepLine *tview.TextView
32 | realtimeTV *tview.TextView
33 | cmdLine *Readline
34 |
35 | buffer []string
36 | unformed bool
37 | scrolling bool
38 | offset int
39 |
40 | input chan string
41 | }
42 |
43 | func init() {
44 | tcell.ColorValues[tcell.ColorYellow] = 0xC7C400
45 | tcell.ColorValues[tcell.ColorWhite] = 0xC7C7C7
46 | tcell.ColorValues[tcell.ColorGreen] = 0x00C200
47 | }
48 |
49 | func NewUI(config Config) *UI {
50 | return &UI{
51 | config: config,
52 | input: make(chan string, 10),
53 | }
54 | }
55 |
56 | func (ui *UI) Create(title string) {
57 | InitConsole(title)
58 |
59 | ui.app = tview.NewApplication()
60 | ui.historyTV = tview.NewTextView().
61 | SetDynamicColors(true).
62 | SetScrollable(true).
63 | SetChangedFunc(func() {
64 | ui.app.Draw()
65 | })
66 |
67 | ui.realtimeTV = tview.NewTextView().
68 | SetDynamicColors(true).
69 | SetScrollable(false).
70 | SetChangedFunc(func() {
71 | ui.app.Draw()
72 | })
73 |
74 | ui.ansiWriter = tview.ANSIWriter(ui.realtimeTV)
75 |
76 | ui.cmdLine = NewReadline()
77 | ui.cmdLine.SetRepeat(true).
78 | SetAutoTrim(true).
79 | SetFieldBackgroundColor(tcell.ColorBlack).
80 | SetLabelColor(tcell.ColorWhite).
81 | SetLabel("命令: ")
82 |
83 | ui.cmdLine.SetChangedFunc(ui.cmdLineTextChanged)
84 |
85 | ui.sepLine = tview.NewTextView().
86 | SetTextAlign(tview.AlignCenter)
87 |
88 | ui.sepLine.SetBackgroundColor(tcell.ColorBlue)
89 |
90 | historyView := tview.NewFlex().SetDirection(tview.FlexRow).
91 | AddItem(ui.historyTV, 0, 1, false).
92 | AddItem(ui.sepLine, 1, 1, false).
93 | AddItem(ui.realtimeTV, ui.config.RTTVHeight, 1, false)
94 |
95 | ui.pages = tview.NewPages().
96 | AddPage("historyView", historyView, true, false).
97 | AddPage("mainView", ui.realtimeTV, true, true)
98 |
99 | mainView := tview.NewFlex().SetDirection(tview.FlexRow).
100 | AddItem(ui.pages, 0, 1, false).
101 | AddItem(ui.cmdLine, 1, 1, false)
102 |
103 | if runtime.GOOS == "windows" {
104 | imStatusLine := tview.NewBox()
105 | mainView.AddItem(imStatusLine, 1, 1, false)
106 | }
107 |
108 | ui.app.SetRoot(mainView, true).
109 | SetFocus(ui.cmdLine).
110 | SetInputCapture(ui.InputCapture)
111 | }
112 |
113 | func (ui *UI) InputCapture(event *tcell.EventKey) *tcell.EventKey {
114 | key := event.Key()
115 |
116 | if ui.isScrolling() {
117 | if key == tcell.KeyCtrlC {
118 | ui.stopScrolling()
119 | ui.app.SetFocus(ui.cmdLine)
120 | } else {
121 | ui.historyInputCapture(event)
122 | }
123 | return nil
124 | }
125 |
126 | if key == tcell.KeyCtrlB || key == tcell.KeyPgUp {
127 | ui.app.SetFocus(ui.historyTV)
128 | ui.startScrolling()
129 | ui.pageUp(10)
130 | return nil
131 | }
132 |
133 | if key == tcell.KeyEnter {
134 | cmd := ui.cmdLine.Enter()
135 | ui.input <- cmd
136 | return nil
137 | }
138 |
139 | return ui.cmdLine.InputCapture(event)
140 | }
141 |
142 | func (ui *UI) cmdLineTextChanged(text string) {
143 | if len(text) == 0 {
144 | return
145 | }
146 |
147 | switch text[0] {
148 | case '"':
149 | ui.cmdLine.SetLabel("闲聊: ").
150 | SetLabelColor(tcell.ColorLightCyan).
151 | SetFieldTextColor(tcell.ColorLightCyan)
152 | case '*':
153 | ui.cmdLine.SetLabel("表情: ").
154 | SetLabelColor(tcell.ColorLime).
155 | SetFieldTextColor(tcell.ColorLime)
156 | case '\'':
157 | ui.cmdLine.SetLabel("说话: ").
158 | SetLabelColor(tcell.ColorDarkCyan).
159 | SetFieldTextColor(tcell.ColorDarkCyan)
160 | case ';':
161 | ui.cmdLine.SetLabel("谣言: ").
162 | SetLabelColor(tcell.ColorPink).
163 | SetFieldTextColor(tcell.ColorPink)
164 | default:
165 | ui.cmdLine.SetLabel("命令: ").
166 | SetLabelColor(tcell.ColorWhite).
167 | SetFieldTextColor(tcell.ColorLightGrey)
168 | }
169 | }
170 |
171 | func (ui *UI) historyInputCapture(event *tcell.EventKey) *tcell.EventKey {
172 | switch event.Key() {
173 | case tcell.KeyCtrlB, tcell.KeyPgUp:
174 | ui.pageUp(10)
175 | case tcell.KeyCtrlF, tcell.KeyPgDn:
176 | ui.pageDown(10)
177 | case tcell.KeyRune:
178 | switch event.Rune() {
179 | case 'k':
180 | ui.pageUp(1)
181 | case 'j':
182 | ui.pageDown(1)
183 | case 'g':
184 | ui.pageHome()
185 | case 'G':
186 | ui.pageEnd()
187 | }
188 | default:
189 | }
190 |
191 | return nil
192 | }
193 |
194 | func (ui *UI) Run() {
195 | defer ui.app.Stop()
196 |
197 | if err := ui.app.Run(); err != nil {
198 | panic(err)
199 | }
200 | }
201 |
202 | func (ui *UI) Stop() {
203 | ui.app.Stop()
204 | close(ui.input)
205 | }
206 |
207 | func (ui *UI) Input() <-chan string {
208 | return ui.input
209 | }
210 |
211 | func (ui *UI) startScrolling() {
212 | ui.Lock()
213 | defer ui.Unlock()
214 |
215 | if ui.scrolling {
216 | return
217 | }
218 |
219 | ui.scrolling = true
220 | _, _, _, height := ui.pages.GetInnerRect()
221 | ui.pages.SwitchToPage("historyView")
222 | ui.offset = len(ui.buffer) - height + 1
223 | ui.app.Draw()
224 | }
225 |
226 | func (ui *UI) stopScrolling() {
227 | ui.Lock()
228 | defer ui.Unlock()
229 |
230 | if !ui.scrolling {
231 | return
232 | }
233 |
234 | ui.pages.SwitchToPage("mainView")
235 | end := len(ui.buffer)
236 | _, _, _, height := ui.pages.GetRect()
237 | ui.offset = end - height
238 | ui.scrolling = false
239 | text := strings.Join(ui.buffer[ui.offset:end], "\n")
240 | text = tview.TranslateANSI(text + "\n")
241 | ui.realtimeTV.SetText(text)
242 | }
243 |
244 | func (ui *UI) isScrolling() bool {
245 | ui.Lock()
246 | defer ui.Unlock()
247 |
248 | scrolling := ui.scrolling
249 | return scrolling
250 | }
251 |
252 | func (ui *UI) pageUp(pageSize int) {
253 | ui.Lock()
254 | defer ui.Unlock()
255 |
256 | if !ui.scrolling {
257 | return
258 | }
259 |
260 | ui.offset -= pageSize
261 | ui.drawHistory()
262 | }
263 |
264 | func (ui *UI) pageDown(pageSize int) {
265 | ui.Lock()
266 | defer ui.Unlock()
267 |
268 | if !ui.scrolling {
269 | return
270 | }
271 |
272 | ui.offset += pageSize
273 | ui.drawHistory()
274 | }
275 |
276 | func (ui *UI) pageHome() {
277 | ui.Lock()
278 | defer ui.Unlock()
279 |
280 | if !ui.scrolling {
281 | return
282 | }
283 |
284 | ui.offset = 0
285 | ui.drawHistory()
286 | }
287 |
288 | func (ui *UI) pageEnd() {
289 | ui.Lock()
290 | defer ui.Unlock()
291 |
292 | if !ui.scrolling {
293 | return
294 | }
295 |
296 | ui.offset = len(ui.buffer)
297 | ui.drawHistory()
298 | }
299 |
300 | func (ui *UI) drawHistory() {
301 | if ui.offset < 0 {
302 | ui.offset = 0
303 | }
304 |
305 | _, _, _, height := ui.historyTV.GetInnerRect()
306 | end := ui.offset + height
307 | stopLine := len(ui.buffer) - ui.config.RTTVHeight
308 | if end > stopLine {
309 | end = stopLine
310 | ui.offset = end - height
311 | if ui.offset < 0 {
312 | ui.offset = 0
313 | }
314 | }
315 |
316 | hint := "PageUp/PageDown/Ctrl+B/F 向上/下翻屏, k/j 向上/下滚动, g/G 滚到头/尾, Ctrl+C 结束翻屏"
317 | status := fmt.Sprintf("%d~%d/%d(%d%%)", ui.offset, end, stopLine, ui.offset*100/stopLine)
318 | ui.sepLine.SetText(fmt.Sprintf("%s %25s", hint, status))
319 | text := strings.Join(ui.buffer[ui.offset:end], "\n")
320 | text = tview.TranslateANSI(text)
321 | ui.historyTV.SetText(text)
322 | }
323 |
324 | func (ui *UI) SetOutput(w io.Writer) {
325 | }
326 |
327 | func (ui *UI) Print(a ...interface{}) (n int, err error) {
328 | str := fmt.Sprint(a...)
329 |
330 | if len(str) == 0 {
331 | return 0, nil
332 | }
333 |
334 | lines := strings.Split(str, "\n")
335 |
336 | count := len(lines)
337 | // 根据 strings.Split 的定义,如果 str 以换行符结束,则 lines 的最后一行为空串
338 | unformed := len(lines[count-1]) > 0
339 | if !unformed {
340 | count--
341 | }
342 |
343 | i := 0
344 | ui.Lock()
345 | defer ui.Unlock()
346 | l := len(ui.buffer)
347 | if ui.unformed {
348 | ui.buffer[l-1] += lines[0]
349 | i++
350 | }
351 |
352 | for ; i < count; i++ {
353 | ui.buffer = append(ui.buffer, lines[i])
354 | }
355 |
356 | if len(ui.buffer) > ui.config.HistoryLines {
357 | offset := len(ui.buffer) - ui.config.HistoryLines
358 | ui.buffer = ui.buffer[offset:len(ui.buffer)]
359 | }
360 |
361 | ui.unformed = unformed
362 |
363 | fmt.Fprint(ui.ansiWriter, str)
364 |
365 | return len(str), nil
366 | }
367 |
368 | func (ui *UI) Println(a ...interface{}) (n int, err error) {
369 | str := fmt.Sprintln(a...)
370 | return ui.Print(str)
371 | }
372 |
373 | func (ui *UI) Printf(format string, a ...interface{}) (n int, err error) {
374 | str := fmt.Sprintf(format, a...)
375 | return ui.Print(str)
376 | }
377 |
--------------------------------------------------------------------------------