From 00c15a2c839c33379a765244f3db33c6ce376871 Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Sun, 28 Jan 2024 02:16:40 -0300 Subject: [PATCH] Update bin/emit --- bin/emit | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/bin/emit b/bin/emit index 817bd79..e34b974 100755 --- a/bin/emit +++ b/bin/emit @@ -2,23 +2,30 @@ $stdout.sync = true def noecho - system "stty -echo" - str = yield - system "stty echo" - str + system("stty -echo") + yield +ensure + system("stty echo") end +def read + noecho { $stdin.gets } + .gsub(/[^A-Za-z0-9_\s\/\-,;:*"']/, '') +end + +reads = 0 loop do - str = noecho { $stdin.gets } - str = str.gsub(/[^A-Za-z0-9_\s\/\-,;:"']/, '') - sep = "\t" - class_name, class_body = str.split(sep, 2) - if class_name && class_body + tab, buf = "\t", read + if IO.select([$stdin], [], [], 0.1).nil? + reads = 0 + print buf.chomp, "}", "\n" + elsif buf.include?(tab) + print "}\n" if reads > 0 + class_name, class_body = buf.split(tab, 2) class_name.gsub!(%r|([/.])|) { "\\#{_1}" } - print ".#{class_name.chomp}", - " { \n", - " " * 2, - class_body.chomp, - "\n}\n" + print ".#{class_name} {", "\n", " " * 2, class_body.chomp, "\n" + reads += 1 + else + print " " * 2, buf end end