Add io-line.rb gem

Replaces binlib/io/line
This commit is contained in:
0x1eef 2023-02-04 16:05:37 -03:00 committed by Robert
parent fb04d4b3d3
commit ad34160215
8 changed files with 6 additions and 49 deletions

View file

@ -4,3 +4,4 @@ gem "nokogiri", "~> 1.13"
gem "paint", "~> 2.2"
gem "json", "~> 2.6"
gem "standard", "~> 1.12"
gem "io-line.rb", "~> 0.1", github: "0x1eef/io-line.rb", tag: "v0.1.0"

View file

@ -19,7 +19,7 @@ Process.setproctitle("quran-pull (insert-chapter-metadata)")
require "bundler/setup"
require "json"
require "paint"
require_relative "../../binlib/io/line"
require "io/line"
##
# Utils

View file

@ -15,7 +15,7 @@ Process.setproctitle("quran-pull (pull-chapters-data)")
require "bundler/setup"
require "json"
require "paint"
require_relative "../../binlib/io/line"
require "io/line"
##
# Utils

View file

@ -22,7 +22,7 @@ require "nokogiri"
require "json"
require "paint"
require "fileutils"
require_relative "../../../binlib/io/line"
require "io/line"
##
# Configuration variables

View file

@ -20,7 +20,7 @@ require "net/http"
require "nokogiri"
require "json"
require "paint"
require_relative "../../binlib/io/line"
require "io/line"
##
# Configuration variables.

View file

@ -20,7 +20,7 @@ require "net/http"
require "nokogiri"
require "json"
require "paint"
require_relative "../../binlib/io/line"
require_relative "io/line"
##
# Configuration variables.

View file

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

View file

@ -1,19 +0,0 @@
# frozen_string_literal: true
class IO::Line::Multiple
def initialize(lines, cursor)
@lines = lines
@cursor = cursor
end
def print(*strs, lineno:)
line = @lines[lineno]
if lineno > @cursor
line.io.cursor_down(lineno - @cursor)
elsif lineno < @cursor
line.io.cursor_up(lineno + @cursor)
end
@cursor = lineno
line.rewind.print(*strs)
end
end