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