From fd52575faf95581d180678e21c5be321541e8f94 Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Fri, 15 Jul 2022 16:43:50 -0300 Subject: [PATCH] io/line: rewrite with io/console --- binlib/io/line.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/binlib/io/line.rb b/binlib/io/line.rb index f32a01c..4358d27 100644 --- a/binlib/io/line.rb +++ b/binlib/io/line.rb @@ -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