io-line.rb 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 30852709ffb0f880474bb199ffe2a6a8d09a2e4d7eaa57d44807742a93dd58c3
4
+ data.tar.gz: 84e951c35619e7180504effc5e074af828061f69264febe9fd3be430b2b6e575
5
+ SHA512:
6
+ metadata.gz: 399d5e5e18b760f86a563526c235fd3f43942acff34ea1a8c00a1278c2768dbb8dc6671a6ec7da0b859ab6aef9fabefab5cb402d3918b0f381ee44b27d243848
7
+ data.tar.gz: 575d115de80bd38981f9a67296add1ac71f96f221cce02ce1bba0945022c77beb10b1ccac51948cded2646b01361da2b368176191caacdf6a02fa76b7308a140
data/.projectile ADDED
File without changes
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ ## About
2
+
3
+ io-line.rb is an IO library that can reuse one or more lines of output. <br>
4
+ The implementation uses the
5
+ [io-console](https://www.rubydoc.info/gems/io-console)
6
+ library from Ruby's stdlib.
7
+
8
+ ## Examples
9
+
10
+ ### One line
11
+
12
+ The following example counts from 1 up to 100. The number from the previous
13
+ iteration is replaced with a number from the current iteration, and the same
14
+ line is reused until the iteration is completed. It is possible to end the
15
+ current line, and move onto the next line with the `IO::Line#end` method:
16
+
17
+ ```ruby
18
+ require "io/line"
19
+ line = IO::Line.new($stdout)
20
+ 1.upto(100) do |number|
21
+ line.rewind.print(number)
22
+ sleep 0.1
23
+ end
24
+ line.end
25
+ ```
26
+
27
+ ## Documentation
28
+
29
+ A complete API reference is available at
30
+ [0x1eef.github.io/x/io-line.rb](https://0x1eef.github.io/x/io-line.rb)
31
+
32
+ ## Install
33
+
34
+ io-line.rb can be installed via rubygems.org:
35
+
36
+ gem install io-line.rb
37
+
38
+ ## Sources
39
+
40
+ * [GitHub](https://github.com/0x1eef/io-line.rb)
41
+ * [GitLab](https://gitlab.com/0x1eef/io-line.rb)
42
+
43
+ ## License
44
+
45
+ [BSD Zero Clause](https://choosealicense.com/licenses/0bsd/)
46
+ <br>
47
+ See [LICENSE](./LICENSE)
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "./lib/io/line"
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "io-line.rb"
6
+ gem.authors = ["0x1eef"]
7
+ gem.email = ["0x1eef@protonmail.com"]
8
+ gem.homepage = "https://github.com/0x1eef/io-line.rb#readme"
9
+ gem.version = IO::Line::VERSION
10
+ gem.licenses = ["BSD0L"]
11
+ gem.files = `git ls-files`.split($/)
12
+ gem.require_paths = ["lib"]
13
+ gem.summary = "Line manipulation via io-console"
14
+ gem.description = gem.summary
15
+ gem.add_runtime_dependency "io-console", "~> 0.5"
16
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ class IO::Line::Multiple
4
+ def initialize(lines, cursor)
5
+ @lines = lines
6
+ @cursor = cursor
7
+ end
8
+
9
+ def print(*strs, lineno:)
10
+ line = @lines[lineno]
11
+ if lineno > @cursor
12
+ line.io.cursor_down(lineno - @cursor)
13
+ elsif lineno < @cursor
14
+ line.io.cursor_up(lineno + @cursor)
15
+ end
16
+ @cursor = lineno
17
+ line.rewind.print(*strs)
18
+ end
19
+ end
data/lib/io/line.rb ADDED
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ class IO::Line
4
+ require "io/console"
5
+ require_relative "line/multiple"
6
+
7
+ VERSION = "0.1.0"
8
+ attr_reader :io
9
+
10
+ def initialize(io)
11
+ @io = io
12
+ end
13
+
14
+ def print(*strs)
15
+ tap { @io.print(strs.join.gsub($/, "")) }
16
+ end
17
+
18
+ def end
19
+ tap { @io.print($/) }
20
+ end
21
+
22
+ def rewind
23
+ tap do
24
+ @io.erase_line(2)
25
+ @io.goto_column(0)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,7 @@
1
+ require "io/line"
2
+ line = IO::Line.new($stdout)
3
+ 1.upto(100) do |number|
4
+ line.rewind.print(number)
5
+ sleep 0.1
6
+ end
7
+ line.end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: io-line.rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - '0x1eef'
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-06-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: io-console
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.5'
27
+ description: Line manipulation via io-console
28
+ email:
29
+ - 0x1eef@protonmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".projectile"
35
+ - README.md
36
+ - io-line.rb.gemspec
37
+ - lib/io/line.rb
38
+ - lib/io/line/multiple.rb
39
+ - share/examples/io-line.rb/one_line_example.rb
40
+ homepage: https://github.com/0x1eef/io-line.rb#readme
41
+ licenses:
42
+ - BSD0L
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubygems_version: 3.5.9
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Line manipulation via io-console
63
+ test_files: []