Skip to content

Commit

Permalink
Update: readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Wayoung7 committed Apr 29, 2024
1 parent f96fa20 commit eb39144
Show file tree
Hide file tree
Showing 3 changed files with 211 additions and 14 deletions.
212 changes: 204 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,207 @@
```
_ _
| (_)
_ __ ___ ___ _ __ ___ ______ __| |_ __ _ __ _ _ __ __ _ _ __ ___
| '_ ` _ \ / _ \| '_ \ / _ \______/ _` | |/ _` |/ _` | '__/ _` | '_ ` _ \
| | | | | | (_) | | | | (_) | | (_| | | (_| | (_| | | | (_| | | | | | |
|_| |_| |_|\___/|_| |_|\___/ \__,_|_|\__,_|\__, |_| \__,_|_| |_| |_|
__/ |
|___/
```
<h1 align="center">
<br>
Mono-Diagram
<br>
</h1>

A cross-platform command line tool for generating plain-text diagrams from a certain syntax. The biggest advantage of plain-text diagrams is that it can fit in anywhere.

## Usage

### Define diagrams

The basic idea of mono-diagram is to define diagram in a file, and pass it to the program to generate planar diagrams. A file can contain multiple diagrams. Each diagram must start with a tag such as `[table]` to tell the program what kind of diagram it is.

<details>
<summary> Binary Tree </summary>

Tag: `[binary_tree]`

Input file:

```
[binary_tree] // Specify diagram category
a->b,c // Node 'a' has left child 'b' and right child 'c'
b->d,f // Node name is just like variables
f->fa,fb
c->k,m
k->e, // Node 'k' only has one left child
m->,x
a:2 // Assign values to node
b:0.42
c:9.5
f:-3
k:abc
m:2 // Different nodes can have same value
d:001
fa:451
fb:8.90
x:1.2
```

Output diagram:

```
___2___
___/ \___
0.42 9.5
_/ \_ _/ \_
001 -3 abc 2
/ \ / \
451 8.90 e 1.2
```

</details>

<details>
<summary> Directed Acyclic Graph (DAG) </summary>

Tag: `[dag]`

Input file:

```
[dag]
a->b // <NODE-NAME>-><NODE-NAME> represents an edge in the graph
a->c // The graph cannot have cycles
b->d
c->f
c->g
a->f
d->da
d->db
g->gg
a->gg
a:Home Page // Assign values
b:Main Section 1
c:Main Section 2
d:Subsection 1
f:Subsection 2
g:Subsection 3
da:Sub-sub
db:Sub-sub
gg:#page#
```

Output diagram:

```
┌───────────────────────────────────────────────────┐
│ Home Page │
└┬─────────────────┬──┬────────────────────────────┬┘
┌V───────────────┐ │ ┌V───────────────┐ │
│ Main Section 1 │ │ │ Main Section 2 │ │
└┬───────────────┘ │ └┬────────────┬──┘ │
┌V─────────────┐ ┌─V──V─────────┐ ┌V─────────────┐ │
│ Subsection 1 │ │ Subsection 2 │ │ Subsection 3 │ │
└┬───────────┬─┘ └──────────────┘ └┬─────────────┘ │
┌V────────┐ ┌V────────┐ ┌──────────V───────────────V┐
│ Sub-sub │ │ Sub-sub │ │ #page# │
└─────────┘ └─────────┘ └───────────────────────────┘
```

</details>

</details>

<details>
<summary> Table </summary>

Tag: `[table]`

Input file:

```
[table] \\ Each column is seperated by '|' and each row is seperated by newline
Base Class Member|Public Inheritance|Protected Inheritance|Private Inheritance
Public|Public|Protected|Private
Protected|Protected|Protected|Private
Private|Hidden|Hidden|Hidden
```

Output diagram:

```
+-------------------+--------------------+-----------------------+---------------------+
| Base Class Member | Public Inheritance | Protected Inheritance | Private Inheritance |
+-------------------+--------------------+-----------------------+---------------------+
| Public | Public | Protected | Private |
+-------------------+--------------------+-----------------------+---------------------+
| Protected | Protected | Protected | Private |
+-------------------+--------------------+-----------------------+---------------------+
| Private | Hidden | Hidden | Hidden |
+-------------------+--------------------+-----------------------+---------------------+
```

</details>

</details>

<details>
<summary> Grid </summary>

Tag: `[grid]`

Input file:

```
[grid] {10, 7} // The grid has 10 colums and 7 rows
1,1:a
6,2:l // The cell at column 6, row 2 has content 'l'
3,3:j
10,5:m
2,7:k
```

Output diagram:

```
+---+---+---+---+---+---+---+---+---+---+
| a | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | l | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | j | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | m |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | k | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
```

</details>

### Pass to program (Command Line Arguments)

Binary name: `mono-diagram`

## Installation

Install [rust](https://www.rust-lang.org/tools/install) if you havn't.

Then, simply run the following commands:

~~~bash
cargo install mono-diagram
~~~


_ _ <br>
| (_) <br>
_ __ ___ ___ _ __ ___ ______ __| |_ __ _ __ _ _ __ __ _ _ __ ___ <br>
| '_ ` _ \ / _ \| '_ \ / _ \______/ _` | |/ _` |/ _` | '__/ _` | '_ ` _ \ <br>
| | | | | | (_) | | | | (_) | | (_| | | (_| | (_| | | | (_| | | | | | |<br>
|_| |_| |_|\___/|_| |_|\___/ \__,_|_|\__,_|\__, |_| \__,_|_| |_| |_|<br>
__/ | <br>
|___/ <br>
10 changes: 6 additions & 4 deletions examples/test
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[binary_tree]
a->b,c
b->,f
b->d,f
f->fa,fb
c->k,m
k->e,
e->n,
m->,x

a:2
b:0.42
Expand All @@ -12,8 +13,9 @@ f:-3
k:abc
m:2
d:001
a:7
n:7
fa:451
fb:8.90
x:1.2

[table]
Base Class Member|Public Inheritance|Protected Inheritance|Private Inheritance
Expand Down
3 changes: 1 addition & 2 deletions src/mono-diagram/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ fn main() {
match &cli.command {
Commands::Build { file } => build_cmd(file),
Commands::Print { file } => print_cmd(file, prefix),
Commands::Watch { file } => watch_cmd(file, prefix),
// Commands::Watch { file } => watch_cmd(file, prefix),
Commands::Copy { file } => copy_cmd(file, prefix),
_ => (),
}
// print_cmd("examples/dag3", None);
}

fn build_cmd(file: &str) {
Expand Down

0 comments on commit eb39144

Please sign in to comment.