Coder Social home page Coder Social logo

esimov / diagram Goto Github PK

View Code? Open in Web Editor NEW
813.0 16.0 32.0 6.18 MB

CLI app to convert ASCII arts into hand drawn diagrams.

License: MIT License

Go 96.35% Shell 3.36% Makefile 0.29%
cli terminal drawing ascii ascii-art canvas gocui termbox-go go golang

diagram's Introduction

Diagram

Go Reference build Go Report Card license

Diagram is a small CLI application to generate hand drawn diagrams from ASCII art.

screencast

Installation

In order to run the application please make sure that Go is installed on your local machine and check if $GOPATH/bin is included into the PATH directory.

Run the following commands to download the project and build the executable.

$ git clone https://github.com/esimov/diagram
$ cd diagram
$ go build

# Start the application
$ diagram

Notice: The tool requires the glfw graphic library, so make sure that it is installed on your local machine.

For a full list of the required external dependencies check the official documentation of go-glfw (https://github.com/go-gl/glfw/blob/master/README.md).

Build

A shell script is bundled into the library to mitigate the generation of binary files for the most widespread operating systems, but take care: different dependencies are needed for different operating systems. To build the executable file run:

$ make all

Usage

Once you are inside the terminal application you can create, edit or delete the ASCII diagrams. By pressing CTRL+d you can convert the ASCII art into a handwritten diagram. The generated PNG file will be saved into the output folder relative to the current path.

Command Line support

The application also supports the generation of hand drawn diagrams directly from command line without to enter into the CLI application.

$ diagram --help will show the currently supported options:

┌┬┐┬┌─┐┌─┐┬─┐┌─┐┌┬┐
 │││├─┤│ ┬├┬┘├─┤│││
─┴┘┴┴ ┴└─┘┴└─┴ ┴┴ ┴
    Version: 1.0.4

CLI app to convert ASCII arts into hand drawn diagrams.

  -font string
    	Path to the font file (default "/Users/esimov/Projects/Go/src/github.com/esimov/diagram/font/gloriahallelujah.ttf")
  -in string
    	Source
  -out string
    	Destination
  -preview
    	Show the preview window (default true)

CLI Examples

Read input from sample.txt and write image to sample.png showing a preview window with the hand drawn diagram:

diagram -in sample.txt -out sample.png

Read input from sample.txt and write image to sample.png, and exit immediately without showing a preview window:

diagram -in sample.txt -out sample.png -preview=false

Generate diagram as above but use a font at a different location:

diagram -in sample.txt -out sample.png -preview=false -font /path/to/my/font/MyHandwriting.ttf

Key bindings

Key Action
Tab Next Panel
Shift+Tab Previous Panel
Ctrl+s Open Save Diagram Modal
Ctrl+s Save Diagram
Ctrl+d Convert Ascii to PNG
Ctrl+x Clear the editor content
Ctrl+z Restore the editor content
PageUp Jump to the top
PageDown Jump to the bottom
Home Jump to the line start
End Jump to the line end
Delete/Backspace Delete diagram
Ctrl+c Quit

Example

Input Output

The application was tested on Ubuntu, MacOS and Windows.

Acknowledgements

The ASCII to PNG conversion was ported from shaky.dart.

Dependencies

Author

License

Copyright © 2017 Endre Simo

This project is under the MIT License. See the LICENSE file for the full license text.

diagram's People

Contributors

esimov avatar marco-m avatar mmurphy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

diagram's Issues

dependencies

In order to make it work on Debian 11, I had to install many dependencies:

sudo apt-get install \
  libxcursor-dev \
  libxrandr-dev  \
  libxinerama-dev  \
  libgl-dev \
  libxi-dev \
  freeglut3-dev \
  libglu1-mesa-dev  \
  libglfw3-dev \
  libgles2-mesa-dev \
  libglu1-mesa-dev \
  mesa-common-dev \
  xorg-dev

go build

This may solve #9.

Plus I had to manually copy the font to the expected folder.

mkdir -p $HOME/go/src/github.com/esimov/diagram/font
cp font/gloriahallelujah.ttf $HOME/go/src/github.com/esimov/diagram/font/

Nice tool BTW !

go get failed on Wayland system

Go get failed

$ go get github.com/esimov/diagram
# github.com/esimov/diagram/vendor/github.com/go-gl/glfw/v3.2/glfw
In file included from ./glfw/src/internal.h:169,
                 from ./glfw/src/context.c:28,
                 from ../go/src/github.com/esimov/diagram/vendor/github.com/go-gl/glfw/v3.2/glfw/c_glfw.go:4:
./glfw/src/x11_platform.h:39:10: fatal error: X11/Xcursor/Xcursor.h: No such file or directory
   39 | #include <X11/Xcursor/Xcursor.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

Go version

$ go version  
go version go1.13.6 linux/amd64

System info

$ cat /etc/os-release 
NAME=Fedora
VERSION="31 (Thirty One)"
ID=fedora
VERSION_ID=31
VERSION_CODENAME=""
PLATFORM_ID="platform:f31"
PRETTY_NAME="Fedora 31 (Thirty One)"
ANSI_COLOR="0;34"
LOGO=fedora-logo-icon
CPE_NAME="cpe:/o:fedoraproject:fedora:31"
HOME_URL="https://fedoraproject.org/"
DOCUMENTATION_URL="https://docs.fedoraproject.org/en-US/fedora/f31/system-administrators-guide/"
SUPPORT_URL="https://fedoraproject.org/wiki/Communicating_and_getting_help"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Fedora"
REDHAT_BUGZILLA_PRODUCT_VERSION=31
REDHAT_SUPPORT_PRODUCT="Fedora"
REDHAT_SUPPORT_PRODUCT_VERSION=31
PRIVACY_POLICY_URL="https://fedoraproject.org/wiki/Legal:PrivacyPolicy"
$ loginctl show-session 4 -p Type
Type=wayland

Failure to Install / Get

Anytime I try any of the actions (get, install, build, etc), I receive the following error. Any ideas?

# github.com/esimov/diagram/vendor/github.com/go-gl/glfw/v3.2/glfw
vendor/github.com/go-gl/glfw/v3.2/glfw/c_glfw.go:4:30: fatal error: glfw/src/context.c: No such file or directory
compilation terminated.
# github.com/esimov/diagram/vendor/github.com/go-gl/gl/v2.1/gl
vendor/github.com/go-gl/gl/v2.1/gl/procaddr.go:52:21: fatal error: GL/glx.h: No such file or directory
compilation terminated.

go get failed

From ubuntu 18.04 LTS:

$ apt-get install libglfw3-dev
$ go get github.com/esimov/diagram

# github.com/esimov/diagram/vendor/github.com/go-gl/glfw/v3.2/glfw
In file included from code/golang/gopath/src/github.com/esimov/diagram/vendor/github.com/go-gl/glfw/v3.2/glfw/c_glfw_linbsd.go:22:0:
code/golang/gopath/src/github.com/esimov/diagram/vendor/github.com/go-gl/glfw/v3.2/glfw/glfw/src/linux_joystick.c: In function ‘_glfwInitJoysticksLinux’:
code/golang/gopath/src/github.com/esimov/diagram/vendor/github.com/go-gl/glfw/v3.2/glfw/glfw/src/linux_joystick.c:224:42: warning: ‘%s’ directive output may be truncated writing up to 255 bytes into a region of size 9 [-Wformat-truncation=]
             snprintf(path, sizeof(path), "%s/%s", dirname, entry->d_name);
                                          ^~~~~~~
In file included from /usr/include/stdio.h:862:0,
                 from /usr/include/X11/Xcursor/Xcursor.h:26,
                 from code/golang/gopath/src/github.com/esimov/diagram/vendor/github.com/go-gl/glfw/v3.2/glfw/glfw/src/x11_platform.h:39,
                 from code/golang/gopath/src/github.com/esimov/diagram/vendor/github.com/go-gl/glfw/v3.2/glfw/glfw/src/internal.h:169,
                 from code/golang/gopath/src/github.com/esimov/diagram/vendor/github.com/go-gl/glfw/v3.2/glfw/glfw/src/x11_init.c:28,
                 from code/golang/gopath/src/github.com/esimov/diagram/vendor/github.com/go-gl/glfw/v3.2/glfw/c_glfw_linbsd.go:17:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:64:10: note: ‘__builtin___snprintf_chk’ output between 12 and 267 bytes into a destination of size 20
   return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        __bos (__s), __fmt, __va_arg_pack ());
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

go get deprecated

It would seem like go get has been deprecated.
Tried installing using go install github.com/esimov/diagram@latest but that failed with the following output:

go: downloading github.com/esimov/diagram v1.0.5
go: github.com/esimov/diagram@latest (in github.com/esimov/[email protected]):
	The go.mod file for the module providing named packages contains one or
	more replace directives. It must not contain directives that would cause
	it to be interpreted differently than if it were the main module.

I have never written a line of Go in my life so I can't really provide deeper insight.

This Thing is Amazing on macOS, Some Notes

THANKS for creating this. It's great.


For the idiots in the room like me:

  • tried it on macOS Ventura 13.4
  • had to run some commands like
brew install glfw
brew install go

then my run script looks like this

#!/usr/bin/env bash

# see https://github.com/esimov/diagram
./diagram -in dans-diagram.txt -out diagram.png -font "font/gloriahallelujah.ttf" -preview=false
open diagram.png

This tool is pretty amazing for what I needed. Keep your ASCII under version control because it's unpredictable what works and what doesn't. Also note that ChatGPT can't produce great ASCII art, but it can modify ASCII art quite well.

image

ASCII Art

Currently we have 65" run. We can get to 81.5
* removing three boards from top platform
* covering three boards from Walkway to Dock

Each Step
* 16.5" Tread (3 boards)
* 7.167" Riser

NOTE: 16.5" Tread is three plastic boards


                                                81.5" run
                            -------------------------------------------------
      --------------------- Platform
     |                     |
     |                     |  Step 1
     |                      ---------
     |                               |
     |                               | Step 2
     |                               ---------
     |                                        |
     | 43" Rise                               | Step 3
     |                                         ---------
     |                                                  |
     |                                                  | Step 4
     |                                                  ---------
     |                                                            |
     |                                                            | Step 5
     |                                                            ---------
     |                                                                     |
     |                                                                     |
                                                                           ----------------------
                                                                               Walkway to Dock

---------------------------------------------------

build fails with "fatal error: glfw/src/context.c: No such file or directory"

As filed in #6, building diagram fails with a failure to find components from glfw, even when glfw is installed (though note that the README does not give instructions detailing deps for diagram).

This failure occurs with current Go releast go1.11.1 and with go1.9.7 which is approximately what is being tested on by this project at travis - which also fails in the same manner.

~ $ uname -a
Linux cube 4.4.0-139-generic #165-Ubuntu SMP Wed Oct 24 10:58:50 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
~ $ go version
go version go1.9.7 linux/amd64
~ $ dpkg -l libglfw*
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version      Architecture Description
+++-==============-============-============-=================================
ii  libglfw3:amd64 3.1.2-3      amd64        portable library for OpenGL, wind
ii  libglfw3-dev:a 3.1.2-3      amd64        portable library for OpenGL, wind
~/src/github.com/esimov/diagram [master]$ go install
# github.com/esimov/diagram/vendor/github.com/go-gl/glfw/v3.2/glfw
vendor/github.com/go-gl/glfw/v3.2/glfw/c_glfw.go:4:30: fatal error: glfw/src/context.c: No such file or directory
compilation terminated.

Invoking build.sh also fails with the same error.

Maybe you are building glfw locally and this is the difference? But with the current instructions, this doesn't build.

Build error with "ui.gui.Execute undefined"

In now, this project has build error on "go get" command with below message:

src/github.com/esimov/diagram/ui/panels.go:241: ui.gui.Execute undefined (type *gocui.Gui has no field or method Execute)
src/github.com/esimov/diagram/ui/panels.go:467: ui.gui.Execute undefined (type *gocui.Gui has no field or method Execute)
src/github.com/esimov/diagram/ui/panels.go:610: ui.gui.Execute undefined (type *gocui.Gui has no field or method Execute)

this is caused by rename method in gocui.
jroimartin/gocui@6564cfc

panic: open ./font/gloriahallelujah.ttf: no such file or directory

Great tool :-)

There is a crash if you are not running the tool from the root of the git checkout because the font isnt there.

You may be able to embed the font using something like https://github.com/jteeuwen/go-bindata

thughes@titanium [0] $ diagram
panic: open ./font/gloriahallelujah.ttf: no such file or directory

goroutine 1 [running, locked to thread]:
github.com/esimov/diagram/canvas.NewCanvas(0xc4203c9900, 0x6e400f, 0x1b, 0x4008000000000000, 0x1)
	/home/thughes/go/src/github.com/esimov/diagram/canvas/canvas.go:25 +0x125
github.com/esimov/diagram/canvas.DrawDiagram(0xc4203b28a0, 0x5d, 0xc420406540, 0x1f, 0xa, 0xc420406540)
	/home/thughes/go/src/github.com/esimov/diagram/canvas/generator.go:336 +0x238
github.com/esimov/diagram/ui.(*UI).drawDiagram(0xc42007a480, 0x6d5d9c, 0x7, 0xc420055e6c, 0x2)
	/home/thughes/go/src/github.com/esimov/diagram/ui/panels.go:459 +0x2f4
github.com/esimov/diagram/ui.onDrawDiagram.func1(0xc420104000, 0xc4201162d0, 0xc420055cc0, 0x510d67)
	/home/thughes/go/src/github.com/esimov/diagram/ui/handlers.go:65 +0x3f
github.com/jroimartin/gocui.(*Gui).execKeybindings(0xc420104000, 0xc4201162d0, 0xc420055d70, 0xc420055d28, 0x48be40, 0xc420055e08)
	/home/thughes/go/src/github.com/jroimartin/gocui/gui.go:629 +0xe6
github.com/jroimartin/gocui.(*Gui).onKey(0xc420104000, 0xc420055d70, 0x51a577, 0x18)
	/home/thughes/go/src/github.com/jroimartin/gocui/gui.go:593 +0x1d4
github.com/jroimartin/gocui.(*Gui).handleEvent(0xc420104000, 0xc420055d70, 0xc420055d68, 0x1)
	/home/thughes/go/src/github.com/jroimartin/gocui/gui.go:413 +0x40
github.com/jroimartin/gocui.(*Gui).MainLoop(0xc420104000, 0xc420055ec8, 0x5d8a43)
	/home/thughes/go/src/github.com/jroimartin/gocui/gui.go:373 +0x1ac
github.com/esimov/diagram/ui.(*UI).Loop(0xc42007a480)
	/home/thughes/go/src/github.com/esimov/diagram/ui/ui.go:66 +0x32
github.com/esimov/diagram/ui.InitApp()
	/home/thughes/go/src/github.com/esimov/diagram/ui/app.go:10 +0x68
main.main()
	/home/thughes/go/src/github.com/esimov/diagram/main.go:37 +0x1ee

a linked package fails - wh

When doing a "go get", fogelman/gg, which is the API for rendering 2D gfx, fails to compile. How to overcome this?

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.