├── .gitignore
├── LICENSE.md
├── README.md
├── cli.js
├── dat.json
├── index.js
├── output.gif
├── package-lock.json
└── package.json
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .nyc_output
3 | npm-debug.log
4 | .travis.yml
5 | demo.html
6 | index.html
7 | wa.js
8 | .datignore
9 | .dat
10 | boooo.css
11 | test.txt
12 | demo2.html
13 | by-lines.txt
14 | a-dir
15 | yarn-error.log
16 | node_modules_bak
17 | bah/
18 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | GNU Affero General Public License
2 | =================================
3 |
4 | _Version 3, 19 November 2007_
5 |
6 | _Copyright © 2007 Free Software Foundation, Inc. _
7 |
8 | Everyone is permitted to copy and distribute verbatim copies
9 | of this license document, but changing it is not allowed.
10 |
11 | **Note:**
12 | was converted to markdown in this version.
13 |
14 | ## Preamble
15 |
16 | The GNU Affero General Public License is a free, copyleft license for
17 | software and other kinds of works, specifically designed to ensure
18 | cooperation with the community in the case of network server software.
19 |
20 | The licenses for most software and other practical works are designed
21 | to take away your freedom to share and change the works. By contrast,
22 | our General Public Licenses are intended to guarantee your freedom to
23 | share and change all versions of a program--to make sure it remains free
24 | software for all its users.
25 |
26 | When we speak of free software, we are referring to freedom, not
27 | price. Our General Public Licenses are designed to make sure that you
28 | have the freedom to distribute copies of free software (and charge for
29 | them if you wish), that you receive source code or can get it if you
30 | want it, that you can change the software or use pieces of it in new
31 | free programs, and that you know you can do these things.
32 |
33 | Developers that use our General Public Licenses protect your rights
34 | with two steps: **(1)** assert copyright on the software, and **(2)** offer
35 | you this License which gives you legal permission to copy, distribute
36 | and/or modify the software.
37 |
38 | A secondary benefit of defending all users' freedom is that
39 | improvements made in alternate versions of the program, if they
40 | receive widespread use, become available for other developers to
41 | incorporate. Many developers of free software are heartened and
42 | encouraged by the resulting cooperation. However, in the case of
43 | software used on network servers, this result may fail to come about.
44 | The GNU General Public License permits making a modified version and
45 | letting the public access it on a server without ever releasing its
46 | source code to the public.
47 |
48 | The GNU Affero General Public License is designed specifically to
49 | ensure that, in such cases, the modified source code becomes available
50 | to the community. It requires the operator of a network server to
51 | provide the source code of the modified version running there to the
52 | users of that server. Therefore, public use of a modified version, on
53 | a publicly accessible server, gives the public access to the source
54 | code of the modified version.
55 |
56 | An older license, called the Affero General Public License and
57 | published by Affero, was designed to accomplish similar goals. This is
58 | a different license, not a version of the Affero GPL, but Affero has
59 | released a new version of the Affero GPL which permits relicensing under
60 | this license.
61 |
62 | The precise terms and conditions for copying, distribution and
63 | modification follow.
64 |
65 | ## TERMS AND CONDITIONS
66 |
67 | ### 0. Definitions
68 |
69 | “This License” refers to version 3 of the GNU Affero General Public License.
70 |
71 | “Copyright” also means copyright-like laws that apply to other kinds of
72 | works, such as semiconductor masks.
73 |
74 | “The Program” refers to any copyrightable work licensed under this
75 | License. Each licensee is addressed as “you”. “Licensees” and
76 | “recipients” may be individuals or organizations.
77 |
78 | To “modify” a work means to copy from or adapt all or part of the work
79 | in a fashion requiring copyright permission, other than the making of an
80 | exact copy. The resulting work is called a “modified version” of the
81 | earlier work or a work “based on” the earlier work.
82 |
83 | A “covered work” means either the unmodified Program or a work based
84 | on the Program.
85 |
86 | To “propagate” a work means to do anything with it that, without
87 | permission, would make you directly or secondarily liable for
88 | infringement under applicable copyright law, except executing it on a
89 | computer or modifying a private copy. Propagation includes copying,
90 | distribution (with or without modification), making available to the
91 | public, and in some countries other activities as well.
92 |
93 | To “convey” a work means any kind of propagation that enables other
94 | parties to make or receive copies. Mere interaction with a user through
95 | a computer network, with no transfer of a copy, is not conveying.
96 |
97 | An interactive user interface displays “Appropriate Legal Notices”
98 | to the extent that it includes a convenient and prominently visible
99 | feature that **(1)** displays an appropriate copyright notice, and **(2)**
100 | tells the user that there is no warranty for the work (except to the
101 | extent that warranties are provided), that licensees may convey the
102 | work under this License, and how to view a copy of this License. If
103 | the interface presents a list of user commands or options, such as a
104 | menu, a prominent item in the list meets this criterion.
105 |
106 | ### 1. Source Code
107 |
108 | The “source code” for a work means the preferred form of the work
109 | for making modifications to it. “Object code” means any non-source
110 | form of a work.
111 |
112 | A “Standard Interface” means an interface that either is an official
113 | standard defined by a recognized standards body, or, in the case of
114 | interfaces specified for a particular programming language, one that
115 | is widely used among developers working in that language.
116 |
117 | The “System Libraries” of an executable work include anything, other
118 | than the work as a whole, that **(a)** is included in the normal form of
119 | packaging a Major Component, but which is not part of that Major
120 | Component, and **(b)** serves only to enable use of the work with that
121 | Major Component, or to implement a Standard Interface for which an
122 | implementation is available to the public in source code form. A
123 | “Major Component”, in this context, means a major essential component
124 | (kernel, window system, and so on) of the specific operating system
125 | (if any) on which the executable work runs, or a compiler used to
126 | produce the work, or an object code interpreter used to run it.
127 |
128 | The “Corresponding Source” for a work in object code form means all
129 | the source code needed to generate, install, and (for an executable
130 | work) run the object code and to modify the work, including scripts to
131 | control those activities. However, it does not include the work's
132 | System Libraries, or general-purpose tools or generally available free
133 | programs which are used unmodified in performing those activities but
134 | which are not part of the work. For example, Corresponding Source
135 | includes interface definition files associated with source files for
136 | the work, and the source code for shared libraries and dynamically
137 | linked subprograms that the work is specifically designed to require,
138 | such as by intimate data communication or control flow between those
139 | subprograms and other parts of the work.
140 |
141 | The Corresponding Source need not include anything that users
142 | can regenerate automatically from other parts of the Corresponding
143 | Source.
144 |
145 | The Corresponding Source for a work in source code form is that
146 | same work.
147 |
148 | ### 2. Basic Permissions
149 |
150 | All rights granted under this License are granted for the term of
151 | copyright on the Program, and are irrevocable provided the stated
152 | conditions are met. This License explicitly affirms your unlimited
153 | permission to run the unmodified Program. The output from running a
154 | covered work is covered by this License only if the output, given its
155 | content, constitutes a covered work. This License acknowledges your
156 | rights of fair use or other equivalent, as provided by copyright law.
157 |
158 | You may make, run and propagate covered works that you do not
159 | convey, without conditions so long as your license otherwise remains
160 | in force. You may convey covered works to others for the sole purpose
161 | of having them make modifications exclusively for you, or provide you
162 | with facilities for running those works, provided that you comply with
163 | the terms of this License in conveying all material for which you do
164 | not control copyright. Those thus making or running the covered works
165 | for you must do so exclusively on your behalf, under your direction
166 | and control, on terms that prohibit them from making any copies of
167 | your copyrighted material outside their relationship with you.
168 |
169 | Conveying under any other circumstances is permitted solely under
170 | the conditions stated below. Sublicensing is not allowed; section 10
171 | makes it unnecessary.
172 |
173 | ### 3. Protecting Users' Legal Rights From Anti-Circumvention Law
174 |
175 | No covered work shall be deemed part of an effective technological
176 | measure under any applicable law fulfilling obligations under article
177 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
178 | similar laws prohibiting or restricting circumvention of such
179 | measures.
180 |
181 | When you convey a covered work, you waive any legal power to forbid
182 | circumvention of technological measures to the extent such circumvention
183 | is effected by exercising rights under this License with respect to
184 | the covered work, and you disclaim any intention to limit operation or
185 | modification of the work as a means of enforcing, against the work's
186 | users, your or third parties' legal rights to forbid circumvention of
187 | technological measures.
188 |
189 | ### 4. Conveying Verbatim Copies
190 |
191 | You may convey verbatim copies of the Program's source code as you
192 | receive it, in any medium, provided that you conspicuously and
193 | appropriately publish on each copy an appropriate copyright notice;
194 | keep intact all notices stating that this License and any
195 | non-permissive terms added in accord with section 7 apply to the code;
196 | keep intact all notices of the absence of any warranty; and give all
197 | recipients a copy of this License along with the Program.
198 |
199 | You may charge any price or no price for each copy that you convey,
200 | and you may offer support or warranty protection for a fee.
201 |
202 | ### 5. Conveying Modified Source Versions
203 |
204 | You may convey a work based on the Program, or the modifications to
205 | produce it from the Program, in the form of source code under the
206 | terms of section 4, provided that you also meet all of these conditions:
207 |
208 | * **a)** The work must carry prominent notices stating that you modified
209 | it, and giving a relevant date.
210 | * **b)** The work must carry prominent notices stating that it is
211 | released under this License and any conditions added under section 7.
212 | This requirement modifies the requirement in section 4 to
213 | “keep intact all notices”.
214 | * **c)** You must license the entire work, as a whole, under this
215 | License to anyone who comes into possession of a copy. This
216 | License will therefore apply, along with any applicable section 7
217 | additional terms, to the whole of the work, and all its parts,
218 | regardless of how they are packaged. This License gives no
219 | permission to license the work in any other way, but it does not
220 | invalidate such permission if you have separately received it.
221 | * **d)** If the work has interactive user interfaces, each must display
222 | Appropriate Legal Notices; however, if the Program has interactive
223 | interfaces that do not display Appropriate Legal Notices, your
224 | work need not make them do so.
225 |
226 | A compilation of a covered work with other separate and independent
227 | works, which are not by their nature extensions of the covered work,
228 | and which are not combined with it such as to form a larger program,
229 | in or on a volume of a storage or distribution medium, is called an
230 | “aggregate” if the compilation and its resulting copyright are not
231 | used to limit the access or legal rights of the compilation's users
232 | beyond what the individual works permit. Inclusion of a covered work
233 | in an aggregate does not cause this License to apply to the other
234 | parts of the aggregate.
235 |
236 | ### 6. Conveying Non-Source Forms
237 |
238 | You may convey a covered work in object code form under the terms
239 | of sections 4 and 5, provided that you also convey the
240 | machine-readable Corresponding Source under the terms of this License,
241 | in one of these ways:
242 |
243 | * **a)** Convey the object code in, or embodied in, a physical product
244 | (including a physical distribution medium), accompanied by the
245 | Corresponding Source fixed on a durable physical medium
246 | customarily used for software interchange.
247 | * **b)** Convey the object code in, or embodied in, a physical product
248 | (including a physical distribution medium), accompanied by a
249 | written offer, valid for at least three years and valid for as
250 | long as you offer spare parts or customer support for that product
251 | model, to give anyone who possesses the object code either **(1)** a
252 | copy of the Corresponding Source for all the software in the
253 | product that is covered by this License, on a durable physical
254 | medium customarily used for software interchange, for a price no
255 | more than your reasonable cost of physically performing this
256 | conveying of source, or **(2)** access to copy the
257 | Corresponding Source from a network server at no charge.
258 | * **c)** Convey individual copies of the object code with a copy of the
259 | written offer to provide the Corresponding Source. This
260 | alternative is allowed only occasionally and noncommercially, and
261 | only if you received the object code with such an offer, in accord
262 | with subsection 6b.
263 | * **d)** Convey the object code by offering access from a designated
264 | place (gratis or for a charge), and offer equivalent access to the
265 | Corresponding Source in the same way through the same place at no
266 | further charge. You need not require recipients to copy the
267 | Corresponding Source along with the object code. If the place to
268 | copy the object code is a network server, the Corresponding Source
269 | may be on a different server (operated by you or a third party)
270 | that supports equivalent copying facilities, provided you maintain
271 | clear directions next to the object code saying where to find the
272 | Corresponding Source. Regardless of what server hosts the
273 | Corresponding Source, you remain obligated to ensure that it is
274 | available for as long as needed to satisfy these requirements.
275 | * **e)** Convey the object code using peer-to-peer transmission, provided
276 | you inform other peers where the object code and Corresponding
277 | Source of the work are being offered to the general public at no
278 | charge under subsection 6d.
279 |
280 | A separable portion of the object code, whose source code is excluded
281 | from the Corresponding Source as a System Library, need not be
282 | included in conveying the object code work.
283 |
284 | A “User Product” is either **(1)** a “consumer product”, which means any
285 | tangible personal property which is normally used for personal, family,
286 | or household purposes, or **(2)** anything designed or sold for incorporation
287 | into a dwelling. In determining whether a product is a consumer product,
288 | doubtful cases shall be resolved in favor of coverage. For a particular
289 | product received by a particular user, “normally used” refers to a
290 | typical or common use of that class of product, regardless of the status
291 | of the particular user or of the way in which the particular user
292 | actually uses, or expects or is expected to use, the product. A product
293 | is a consumer product regardless of whether the product has substantial
294 | commercial, industrial or non-consumer uses, unless such uses represent
295 | the only significant mode of use of the product.
296 |
297 | “Installation Information” for a User Product means any methods,
298 | procedures, authorization keys, or other information required to install
299 | and execute modified versions of a covered work in that User Product from
300 | a modified version of its Corresponding Source. The information must
301 | suffice to ensure that the continued functioning of the modified object
302 | code is in no case prevented or interfered with solely because
303 | modification has been made.
304 |
305 | If you convey an object code work under this section in, or with, or
306 | specifically for use in, a User Product, and the conveying occurs as
307 | part of a transaction in which the right of possession and use of the
308 | User Product is transferred to the recipient in perpetuity or for a
309 | fixed term (regardless of how the transaction is characterized), the
310 | Corresponding Source conveyed under this section must be accompanied
311 | by the Installation Information. But this requirement does not apply
312 | if neither you nor any third party retains the ability to install
313 | modified object code on the User Product (for example, the work has
314 | been installed in ROM).
315 |
316 | The requirement to provide Installation Information does not include a
317 | requirement to continue to provide support service, warranty, or updates
318 | for a work that has been modified or installed by the recipient, or for
319 | the User Product in which it has been modified or installed. Access to a
320 | network may be denied when the modification itself materially and
321 | adversely affects the operation of the network or violates the rules and
322 | protocols for communication across the network.
323 |
324 | Corresponding Source conveyed, and Installation Information provided,
325 | in accord with this section must be in a format that is publicly
326 | documented (and with an implementation available to the public in
327 | source code form), and must require no special password or key for
328 | unpacking, reading or copying.
329 |
330 | ### 7. Additional Terms
331 |
332 | “Additional permissions” are terms that supplement the terms of this
333 | License by making exceptions from one or more of its conditions.
334 | Additional permissions that are applicable to the entire Program shall
335 | be treated as though they were included in this License, to the extent
336 | that they are valid under applicable law. If additional permissions
337 | apply only to part of the Program, that part may be used separately
338 | under those permissions, but the entire Program remains governed by
339 | this License without regard to the additional permissions.
340 |
341 | When you convey a copy of a covered work, you may at your option
342 | remove any additional permissions from that copy, or from any part of
343 | it. (Additional permissions may be written to require their own
344 | removal in certain cases when you modify the work.) You may place
345 | additional permissions on material, added by you to a covered work,
346 | for which you have or can give appropriate copyright permission.
347 |
348 | Notwithstanding any other provision of this License, for material you
349 | add to a covered work, you may (if authorized by the copyright holders of
350 | that material) supplement the terms of this License with terms:
351 |
352 | * **a)** Disclaiming warranty or limiting liability differently from the
353 | terms of sections 15 and 16 of this License; or
354 | * **b)** Requiring preservation of specified reasonable legal notices or
355 | author attributions in that material or in the Appropriate Legal
356 | Notices displayed by works containing it; or
357 | * **c)** Prohibiting misrepresentation of the origin of that material, or
358 | requiring that modified versions of such material be marked in
359 | reasonable ways as different from the original version; or
360 | * **d)** Limiting the use for publicity purposes of names of licensors or
361 | authors of the material; or
362 | * **e)** Declining to grant rights under trademark law for use of some
363 | trade names, trademarks, or service marks; or
364 | * **f)** Requiring indemnification of licensors and authors of that
365 | material by anyone who conveys the material (or modified versions of
366 | it) with contractual assumptions of liability to the recipient, for
367 | any liability that these contractual assumptions directly impose on
368 | those licensors and authors.
369 |
370 | All other non-permissive additional terms are considered “further
371 | restrictions” within the meaning of section 10. If the Program as you
372 | received it, or any part of it, contains a notice stating that it is
373 | governed by this License along with a term that is a further
374 | restriction, you may remove that term. If a license document contains
375 | a further restriction but permits relicensing or conveying under this
376 | License, you may add to a covered work material governed by the terms
377 | of that license document, provided that the further restriction does
378 | not survive such relicensing or conveying.
379 |
380 | If you add terms to a covered work in accord with this section, you
381 | must place, in the relevant source files, a statement of the
382 | additional terms that apply to those files, or a notice indicating
383 | where to find the applicable terms.
384 |
385 | Additional terms, permissive or non-permissive, may be stated in the
386 | form of a separately written license, or stated as exceptions;
387 | the above requirements apply either way.
388 |
389 | ### 8. Termination
390 |
391 | You may not propagate or modify a covered work except as expressly
392 | provided under this License. Any attempt otherwise to propagate or
393 | modify it is void, and will automatically terminate your rights under
394 | this License (including any patent licenses granted under the third
395 | paragraph of section 11).
396 |
397 | However, if you cease all violation of this License, then your
398 | license from a particular copyright holder is reinstated **(a)**
399 | provisionally, unless and until the copyright holder explicitly and
400 | finally terminates your license, and **(b)** permanently, if the copyright
401 | holder fails to notify you of the violation by some reasonable means
402 | prior to 60 days after the cessation.
403 |
404 | Moreover, your license from a particular copyright holder is
405 | reinstated permanently if the copyright holder notifies you of the
406 | violation by some reasonable means, this is the first time you have
407 | received notice of violation of this License (for any work) from that
408 | copyright holder, and you cure the violation prior to 30 days after
409 | your receipt of the notice.
410 |
411 | Termination of your rights under this section does not terminate the
412 | licenses of parties who have received copies or rights from you under
413 | this License. If your rights have been terminated and not permanently
414 | reinstated, you do not qualify to receive new licenses for the same
415 | material under section 10.
416 |
417 | ### 9. Acceptance Not Required for Having Copies
418 |
419 | You are not required to accept this License in order to receive or
420 | run a copy of the Program. Ancillary propagation of a covered work
421 | occurring solely as a consequence of using peer-to-peer transmission
422 | to receive a copy likewise does not require acceptance. However,
423 | nothing other than this License grants you permission to propagate or
424 | modify any covered work. These actions infringe copyright if you do
425 | not accept this License. Therefore, by modifying or propagating a
426 | covered work, you indicate your acceptance of this License to do so.
427 |
428 | ### 10. Automatic Licensing of Downstream Recipients
429 |
430 | Each time you convey a covered work, the recipient automatically
431 | receives a license from the original licensors, to run, modify and
432 | propagate that work, subject to this License. You are not responsible
433 | for enforcing compliance by third parties with this License.
434 |
435 | An “entity transaction” is a transaction transferring control of an
436 | organization, or substantially all assets of one, or subdividing an
437 | organization, or merging organizations. If propagation of a covered
438 | work results from an entity transaction, each party to that
439 | transaction who receives a copy of the work also receives whatever
440 | licenses to the work the party's predecessor in interest had or could
441 | give under the previous paragraph, plus a right to possession of the
442 | Corresponding Source of the work from the predecessor in interest, if
443 | the predecessor has it or can get it with reasonable efforts.
444 |
445 | You may not impose any further restrictions on the exercise of the
446 | rights granted or affirmed under this License. For example, you may
447 | not impose a license fee, royalty, or other charge for exercise of
448 | rights granted under this License, and you may not initiate litigation
449 | (including a cross-claim or counterclaim in a lawsuit) alleging that
450 | any patent claim is infringed by making, using, selling, offering for
451 | sale, or importing the Program or any portion of it.
452 |
453 | ### 11. Patents
454 |
455 | A “contributor” is a copyright holder who authorizes use under this
456 | License of the Program or a work on which the Program is based. The
457 | work thus licensed is called the contributor's “contributor version”.
458 |
459 | A contributor's “essential patent claims” are all patent claims
460 | owned or controlled by the contributor, whether already acquired or
461 | hereafter acquired, that would be infringed by some manner, permitted
462 | by this License, of making, using, or selling its contributor version,
463 | but do not include claims that would be infringed only as a
464 | consequence of further modification of the contributor version. For
465 | purposes of this definition, “control” includes the right to grant
466 | patent sublicenses in a manner consistent with the requirements of
467 | this License.
468 |
469 | Each contributor grants you a non-exclusive, worldwide, royalty-free
470 | patent license under the contributor's essential patent claims, to
471 | make, use, sell, offer for sale, import and otherwise run, modify and
472 | propagate the contents of its contributor version.
473 |
474 | In the following three paragraphs, a “patent license” is any express
475 | agreement or commitment, however denominated, not to enforce a patent
476 | (such as an express permission to practice a patent or covenant not to
477 | sue for patent infringement). To “grant” such a patent license to a
478 | party means to make such an agreement or commitment not to enforce a
479 | patent against the party.
480 |
481 | If you convey a covered work, knowingly relying on a patent license,
482 | and the Corresponding Source of the work is not available for anyone
483 | to copy, free of charge and under the terms of this License, through a
484 | publicly available network server or other readily accessible means,
485 | then you must either **(1)** cause the Corresponding Source to be so
486 | available, or **(2)** arrange to deprive yourself of the benefit of the
487 | patent license for this particular work, or **(3)** arrange, in a manner
488 | consistent with the requirements of this License, to extend the patent
489 | license to downstream recipients. “Knowingly relying” means you have
490 | actual knowledge that, but for the patent license, your conveying the
491 | covered work in a country, or your recipient's use of the covered work
492 | in a country, would infringe one or more identifiable patents in that
493 | country that you have reason to believe are valid.
494 |
495 | If, pursuant to or in connection with a single transaction or
496 | arrangement, you convey, or propagate by procuring conveyance of, a
497 | covered work, and grant a patent license to some of the parties
498 | receiving the covered work authorizing them to use, propagate, modify
499 | or convey a specific copy of the covered work, then the patent license
500 | you grant is automatically extended to all recipients of the covered
501 | work and works based on it.
502 |
503 | A patent license is “discriminatory” if it does not include within
504 | the scope of its coverage, prohibits the exercise of, or is
505 | conditioned on the non-exercise of one or more of the rights that are
506 | specifically granted under this License. You may not convey a covered
507 | work if you are a party to an arrangement with a third party that is
508 | in the business of distributing software, under which you make payment
509 | to the third party based on the extent of your activity of conveying
510 | the work, and under which the third party grants, to any of the
511 | parties who would receive the covered work from you, a discriminatory
512 | patent license **(a)** in connection with copies of the covered work
513 | conveyed by you (or copies made from those copies), or **(b)** primarily
514 | for and in connection with specific products or compilations that
515 | contain the covered work, unless you entered into that arrangement,
516 | or that patent license was granted, prior to 28 March 2007.
517 |
518 | Nothing in this License shall be construed as excluding or limiting
519 | any implied license or other defenses to infringement that may
520 | otherwise be available to you under applicable patent law.
521 |
522 | ### 12. No Surrender of Others' Freedom
523 |
524 | If conditions are imposed on you (whether by court order, agreement or
525 | otherwise) that contradict the conditions of this License, they do not
526 | excuse you from the conditions of this License. If you cannot convey a
527 | covered work so as to satisfy simultaneously your obligations under this
528 | License and any other pertinent obligations, then as a consequence you may
529 | not convey it at all. For example, if you agree to terms that obligate you
530 | to collect a royalty for further conveying from those to whom you convey
531 | the Program, the only way you could satisfy both those terms and this
532 | License would be to refrain entirely from conveying the Program.
533 |
534 | ### 13. Remote Network Interaction; Use with the GNU General Public License
535 |
536 | Notwithstanding any other provision of this License, if you modify the
537 | Program, your modified version must prominently offer all users
538 | interacting with it remotely through a computer network (if your version
539 | supports such interaction) an opportunity to receive the Corresponding
540 | Source of your version by providing access to the Corresponding Source
541 | from a network server at no charge, through some standard or customary
542 | means of facilitating copying of software. This Corresponding Source
543 | shall include the Corresponding Source for any work covered by version 3
544 | of the GNU General Public License that is incorporated pursuant to the
545 | following paragraph.
546 |
547 | Notwithstanding any other provision of this License, you have
548 | permission to link or combine any covered work with a work licensed
549 | under version 3 of the GNU General Public License into a single
550 | combined work, and to convey the resulting work. The terms of this
551 | License will continue to apply to the part which is the covered work,
552 | but the work with which it is combined will remain governed by version
553 | 3 of the GNU General Public License.
554 |
555 | ### 14. Revised Versions of this License
556 |
557 | The Free Software Foundation may publish revised and/or new versions of
558 | the GNU Affero General Public License from time to time. Such new versions
559 | will be similar in spirit to the present version, but may differ in detail to
560 | address new problems or concerns.
561 |
562 | Each version is given a distinguishing version number. If the
563 | Program specifies that a certain numbered version of the GNU Affero General
564 | Public License “or any later version” applies to it, you have the
565 | option of following the terms and conditions either of that numbered
566 | version or of any later version published by the Free Software
567 | Foundation. If the Program does not specify a version number of the
568 | GNU Affero General Public License, you may choose any version ever published
569 | by the Free Software Foundation.
570 |
571 | If the Program specifies that a proxy can decide which future
572 | versions of the GNU Affero General Public License can be used, that proxy's
573 | public statement of acceptance of a version permanently authorizes you
574 | to choose that version for the Program.
575 |
576 | Later license versions may give you additional or different
577 | permissions. However, no additional obligations are imposed on any
578 | author or copyright holder as a result of your choosing to follow a
579 | later version.
580 |
581 | ### 15. Disclaimer of Warranty
582 |
583 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
584 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
585 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY
586 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
587 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
588 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
589 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
590 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
591 |
592 | ### 16. Limitation of Liability
593 |
594 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
595 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
596 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
597 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
598 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
599 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
600 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
601 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
602 | SUCH DAMAGES.
603 |
604 | ### 17. Interpretation of Sections 15 and 16
605 |
606 | If the disclaimer of warranty and limitation of liability provided
607 | above cannot be given local legal effect according to their terms,
608 | reviewing courts shall apply local law that most closely approximates
609 | an absolute waiver of all civil liability in connection with the
610 | Program, unless a warranty or assumption of liability accompanies a
611 | copy of the Program in return for a fee.
612 |
613 | _END OF TERMS AND CONDITIONS_
614 |
615 | ## How to Apply These Terms to Your New Programs
616 |
617 | If you develop a new program, and you want it to be of the greatest
618 | possible use to the public, the best way to achieve this is to make it
619 | free software which everyone can redistribute and change under these terms.
620 |
621 | To do so, attach the following notices to the program. It is safest
622 | to attach them to the start of each source file to most effectively
623 | state the exclusion of warranty; and each file should have at least
624 | the “copyright” line and a pointer to where the full notice is found.
625 |
626 |
627 | Copyright (C)
628 |
629 | This program is free software: you can redistribute it and/or modify
630 | it under the terms of the GNU Affero General Public License as published by
631 | the Free Software Foundation, either version 3 of the License, or
632 | (at your option) any later version.
633 |
634 | This program is distributed in the hope that it will be useful,
635 | but WITHOUT ANY WARRANTY; without even the implied warranty of
636 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
637 | GNU Affero General Public License for more details.
638 |
639 | You should have received a copy of the GNU Affero General Public License
640 | along with this program. If not, see .
641 |
642 | Also add information on how to contact you by electronic and paper mail.
643 |
644 | If your software can interact with users remotely through a computer
645 | network, you should also make sure that it provides a way for users to
646 | get its source. For example, if your program is a web application, its
647 | interface could display a “Source” link that leads users to an archive
648 | of the code. There are many ways you could offer source, and different
649 | solutions will be better for different programs; see section 13 for the
650 | specific requirements.
651 |
652 | You should also get your employer (if you work as a programmer) or school,
653 | if any, to sign a “copyright disclaimer” for the program, if necessary.
654 | For more information on this, and how to apply and follow the GNU AGPL, see
655 | .
656 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # dat-shell
2 | [][standardjs]
3 | [](https://www.npmjs.com/package/dat-shell)
4 | [](https://travis-ci.org/millette/dat-shell)
5 | [](https://coveralls.io/github/millette/dat-shell?branch=master)
6 | [](https://gemnasium.com/github.com/millette/dat-shell)
7 | > Dat shell. Open a remote dat and explore with cd, ls, etc.
8 |
9 | ## DEPRECATED
10 |
11 | Note that `dat-shell` hasn't been updated in a few years. Hoping to get back to it in 2020.
12 |
13 | dat-shell is part of the [dat][] Peer-to-Peer universe. It's useful to explore remote dats by their key without having to download them. Think of it as bash for dats, letting you ```cd```, ```ls``` and ```cp``` at will.
14 |
15 | ![dat-shell screencast][screencast]
16 |
17 | ## Install
18 | ```sh
19 | $ npm install --global dat-shell
20 | ```
21 |
22 | ### Requirements
23 | You'll need node 8.9.1 (LTS) or above. I suggest using [n-install] to install the ```n``` node version manager.
24 |
25 | You'll probably need ```git``` too since we're using my (temporary) fork of glob to support hyperdrives (dat archives), and that fork is only available on github and not (yet) on npm. See [below][merge-glob] to help merge my glob fork.
26 |
27 | ## Usage
28 | ```sh
29 | $ dat-shell # dat-key is optionnal
30 | ```
31 |
32 | For example, you can access this readme and scripts at:
33 |
34 | ```sh
35 | $ dat-shell dat://ae8c136e04a66451c79325681d4593bc3ce30c8005dfa5fc6001e0898ec4573a
36 | # or
37 | $ dat-shell ae8c136e04a66451c79325681d4593bc3ce30c8005dfa5fc6001e0898ec4573a
38 | # or
39 | $ dat-shell dat://dat-shell-millette.hashbase.io/
40 | ```
41 |
42 | You might wonder about but it's perfectly valid since the hostname maps to the ```ae8c...573a``` key through https discovery.
43 |
44 | ### Commands
45 | * help: List of commands and their descriptions.
46 | * .help: Internal repl commands.
47 | * ln: Pseudo symbolic link (mkfifo).
48 | * cp: Copy a file from remote dat to local filesystem.
49 | * cat: View a file (concatenate).
50 | * ls: List files.
51 | * file: Detect mimetype.
52 | * view: Generic view command (text, markdown, html, etc.).
53 | * sl: Train yourself to avoid typos.
54 | * cd: Change directory.
55 | * pwd: Output current working directory.
56 | * dat: dat -c to close; dat to open; dat to output current key.
57 | * state: Output current state.
58 | * version: Current dat-shell version.
59 | * exit or quit: Exit dat-shell (or CTRL-D).
60 |
61 | #### ln
62 | ln is a bit weird, not sure how useful it's going to be. As it's currently implemented, ln creates a fifo, writes the specified remote file (in dat) to the fifo and waits for the user to read the fifo before closing and removing it.
63 |
64 | For instance, inside dat-shell, you can do:
65 |
66 | ```
67 | ln readme.md ~/tmp-readme.md # ~/tmp-readme.md will be overwritten with our temporary fifo
68 | ```
69 |
70 | And in another terminal (bash, etc.):
71 | ```
72 | cat ~/tmp-readme.md # or tail, cp, etc.
73 | ```
74 |
75 | You can't currently ```ln``` a video file and play it with vlc or mplayer unfortunately.
76 |
77 | ## Upgrading
78 | The cli now uses [update-notifier][] to let the user know about updates to this program.
79 |
80 | Users have the ability to opt-out of the update notifier by changing
81 | the optOut property to true in ~/.config/configstore/update-notifier-dat-shell.json.
82 | The path is available in notifier.config.path.
83 |
84 | Users can also opt-out by setting the environment variable NO_UPDATE_NOTIFIER
85 | with any value or by using the --no-update-notifier flag on a per run basis.
86 |
87 | To upgrade, simply
88 | ```sh
89 | $ npm install --global dat-shell
90 | ```
91 |
92 | ## Contribute
93 | Needless to say, I'm 100% open to contributions. Unit tests are coming soon, but for now make sure to follow the [StandardJS][standardjs] coding style (no semi-colons, etc). Run either ```yarn lint``` or ```npm run lint``` to verify.
94 |
95 | ## TODO
96 | There's lots to do, classified here in bugs and features.
97 |
98 | I should probably move most of the items below to GitHub issues and establish a roadmap.
99 |
100 | ### Merge glob
101 | There's an [issue on glob to allow other fs implementations][glob280]. This allows glob to work on dat archives (and the hyperdrive beneath).
102 |
103 | ### Bugs
104 | * [issue#1] Improve error messages
105 | * [issue#2] Prevent cd into a file (doh)
106 | * [issue#3] Copy to directory (currently, a destination filename is required)
107 | * [issue#4] Improve screencast (demo), see
108 | * [issue#16] Ctrl-D doesn't always quit
109 | * [issue#11] ln should work as expected (for mplayer, etc.)
110 |
111 | ### Features
112 | * [issue#7] Add file autocompletion
113 | * [issue#8] Add text browser mode (*à la* lynx)
114 | * [issue#9] Enable usage as: dat-shell KEY ls (non-interactive)
115 | * [issue#10] Browse versions (history)
116 | * [issue#12] Add status bar (show when files are updated, version, etc.)
117 | * [issue#13] Unit tests, travis, coveralls
118 | * [issue#14] Enumerate hosts
119 | * [issue#15] Improve args quoting (*à la* bash)
120 | * Add more command
121 | * Add tail command
122 | * Add tree command
123 | * Improve ls handling (arguments, long version, etc.)
124 | * Colors
125 | * Make all commands async (promises)
126 | * Improve user responses
127 | * Make prompt configurable (*à la* bash)
128 | * Make statusbar configurable
129 | * Gemnasium badge
130 | * Support plugins
131 | * Add debugging options and output
132 | * Evaluate [shelljs][] for integration
133 | * Evaluate [cash][] for integration
134 | * Evaluate [vorpal][] for integration
135 | * Evaluate [nsh][] for integration
136 | * Evaluate [coreutils][] for integration
137 | * Evaluate [bashful][] for integration
138 | * Add bookmark support (compatible with beaker, hopefully)
139 | * Make sure it works cross-platform (posix, windows)
140 | * Package self-contained binary with pkg
141 | * "Implement" [standard-readme][]
142 |
143 | ### Optimizations (speed or size)
144 | * Replace marked-terminal and update-notifier with smaller equivalents
145 |
146 | ### Ideas from #dat on freenode (IRC)
147 | * creationix: would be cool to have the ability to run scripts in dat-shell
148 | * creationix: pluggable vms for running scripts, scripts could list dependencies via dat urls, maybe even load native vm code from dats
149 | * scriptjs: Would be nice if the licence for dat-shell was aligned with the dat ecosystem MIT please
150 |
151 | ## Related projects
152 | * [Reimagining the browser as a network OS][] by Paul Frazee
153 |
154 | ### Maybe related
155 | See [features] above.
156 |
157 | * [shelljs][]
158 | * [cash][]
159 | * [vorpal][]
160 | * [nsh][]
161 | * [coreutils][]
162 | * [bashful][]
163 |
164 | ## License
165 | AGPL-v3 © 2017 [Robin Millette][]
166 |
167 | [Robin Millette]:
168 | [update-notifier]:
169 | [dat]:
170 | [shelljs]:
171 | [cash]:
172 | [vorpal]:
173 | [n-install]:
174 | [glob280]:
175 | [merge-glob]: <#merge-glob>
176 | [features]: <#features>
177 | [standard-readme]:
178 | [standardjs]:
179 | [Reimagining the browser as a network OS]:
180 | [mkfifo]:
181 | [nsh]:
182 | [coreutils]:
183 | [bashful]:
184 |
185 | [issue#1]:
186 | [issue#2]:
187 | [issue#3]:
188 | [issue#4]:
189 | [issue#5]:
190 | [issue#6]:
191 | [issue#7]:
192 | [issue#8]:
193 | [issue#9]:
194 | [issue#10]:
195 | [issue#11]:
196 | [issue#12]:
197 | [issue#13]:
198 | [issue#14]:
199 | [issue#15]:
200 | [issue#16]:
201 |
202 | [screencast]: output.gif "dat-shell screencast"
203 |
--------------------------------------------------------------------------------
/cli.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | /*
4 | dat-shell
5 | Dat shell. Open a remote dat and explore with cd, ls, etc.
6 |
7 | Copyright 2017 Robin Millette ()
8 |
9 | This program is free software: you can redistribute it and/or modify
10 | it under the terms of the GNU Affero General Public License as published by
11 | the Free Software Foundation, either version 3 of the License, or
12 | (at your option) any later version.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU Affero General Public License for more details.
18 |
19 | You should have received a copy of the
20 | [GNU Affero General Public License](LICENSE.md)
21 | along with this program. If not, see .
22 | */
23 |
24 | 'use strict'
25 |
26 | // self
27 | const DatRepl = require('.')
28 | const pkg = require('./package.json')
29 |
30 | // npm
31 | const updateNotifier = require('update-notifier')
32 |
33 | const rr = new DatRepl({ pkg, datKey: process.argv[2] })
34 | if (rr.datKey) { console.log('datKey:', rr.datKey) }
35 |
36 | updateNotifier({ pkg }).notify()
37 |
--------------------------------------------------------------------------------
/dat.json:
--------------------------------------------------------------------------------
1 | {
2 | "url": "dat://ae8c136e04a66451c79325681d4593bc3ce30c8005dfa5fc6001e0898ec4573a",
3 | "title": "dat-shell",
4 | "description": "Dat shell. Open a remote dat and explore with cd, ls, etc."
5 | }
6 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | // npm
4 | const Dat = require('dat-node')
5 | const dlr = require('dat-link-resolve')
6 | const ram = require('random-access-memory')
7 | const glob = require('glob')
8 | const pump = require('pump')
9 | const stdout = require('stdout')
10 | const expandTilde = require('expand-tilde')
11 | const mime = require('mime')
12 | const TerminalRenderer = require('marked-terminal')
13 | const DownmarkStream = require('downmark-stream')
14 | const html2ansi = require('html-to-ansi')
15 | const { mkfifo } = require('mkfifo')
16 |
17 | // core
18 | const repl = require('repl')
19 | const resolvePath = require('path').resolve
20 | const fs = require('fs')
21 | const util = require('util')
22 |
23 | const startsWith = (line, x) => !x.indexOf(line)
24 |
25 | const openDat = (key) => new Promise((resolve, reject) => {
26 | let tooBad
27 | const doG = (dat, stats, g) => {
28 | const st = stats.get()
29 | if (!st.files) { return stats.once('update', doG.bind(null, dat, stats)) }
30 | clearTimeout(tooBad)
31 | resolve(dat)
32 | }
33 |
34 | dlr(key, true, (errDlr, resp) => {
35 | if (errDlr) { return reject(errDlr) }
36 |
37 | Dat(ram, { sparse: true, key: resp.key }, (err, dat) => {
38 | if (err) { return reject(err) }
39 | dat.joinNetwork()
40 | const stats = dat.trackStats()
41 | dat.shell = resp
42 | stats.once('update', doG.bind(null, dat, stats))
43 |
44 | dat.network.once('listening', () => {
45 | tooBad = setTimeout(() => {
46 | dat.leaveNetwork() // preferable to dat.close() in this specific case
47 | reject(new Error('Timeout.'))
48 | }, 60000)
49 | })
50 | })
51 | })
52 | })
53 |
54 | const notFound = (cmd) => Object.assign(new Error(`Command not found.`), { cmd })
55 |
56 | const writer = (str) => {
57 | if (typeof str === 'string') { return str + '\n' }
58 | if (typeof str === 'object' && str.length !== undefined) { return str.join('\n') + '\n' }
59 | if (typeof str === 'object') { return util.inspect(str, { colors: true }) }
60 | return str + '\n'
61 | }
62 |
63 | class DatRepl {
64 | constructor (opts) {
65 | Object.assign(this, opts)
66 | if (opts.datKey) { this._datKeyProvided = opts.datKey }
67 |
68 | const asyncs = ['ls', 'cat', 'cp', 'file', 'view', 'ln']
69 |
70 | this._commands = {
71 | '.help': {},
72 | help: (args) => {
73 | const lines = ['Available commands:']
74 | let r
75 | let str
76 | for (r in this._commands) {
77 | str = r
78 | if (this._commands[r].help) { str += `: ${this._commands[r].help}` }
79 | lines.push(str)
80 | }
81 | return lines
82 | },
83 | ln: (args) => new Promise((resolve, reject) => {
84 | if (!this.datKey || !this._dat || !this._dat.archive) { return reject(new Error('Dat not ready.')) }
85 | if (!args || args.length !== 2) { return reject(new Error('ln requires two file arguments.')) }
86 | const fn = expandTilde(args[1])
87 | mkfifo(fn, parseInt(644, 8), (err) => {
88 | if (err && err.code !== 'EEXIST') { return reject(err) }
89 | const inFile = this._dat.archive.createReadStream(resolvePath(this.cwd, args[0]))
90 | const outFile = fs.createWriteStream(fn)
91 | console.log(`${fn} is waiting to be read...`)
92 | pump(inFile, outFile, (err) => {
93 | fs.unlink(fn, (e2) => {
94 | if (err) { return reject(err) }
95 | if (e2) { return reject(e2) }
96 | resolve()
97 | })
98 | })
99 | })
100 | }),
101 | cp: (args) => new Promise((resolve, reject) => {
102 | if (!this.datKey || !this._dat || !this._dat.archive) { return reject(new Error('Dat not ready.')) }
103 | if (!args || args.length !== 2) { return reject(new Error('cp requires two file arguments.')) }
104 | const inFile = this._dat.archive.createReadStream(resolvePath(this.cwd, args[0]))
105 | const outFile = fs.createWriteStream(expandTilde(args[1]))
106 | pump(inFile, outFile, (err) => err ? reject(err) : resolve())
107 | }),
108 | cat: (args) => new Promise((resolve, reject) => {
109 | if (!this.datKey || !this._dat || !this._dat.archive) { return reject(new Error('Dat not ready.')) }
110 | if (!args || !args[0]) { return reject(new Error('cat requires a file argument.')) }
111 | pump(this._dat.archive.createReadStream(resolvePath(this.cwd, args[0])), stdout(), (err) => err ? reject(err) : resolve())
112 | }),
113 | ls: (args) => new Promise((resolve, reject) => {
114 | if (!this.datKey || !this._dat || !this._dat.archive) { return reject(new Error('Dat not ready.')) }
115 | const cwd = (args && args[0] && resolvePath(this.cwd, args[0])) || this.cwd
116 | glob('*', { mark: true, cwd, fs: this._dat.archive }, (err, files) => err ? reject(err) : resolve(files.filter(Boolean)))
117 | }),
118 | file: (args) => new Promise((resolve, reject) => {
119 | if (!this.datKey || !this._dat || !this._dat.archive) { return reject(new Error('Dat not ready.')) }
120 | if (!args || !args[0]) { return reject(new Error('file requires a file argument.')) }
121 | const type = mime.getType(args[0])
122 | if (type) { return resolve(type) }
123 | reject(new Error('No mimetype detected.'))
124 | }),
125 | view: (args) => new Promise((resolve, reject) => {
126 | if (!this.datKey || !this._dat || !this._dat.archive) { return reject(new Error('Dat not ready.')) }
127 | if (!args || !args[0]) { return reject(new Error('view requires a file argument.')) }
128 | const type = mime.getType(args[0])
129 | switch (type) {
130 | case null:
131 | return reject(new Error('No mimetype detected.'))
132 |
133 | case 'application/json':
134 | return this._dat.archive.readFile(resolvePath(this.cwd, args[0]), 'utf-8', (err, x) => {
135 | if (err) { return reject(err) }
136 | try {
137 | resolve(JSON.parse(x))
138 | } catch (e) {
139 | reject(e)
140 | }
141 | })
142 |
143 | case 'text/markdown':
144 | return pump(this._dat.archive.createReadStream(resolvePath(this.cwd, args[0])), DownmarkStream({ renderer: new TerminalRenderer() }), stdout(), (err) => {
145 | if (err) { return reject(err) }
146 | resolve()
147 | })
148 |
149 | case 'text/plain':
150 | return pump(this._dat.archive.createReadStream(resolvePath(this.cwd, args[0])), stdout(), (err) => {
151 | if (err) { return reject(err) }
152 | resolve()
153 | })
154 |
155 | case 'text/html':
156 | return this._dat.archive.readFile(resolvePath(this.cwd, args[0]), 'utf-8', (err, x) => {
157 | if (err) { return reject(err) }
158 | const html = x
159 | .replace(//i, '')
160 | .replace(/<\/p>/ig, '
\n')
161 | .replace(/<\/div>/ig, '\n')
162 | resolve(html2ansi(html))
163 | })
164 | }
165 |
166 | const types = type.split('/')
167 | if (types[0] === 'text') {
168 | return pump(this._dat.archive.createReadStream(resolvePath(this.cwd, args[0])), stdout(), (err) => {
169 | if (err) { return reject(err) }
170 | resolve()
171 | })
172 | }
173 | reject(new Error('Unsupported file type.'))
174 | }),
175 | sl: (args) => 'Choo! Choo!',
176 | cd: (args) => {
177 | if (args && args[0] === '-') {
178 | if (!this._previousCwd) { return 'No previous working directory.' }
179 | [this._previousCwd, this.cwd] = [this.cwd, this._previousCwd] // swap
180 | } else {
181 | this._previousCwd = this.cwd
182 | this.cwd = args && args[0]
183 | }
184 | this._replServer.setPrompt(this._makePrompt())
185 | },
186 | pwd: (args) => this.cwd,
187 | dat: (args) => {
188 | if (args && args[0]) { this.datKey = (args[0] === '--close' || args[0] === '-c') ? false : args[0] }
189 | return this.datKey
190 | },
191 | state: (args) => {
192 | const lines = [...this._commands.version(), '', `cwd: ${this.cwd}`]
193 | if (this._previousCwd) { lines.push(`previousCwd: ${this._previousCwd}`) }
194 | if (this._datKeyProvided) { lines.push(`datKeyProvided: ${this._datKeyProvided}`) }
195 | if (this.datKey) { lines.push(`datKey: ${this.datKey}`) }
196 | if (this._version) { lines.push(`version: ${this._version}`) }
197 | if (this._latestVersion) { lines.push(`latest version: ${this._latestVersion}`) }
198 | return lines
199 | },
200 | version: (args) => [`${this.pkg.name} v${this.pkg.version}`, `${this.pkg.description}`],
201 | quit: (args) => process.exit((args && parseInt(args[0], 10)) || 0),
202 | exit: (args) => process.exit((args && parseInt(args[0], 10)) || 0)
203 | }
204 |
205 | this._commands['.help'].help = 'Internal repl commands.'
206 | this._commands.help.help = 'List of commands and their descriptions.'
207 | this._commands.ls.help = 'List files.'
208 | this._commands.file.help = 'Detect mimetype.'
209 | this._commands.ln.help = 'Pseudo symbolic link (mkfifo).'
210 | this._commands.cat.help = 'View a file (concatenate).'
211 | this._commands.view.help = 'Generic view command (text, markdown, html, etc.).'
212 | this._commands.cp.help = 'Copy a file from remote dat to local filesystem.'
213 | this._commands.cd.help = 'Change directory.'
214 | this._commands.sl.help = 'Train yourself to avoid typos.'
215 | this._commands.pwd.help = 'Output current working directory.'
216 | this._commands.dat.help = 'dat -c to close; dat to open; dat to output current key.'
217 | this._commands.state.help = 'Output current state.'
218 | this._commands.version.help = 'Current dat-shell version.'
219 | this._commands.exit.help = 'Exit dat-shell (or CTRL-D).'
220 | this._commands.quit.help = 'Exit dat-shell (or CTRL-D).'
221 |
222 | const completer = (line) => [
223 | [
224 | ...Object.keys(this._commands),
225 | ...Object.keys(this._replServer.commands).map((x) => `.${x}`)
226 | ]
227 | .filter(startsWith.bind(this, line))
228 | .sort(),
229 | line
230 | ]
231 |
232 | /*
233 | const completer = (line, cb) => cb(null, [Object.keys(this._commands).filter((x) => !x.indexOf(line)), line])
234 | cb(new Error('Kaboom'))
235 | * Triggers the following
236 | * sDEBUG: tab completion error %j
237 | * (node:19857) [DEP0028] DeprecationWarning: util.debug is deprecated. Use console.error instead.
238 | * Probably fixed in 9.0.0 (check it out)
239 | */
240 |
241 | const startOptions = {
242 | writer,
243 | completer,
244 | prompt: this._makePrompt(),
245 | ignoreUndefined: true,
246 | eval: (str, context, filename, cb) => {
247 | const callback = (err, ok) => {
248 | this.title = `${this._datKeyProvided} (${this.datKey}) ${this._version} ${this.cwd}`
249 | cb(err, ok)
250 | }
251 |
252 | str = str.trim()
253 | const parts = str.split(' ') // FIXME do it as bash (quotes, etc.)
254 | const cmd = parts[0]
255 | if (!str) { return callback() }
256 | // FIXME make all this._commands async
257 | if (asyncs.indexOf(cmd) !== -1) {
258 | return this._commands[cmd](parts.slice(1))
259 | .then((X) => callback(null, X))
260 | .catch(callback)
261 | }
262 | if (this._commands[cmd]) { return callback(null, this._commands[cmd](parts.slice(1))) }
263 | callback(notFound(str))
264 | }
265 | }
266 |
267 | console.log(this._commands.state().join('\n'))
268 | console.log(this._commands.help().join('\n'))
269 | this._replServer = repl.start(startOptions)
270 | // console.log('replServer:', Object.keys(this._replServer))
271 | }
272 |
273 | _makePrompt () { return `dat-shell ${this.cwd} $ ` }
274 |
275 | set title (str) {
276 | if (!this._replServer) { return }
277 | this._replServer.outputStream.write(`\u001b]0;${str}\u0007`)
278 | }
279 |
280 | get replServer () { return this._replServer }
281 |
282 | get cwd () { return this._cwd || '/' }
283 |
284 | set cwd (d) {
285 | if (!this._dat) { return }
286 | const lastCwd = this.cwd
287 | this._cwd = `${resolvePath(this.cwd, d || '/')}`
288 | if (this._cwd.slice(-1) !== '/') { this._cwd += '/' }
289 | this._commands.ls()
290 | .then(() => this._replServer.setPrompt(this._makePrompt()))
291 | .catch(() => { this.cwd = lastCwd })
292 | }
293 |
294 | get datKey () { return this._datKey }
295 |
296 | set datKey (key) {
297 | if (key) {
298 | if (this._datKey !== key) {
299 | if (this._datKey && this._dat && this._dat.close) { this._dat.close() }
300 | openDat(key)
301 | .then((dat) => {
302 | this._dat = dat
303 | this._latestVersion = dat.archive.version
304 | this._datKey = dat.key.toString('hex')
305 | this.cwd = (dat.shell.path) || '/'
306 | if (dat.shell.version) {
307 | this._version = dat.shell.version
308 | if (dat.shell.version !== dat.archive.version) {
309 | const na = dat.archive.checkout(dat.shell.version)
310 | if (na) {
311 | this._dat.archive = na
312 | } else {
313 | this._version = dat.archive.version
314 | }
315 | }
316 | } else {
317 | this._version = dat.archive.version
318 | }
319 | if (this._datKey !== key) { this._datKeyProvided = key }
320 | })
321 | }
322 | } else if (this._datKey && this._dat && this._dat.close) {
323 | this._dat.close()
324 | this._datKey = undefined
325 | this._datKeyProvided = undefined
326 | }
327 | }
328 | }
329 |
330 | module.exports = DatRepl
331 |
--------------------------------------------------------------------------------
/output.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/millette/dat-shell/eb9c175e2781472cc948c268a62626977344f04f/output.gif
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "dat-shell",
3 | "description": "Dat shell. Open a remote dat and explore with cd, ls, etc.",
4 | "version": "0.6.0",
5 | "license": "AGPL-3.0",
6 | "repository": "millette/dat-shell",
7 | "author": {
8 | "name": "Robin Millette",
9 | "email": "robin@millette.info",
10 | "url": "http://robin.millette.info"
11 | },
12 | "keywords": [
13 | "cli",
14 | "dat",
15 | "shell",
16 | "hyperdrive"
17 | ],
18 | "main": "index.js",
19 | "bin": {
20 | "dat-shell": "cli.js"
21 | },
22 | "engines": {
23 | "node": ">=10.16.0"
24 | },
25 | "scripts": {
26 | "lint": "standard",
27 | "deps": "standard && dependency-check . && dependency-check . --unused --no-dev"
28 | },
29 | "dependencies": {
30 | "dat-link-resolve": "millette/dat-link-resolve#verbose-mode",
31 | "dat-node": "^3.5.6",
32 | "downmark-stream": "^1.0.0",
33 | "expand-tilde": "^2.0.2",
34 | "glob": "millette/node-glob#opt-fs",
35 | "html-to-ansi": "^1.0.1",
36 | "marked-terminal": "^2.0.0",
37 | "mime": "^2.3.1",
38 | "mkfifo": "millette/node-mkfifo#upgrade-deps",
39 | "pump": "^3.0.0",
40 | "random-access-memory": "^2.4.0",
41 | "stdout": "^0.0.3",
42 | "update-notifier": "^2.3.0"
43 | },
44 | "devDependencies": {
45 | "dependency-check": "^3.1.0",
46 | "standard": "^13.0.2"
47 | }
48 | }
49 |
--------------------------------------------------------------------------------