0.1.1 • Published 2 years ago

doku.js v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Doku

Doku.js is a terminal ui text/document viewer that supports a custom documentation syntax called doky.

ASCII ART

Features

  • Border colors. (all common terminal colors: blue, red, green, yellow, magenta, cyan, white, black, results may change depending on your terminal colors)
  • Center content.
  • Change frame position.
  • Slide text from top to bottom.
  • Change common patterns.
  • Text search.
  • App Commands.

Common Patterns

PatternBetter Pattern
Line with 10 or more - (Heading-like)
Line with 10 or more _ (Heading-like)
Line with 10 or more = (Heading-like)
==>
<==
-->
<--
8 or more -
8 or more _
:=
=:
~=
!=

Examples are located in examples/patterns.doxy

Results

Results of Patters

Installation

npm install -g doku.js

You can then run doku by simply typing doku <filename> on any file you want.

If you don't want to install it globally, then you can install it in any directory you want then execute it via npx doku command.

Using inside another Node app

If you want to use this library within your project simply add as dependency.

npm install doku.js

After adding as dependency you can simply require it.

Example:

const doku = require("doku");

function stopExecution() {
    process.exit(0);
}

const header = "..."; // Header string that will be displayed at the top of application.
const content = "..."; // String containing document.
const isCentered = true; // Show frame at center.

const dokument = new Doku(content, header, isCentered);
dokument.subToEvent("doku-end", stopExecution);

Details

Parsing

Doku can render any plain text file as it is. It will parse file on the start then will parse again if terminal resizes. This parsing will cause change in total number of lines like shown in below.

Parsing on smaller displays

Total number of liner increased. Small Display

Parsing on larger displays

Total number of liner decreased. Large Display

Terminal

Doku clears terminal each time it will do re-rendering. You cannot really access to your terminal since it (stdin) is in raw mode.

process.stdin.setRawMode(true);
process.stdin.setEncoding('utf8');
process.stdin.resume();

Events

If you included doku as dependency to your project, then you'll have two events.

doku-start event

This event will be fired when construction of doku object is done.

// To subscribe
doku.subToEvent("doku-start", startHandler);

// To unsubscribe
doku.unsubToEvent("doku-start", startHandler);

doku-end event

This event will be fired when deconstruction of doku object is occurs.

// To subscribe
doku.subToEvent("doku-end", stopHandler);

// To unsubscribe
doku.unsubToEvent("doku-end", stopHandler);

Actions

Doku has following actions while running application:

ActionDescription (all actions are case insensitive)
Next Lined, Down Arrow, Enter
Previous Linea, Up Arrow
Next Page (20 lines)Page Down, Right Arrow
Previous Page (20 lines)Page Up, Left Arrow
Go To Starts, Home
Go To Ende, End
Go To Line NumberPrint any number. Press Enter to go, q or ESC to cancel
Cycle Border Colorsr (blue, red, green, yellow, magenta, cyan, white, black)
Center Contentc
Frame Positionl
Toggle Text Slidet
Toggle Patternsp
Find Nextn (Go to next occurrence of word if exists)
Find Previousb (Go to previous occurrence of word if exists)
Open Command Line:
Show Help Windowh
Quit Applicationq or CTRL+C
Quit Helph

App Commands

While in normal mode (not in command line), if a number is entered as the first character, command line waits a line number to go. If given line number is valid then document will go to that line. You can always cancel command by pressing ESC or q.

If an error occurs, then command line (alongside with status) will turn red. For example if user presses k which is not mapped, an error like shown below will be displayed. Error due to not mapped key

If user types : then it opens a command line. There are couple of things that users can do:

CommandsShortcutDescriptionArgument NumberArgument Type
switchswswitches state of given command1Any
toggletotoggles given command1Any
findffind all occurrences of given text1Any
timetsets time for text slide1Number
quitqquits application0None

Switch Command

CommandsAbbr.Description# of Arguments
blockchanges border block0
border-colorbcchanges border color0

Toggle Command

CommandsAbbr.Description# of Arguments
same-colorscset all borders same color0
case-ignorecicase sensitivity in find command0

Time Command

It sets the time interval to text slide command. Default is 1000ms (1 second). It takes 1 argument. That argument must be positive number. It is in milliseconds.

Quit Command

Quits application.

Screenshots

Search Command

Search Command

Searching Next by Pressing n

Search Next

Frame Left

Frame Left

Frame Center

Frame Center

Content Centered

Content Centered

doky - Custom Documentation Syntax

doky has custom commands that allows doku to change what is displayed on terminal.

Table

If you want to display your data in a tabular form, you use following commands:

  • @{begin-table}@: This command starts table data. Whole line must be @{begin-table}@ to parse everything correctly.
  • @{end-table}@: This command ends table data. Whole line must be @{end-table}@ to parse everything correctly.

In between these two lines with command, you need to provide data as below:

| Column | .... | .... | .... |  --> Columns 
|-----------------------------|  --> Separator
| Row1   | .... | .... | .... |  --> Row
| Row2   | .... | .... | .... |  --> Row

You can add | character to separator line if you want. There is no left, right or center align.

Examples

Simple

@{begin-table}@
| Column 1 | Column 2 | Column 3 |
|----------|----------|----------|
| Data 1-1 | Data 1-2 | Data 1-3 | 
| Data 3-1 | Data 3-2 | Data 3-3 |
@{end-table}@

Missing Fields

@{begin-table}@
| Column 1 | Column 2 | Column 3 |
|--------------------------------|
| Data 1-1 | Data 1-2 |
| Data 2-1 | | Data 2-3 |
@{end-table}@

More Complex

@{begin-table}@
| Column 1 | Column 2 | Column 3 |
|----------|----------|----------|
| Data 1-1 | Data 1-2 | Data 1-3 | 

| Data 2-1 |
// Inline comment
| Data 3-1      | Data 3-2      | Data 3-3       |
@{end-table}@

Examples are located in examples/tables.doxy

Results

Results of Table

Code Block

When you want to display your text in a code block, multiline or inline, you can use 3 backticks (`)

3 backticks start and end code blocks.

Examples

Inline

Here is an ```inline``` code block.

Multiline

``` Here is a multiline code block. ```

Both

Maybe you want to try ``` Something like a multiline and then ```something like ```inline``` code block.

Examples are located in examples/code-block.doxy

Results

Results of Table

Commands

doky has a command syntax. The syntax is @{command}@.

Any command you want to have will be in between command start (@{) and command end (}@) characters.

You can put any number of commands in between command start and end characters with comma (,) as the delimiter.

If you want to escape any string in a command block, then simply put it in between quotes ("text"). This will make that string to be interpreted as plain text.

For example:

@{c.fg.white, c.bg.red, "White on Red", c.reset}@

will put Results of Command

Commands: Coloring

There are couple of coloring commands.

All coloring commands start with c prefix.

CommandEffect
c.resetResets all coloring effects
c.brightMakes font color bright
c.dimMakes font color dimmer
c.underscorePuts underscore to text
c.blinkMakes text blink
c.reverseSwitches back and foreground color as in selected
c.hiddenMakes text hidden
c.fg.blackBlack Foreground
c.fg.redRed Foreground
c.fg.greenGreen Foreground
c.fg.yellowYellow Foreground
c.fg.blueBlue Foreground
c.fg.magentaMagenta Foreground
c.fg.cyanCyan Foreground
c.fg.whiteWhite Foreground
c.bg.blackBlack Background
c.bg.redRed Background
c.bg.greenGreen Background
c.bg.yellowYellow Background
c.bg.blueBlue Background
c.bg.magentaMagenta Background
c.bg.cyanCyan Background
c.bg.whiteWhite Background
c.headerBlue background + Black Foreground
c.warningBlack background + Yellow Foreground

Examples are located in examples/colors.doxy

Results

Results of Colors

Commands: Extras

shrug

This command puts ¯\_(ツ⁣)_/¯ into where you put the command.

startdate

This command puts start date time of the application into where you put the command.

Escaping Commands

If you ever find yourself in need of escaping certain commands, like in documentation, you can use

@{"@{escaped}@"}@

"@{not escaped}@" will not be escaped since @{ and }@ will be parsed. However, @{"@{finally escaped}@"}@ will be escaped.

Examples are located in examples/extras.doxy

Results

Results of Extras

0.1.1

2 years ago

0.1.0

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago