A Simple Text/Document Viewer written in JS

Overview

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

Pattern Better 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:

Action Description (all actions are case insensitive)
Next Line d, Down Arrow, Enter
Previous Line a, Up Arrow
Next Page (20 lines) Page Down, Right Arrow
Previous Page (20 lines) Page Up, Left Arrow
Go To Start s, Home
Go To End e, End
Go To Line Number Print any number. Press Enter to go, q or ESC to cancel
Cycle Border Colors r (blue, red, green, yellow, magenta, cyan, white, black)
Center Content c
Frame Position l
Toggle Text Slide t
Toggle Patterns p
Find Next n (Go to next occurrence of word if exists)
Find Previous b (Go to previous occurrence of word if exists)
Open Command Line :
Show Help Window h
Quit Application q or CTRL+C
Quit Help h

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:

Commands Shortcut Description Argument Number Argument Type
switch sw switches state of given command 1 Any
toggle to toggles given command 1 Any
find f find all occurrences of given text 1 Any
time t sets time for text slide 1 Number
quit q quits application 0 None

Switch Command

Commands Abbr. Description # of Arguments
block changes border block 0
border-color bc changes border color 0

Toggle Command

Commands Abbr. Description # of Arguments
same-color sc set all borders same color 0
case-ignore ci case sensitivity in find command 0

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.

Command Effect
c.reset Resets all coloring effects
c.bright Makes font color bright
c.dim Makes font color dimmer
c.underscore Puts underscore to text
c.blink Makes text blink
c.reverse Switches back and foreground color as in selected
c.hidden Makes text hidden
c.fg.black Black Foreground
c.fg.red Red Foreground
c.fg.green Green Foreground
c.fg.yellow Yellow Foreground
c.fg.blue Blue Foreground
c.fg.magenta Magenta Foreground
c.fg.cyan Cyan Foreground
c.fg.white White Foreground
c.bg.black Black Background
c.bg.red Red Background
c.bg.green Green Background
c.bg.yellow Yellow Background
c.bg.blue Blue Background
c.bg.magenta Magenta Background
c.bg.cyan Cyan Background
c.bg.white White Background
c.header Blue background + Black Foreground
c.warning Black 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

You might also like...

🔆🔎👀 Smart Contract Storage Viewer, DataType Guesser, Toolbox & Transaction Decoder

🔆🔎👀  Smart Contract Storage Viewer, DataType Guesser, Toolbox & Transaction Decoder

🔆 🔎 👀 Smart Contract Storage HexViewer Demo Target - the target contract API Endpoint - your infura (or equivalent) api key Retrieves smart contrac

Nov 27, 2022

This is an IFC wrapped on Three js based viewer, I think..

This is an IFC wrapped on Three js based viewer, I think..

ifc-three-js-viewer Project description: This is an IFC wrapped on Three js based viewer, I think.. Features & Screenshots: A simple viewer for render

Dec 14, 2022

🌌 Fast, in-memory, full-text search engine written in TypeScript. Now in beta.

🌌  Fast, in-memory, full-text search engine written in TypeScript. Now in beta.

Installation You can install Lyra using npm, yarn, pnpm: npm i @nearform/lyra yarn add @nearform/lyra pnpm add @nearform/lyra Usage Lyra is quite simp

Dec 30, 2022

Do calculations with your written text.

Do calculations with your written text.

https://calcutext.com Calcutext is a web app where you can do calculations with your written text. Features Write any math operations, as available in

Dec 22, 2022

A Virtual Interactive Keyboard which replicates every key you press and a Text-Area in which everything is written and can be copied to the clipboard with a click of a button.

A Virtual Interactive Keyboard which replicates every key you press and a Text-Area in which everything is written and can be copied to the clipboard with a click of a button.

Mar 1, 2021

Twitter Text Libraries. This code is used at Twitter to tokenize and parse text to meet the expectations for what can be used on the platform.

twitter-text This repository is a collection of libraries and conformance tests to standardize parsing of Tweet text. It synchronizes development, tes

Jan 8, 2023

Obsidian text generator Plugin Text generator using GPT-3 (OpenAI)

Obsidian text generator Plugin Text generator using GPT-3 (OpenAI)

is a handy plugin for Obsidian that helps you generate text content using the powerful language model GP

Dec 29, 2022

Obsidian plugin: Type text shortcuts that expand into javascript generated text.

Obsidian plugin: Type text shortcuts that expand into javascript generated text.

Obsidian Plugin - Text Expander JS (open beta) This Obsidian plugin allows the user to type text shortcuts that are replaced by (or "expanded into") j

Dec 27, 2022

A lightweight JavaScript library that renders text in a brilliant style by displaying strings of random characters before the actual text.

A lightweight JavaScript library that renders text in a brilliant style by displaying strings of random characters before the actual text.

cryptoWriter.js A lightweight javascript library which creates brilliant text animation by rendering strings of random characters before the actual te

Sep 13, 2022
Comments
  • Command propagation error

    Command propagation error

    Each time a modifier is added into line, previous modifiers are treated as part of the new modifier.

    So previous modifiers are repeated every time a new one comes, making redundant duplications.

    Discovered this one on a line

    @{c.fg.white, c.bg.cyan}@ Test @{shrug}@ @{c.reset}@
    

    It was not visible on colors but extra commands like shrug makes it crystal clear.

    bug 
    opened by fezcode 0
A viewer for Arc System Works scripts and hitboxes written in Godot.

ASWViewer A viewer for Arc System Works scripts and hitboxes written in Godot. Currently only supports Guilty Gear -Strive-. It also displays the mode

null 3 Sep 20, 2022
A very simple JavaScript library written in vanilla js for scrambling text.

Scrambling Text A very simple JavaScript library written in vanilla js for scrambling text. Demo Page Table of Contents Installation Examples Basic Ex

sogoagain 10 Dec 7, 2022
An alternative viewer for DevDAO NFT with a ✨holographic✨ twist

Holo DevDAO An alternative viewer for DevDAO NFT with a ✨ holographic ✨ twist. Pre-requisites node version >= 15.0.1 & npm >= 7.20.6. If you have nvm

Naomi Hauret 19 Dec 17, 2022
A Web Viewer for Blender.

BlenderWebViewer a Web Viewer for Blender. To get started: Clone the repo Install the add-on for Blender (blenderPlugin.zip) change the path field in

eliaorsini 48 Nov 29, 2022
[ThatProject] ESP32 LoRa GPS Data Viewer

Map Viewer for MCU with LoRa & GPS Data ThatProject Channel LoRa module has caught the attention of many people for a number of reasons. Being able to

Eric 6 Aug 7, 2022
Custom Element: interactive panorama viewer

<little-planet> This project is a Custom HTML Element (AKA Web Component) that renders an interactive view of a panoramic photo. Can be used with no J

Ondřej Žára 12 Nov 25, 2022
JavaScript Online DWG/DXF Viewer

dwg-viewer-js A DWG viewer you can buy for $420 (US) I had originally made this for a software company but they cancelled at the last moment so if any

Savir Singh 4 Jul 6, 2022
Embed panorama photos on your website with Panorama Viewer

#Panorama Viewer by Pete R. Embed interactive Panorama Pictures on your site with this simple plugin. Created by Pete R., Founder of Travelistly and B

Pete R. 474 Oct 8, 2022
Quick spreadsheet viewer in vanilla JS

Heihō Quick spreadsheet viewer in vanilla JS What it does ? The heiho.js script is quick and simple spreadsheet viewer. It is meant to preview the con

Kaloyan Tsvetkov 18 Sep 8, 2022
An OpenStoriesFeed viewer

An OpenStoriesFeed viewer

ddddddddʣzzz 22 Dec 17, 2022