Update bin/emit

This commit is contained in:
0x1eef 2024-01-28 02:16:40 -03:00
parent c3914e6cc4
commit 00c15a2c83

View file

@ -2,23 +2,30 @@
$stdout.sync = true $stdout.sync = true
def noecho def noecho
system "stty -echo" system("stty -echo")
str = yield yield
system "stty echo" ensure
str system("stty echo")
end end
def read
noecho { $stdin.gets }
.gsub(/[^A-Za-z0-9_\s\/\-,;:*"']/, '')
end
reads = 0
loop do loop do
str = noecho { $stdin.gets } tab, buf = "\t", read
str = str.gsub(/[^A-Za-z0-9_\s\/\-,;:"']/, '') if IO.select([$stdin], [], [], 0.1).nil?
sep = "\t" reads = 0
class_name, class_body = str.split(sep, 2) print buf.chomp, "}", "\n"
if class_name && class_body elsif buf.include?(tab)
print "}\n" if reads > 0
class_name, class_body = buf.split(tab, 2)
class_name.gsub!(%r|([/.])|) { "\\#{_1}" } class_name.gsub!(%r|([/.])|) { "\\#{_1}" }
print ".#{class_name.chomp}", print ".#{class_name} {", "\n", " " * 2, class_body.chomp, "\n"
" { \n", reads += 1
" " * 2, else
class_body.chomp, print " " * 2, buf
"\n}\n"
end end
end end