-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdgen.moon
97 lines (81 loc) · 1.95 KB
/
dgen.moon
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
lgi = require 'lgi'
lpeg = require 'lpeg'
serpent = require 'serpent'
import Gtk,Gdk from lgi
import P,C,Ct,S,V from lpeg
local clipboard
signature = Gtk.Entry {
placeholder_text: 'Signature'
}
description = Gtk.TextView {
expand: true
wrap_mode: 'WORD'
}
output = Gtk.TextView {
expand: true
wrap_mode: 'WORD'
}
make_lines = (n,data) ->
txt = [[]]
buf = {}
for i=1,#data
table.insert(buf,data[i])
if i%n == 0
txt ..= table.concat(buf," ")
buf = {}
txt ..= "\\n"
txt ..= table.concat(buf," ")
txt
generate = Gtk.Button { label: 'Generate' }
generate.on_clicked = () =>
grammar = P {
'words'
words: Ct((C(V'word') + V'notword')^0)
notword: S' \n'
word: (P(1) - V'notword')^1
}
data = grammar\match(description.buffer.text)
print(serpent.block(data,{comment:false}))
pdata = make_lines(10,data)
final_txt = "'KEY': { signature: '#{signature.text}', description: '# #{signature.text}\\n\\n#{pdata}' },"
output.buffer.text = final_txt
entrybox = Gtk.Box {
orientation: 'VERTICAL'
signature
Gtk.Frame {Gtk.ScrolledWindow {description}}
generate
}
toclipboard = Gtk.Button { label: 'Copy' }
with toclipboard\get_style_context!
\add_class 'destructive-action'
toclipboard.on_clicked = () =>
clipboard\set_text output.buffer.text, -1
output.buffer.text = ''
signature.text = ''
description.buffer.text = ''
outbox = Gtk.Box {
margin_top: 5
orientation: 'VERTICAL'
Gtk.Frame {Gtk.ScrolledWindow {output}}
toclipboard
}
with entrybox\get_style_context!
\add_class 'linked'
with outbox\get_style_context!
\add_class 'linked'
window = Gtk.Window {
width_request: 500
height_request: 500
title: 'Description Generator'
Gtk.Box {
margin: 5
orientation: 'VERTICAL'
entrybox
outbox
}
}
display = window\get_display!
clipboard = Gtk.Clipboard.get_for_display(display, Gdk.SELECTION_CLIPBOARD)
window.on_destroy = () => Gtk.main_quit!
window\show_all!
Gtk\main!