io/line: rewrite with io/console

This commit is contained in:
0x1eef 2022-07-15 16:43:50 -03:00
parent a81a7b0df7
commit fd52575faf

View file

@ -1,24 +1,24 @@
# frozen_string_literal: true
class IO::Line
require "io/console"
def initialize(io)
@io = io
@size = 0
end
def print(*strs)
tap do
str = strs.join
@size = str.gsub(/\n*/, "").size
@io.print(str)
end
tap { @io.print(strs.join.gsub($/, "")) }
end
def end
tap { @io.print "\n" }
tap { @io.print("\n") }
end
def rewind
tap { @io.print "\b \b" * @size }
tap do
@io.erase_line(2)
@io.goto_column(0)
end
end
end