nkh / P5-App-Asciio

Plain ASCII diagram
https://nkh.github.io/P5-App-Asciio/
56 stars 4 forks source link

How to save file for later editing? #14

Closed ceremcem closed 1 year ago

ceremcem commented 1 year ago

As we discussed earlier in the Stackoverflow question, I tried to save the drawing in a format that we can use to edit it later.

However, when I right click and "Save" the current drawing, it just saves the drawn ascii art into a file. When I try to reopen the saved file in Asciio, it throws the following error in the console:

Asciio: Warning: can't find setup data '/home/ceremcem/.config/Asciio/Asciio.ini'
000-button-press-3   Mouse right-click                        [actions/default_bindings.pl]
                     Open
invalid buffer (too short 657 or bad marker 32) at /home/ceremcem/perl5/lib/perl5/App/Asciio/Io.pm line 61.
Use of uninitialized value in subroutine entry at /home/ceremcem/perl5/lib/perl5/App/Asciio/Io.pm line 63.
*** unhandled exception in callback:
***   Sereal: Error: Bad Sereal header: Not a valid Sereal document. at offset 1 of input at srl_decoder.c line 619 at /home/ceremcem/perl5/lib/perl5/App/Asciio/Io.pm line 63.
***  ignoring at /usr/share/perl5/Gtk3.pm line 572.
000-button-press-1   Mouse left-click                         [actions/default_bindings.pl]

I expect a JSON-like data structure that represents the drawing.

nkh commented 1 year ago

what name did you use for the file?

ceremcem commented 1 year ago

I saved the file as a.txt.

ceremcem commented 1 year ago

A-ha! If I use any extension except .txt, it stores the drawing in its internal format, I guess.

nkh commented 1 year ago

As I explained before.

.txt, .png (if that still works), and .svg, will save in those format. go for .asciio, it's the one that I use.

ceremcem commented 1 year ago

Is it possible to save the internal format in Base-64 at the end of the drawing? In this way, we can copy and paste the drawing inside our source code and still copy back to asciio for later editing.

Example .txt output:

                                           .--------.
                                         ,'       .'|
                                        :-------.'# |
                                        | # # # | # |
                                        | # # # | # |---------.
                                        | # # # | # |         |
                                        | # # # | # |         |
                                        | # # # | #           |
                                        | # # # |             |
                                                              v
                                                            (\_/)
                                                            (O.o)
                                                            (> <)

# Source: N4IgLiBcIDwBYFMA2SD2A+GB6RKMgBoQBnKEAK1KIGMzCQ4pQAnMpAQzAWIgF9egA

(Note: Saving in png does not work)

ceremcem commented 1 year ago

Note: Saving in svg also does not work.

nkh commented 1 year ago

there's some code for saving in base64 but it's not a good idea, the code become large very quickly (it's not just the boxes that are saved) and it looks bad in the code, much better to keep the asciio files under version control. the extension for base64 is .perl, but again, it's a bad idea and I'm not sure the importer stil works.

did you install "goat" as I told you? that's a dependency for saving in svg format.

the exporter for .png is here P5-App-Asciio/setup/GTK/import_export/png.pl and it's commented out since it hasn't been ported to GTK3 yet. I have no plans to do that in the near future.

ceremcem commented 1 year ago

Advantage of Base-64 is that it will be only one line independent of the size.

How can I use the internal file in my own application? What is the object format you use? I want to take a look at it, maybe I could provide a JSON or Base-64 converter that suits my needs.

nkh commented 1 year ago

I fixed the base64 exporter, you'll need to pull the latest.

the code is already written here: setup/import_export/perl.pl

and here's an example of the output:

example.txt