tty-font 0.1.0 → 0.2.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 +4 -4
- data/.rspec +1 -0
- data/.travis.yml +3 -2
- data/CHANGELOG.md +12 -0
- data/README.md +1 -1
- data/appveyor.yml +2 -0
- data/examples/3d.rb +1 -1
- data/examples/doom.rb +1 -1
- data/examples/standard.rb +1 -1
- data/examples/star_wars_logo.rb +2 -1
- data/examples/starwars.rb +1 -1
- data/examples/straight.rb +1 -1
- data/lib/tty/font.rb +14 -14
- data/lib/tty/font/result.rb +33 -0
- data/lib/tty/font/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a04850a2bc3ff2ea8a003c245f440f58bea9dc88
|
4
|
+
data.tar.gz: 0e10290aac997330a2556a13f9e7f250e9762de6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55fcb422aca75166e4bc80fab96ac8c78a9715f228f718a846ac5008dc9ecf49fd4af254b28950c3c8d95a818538c17f5aed18b65473270670c69b82974eba9a
|
7
|
+
data.tar.gz: 5f9244ea33eeda0776620b0c179f8a2be0c5b276784b4e5e8b98b9591ff002776749c1b7653bf56b0df4279c84512e062e6057e3879f2c2d93cb2e4ea6881f0b
|
data/.rspec
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,19 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
## [v0.2.0] - 2018-02-20
|
4
|
+
|
5
|
+
### Added
|
6
|
+
* Add Result for processing transformed output
|
7
|
+
|
8
|
+
### Changed
|
9
|
+
* Change #add_line to #create_line and refactor
|
10
|
+
|
11
|
+
### Fixed
|
12
|
+
* Fix File to use global namespace
|
13
|
+
|
3
14
|
## [v0.1.0] - 2017-12-18
|
4
15
|
|
5
16
|
* Initial implementation and release
|
6
17
|
|
18
|
+
[v0.2.0]: https://github.com/piotrmurach/tty-font/compare/v0.1.0...v0.2.0
|
7
19
|
[v0.1.0]: https://github.com/piotrmurach/tty-font/compare/v0.1.0
|
data/README.md
CHANGED
data/appveyor.yml
CHANGED
data/examples/3d.rb
CHANGED
data/examples/doom.rb
CHANGED
data/examples/standard.rb
CHANGED
data/examples/star_wars_logo.rb
CHANGED
data/examples/starwars.rb
CHANGED
data/examples/straight.rb
CHANGED
data/lib/tty/font.rb
CHANGED
@@ -3,11 +3,12 @@
|
|
3
3
|
require 'pathname'
|
4
4
|
require 'yaml'
|
5
5
|
|
6
|
+
require_relative 'font/result'
|
6
7
|
require_relative 'font/version'
|
7
8
|
|
8
9
|
module TTY
|
9
10
|
class Font
|
10
|
-
FONTS_PATH = Pathname.new(File.join(__dir__, 'font'))
|
11
|
+
FONTS_PATH = ::Pathname.new(::File.join(__dir__, 'font'))
|
11
12
|
|
12
13
|
def initialize(font = :standard, **options)
|
13
14
|
@font = font
|
@@ -22,16 +23,16 @@ module TTY
|
|
22
23
|
#
|
23
24
|
# @api public
|
24
25
|
def write(text, **options)
|
25
|
-
|
26
|
+
result = Result.new
|
26
27
|
chars = text.chars
|
27
28
|
space = options.fetch(:letter_spacing) { @space }
|
28
29
|
indexes = words_boundary_indexes(text)
|
29
30
|
|
30
|
-
@data['char_height'].times do |
|
31
|
-
|
31
|
+
@data['char_height'].times do |line_no|
|
32
|
+
result << create_line(chars, indexes, line_no, space)
|
32
33
|
end
|
33
34
|
|
34
|
-
|
35
|
+
result.to_s
|
35
36
|
end
|
36
37
|
|
37
38
|
# Inspect font attributes
|
@@ -49,18 +50,17 @@ module TTY
|
|
49
50
|
|
50
51
|
private
|
51
52
|
|
52
|
-
#
|
53
|
+
# Create a new line for the output
|
54
|
+
#
|
55
|
+
# @return [String]
|
53
56
|
#
|
54
57
|
# @api private
|
55
|
-
def
|
56
|
-
chars.each_with_index.
|
57
|
-
|
58
|
-
acc << @data['chars'][char][line]
|
59
|
-
acc << ' ' * space if space > 0 && !indexes.include?(indx)
|
60
|
-
else
|
58
|
+
def create_line(chars, indexes, line_no, space)
|
59
|
+
chars.each_with_index.map do |char, i|
|
60
|
+
unless @data['chars'].key?(char)
|
61
61
|
raise ArgumentError, "Font #{@font} doesn't support '#{char}' character"
|
62
62
|
end
|
63
|
-
|
63
|
+
@data['chars'][char][line_no] + (!indexes.include?(i) ? ' ' : '') * space
|
64
64
|
end.join
|
65
65
|
end
|
66
66
|
|
@@ -80,7 +80,7 @@ module TTY
|
|
80
80
|
#
|
81
81
|
# @api private
|
82
82
|
def load_font(font_path)
|
83
|
-
YAML.load_file(font_path)
|
83
|
+
::YAML.load_file(font_path)
|
84
84
|
rescue Errno::ENOENT
|
85
85
|
raise ArgumentError, "Font '#{File.basename(font_path)}' not found"
|
86
86
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TTY
|
4
|
+
class Font
|
5
|
+
# Represents font rendering result. It provides more
|
6
|
+
# convenient interface for using the output.
|
7
|
+
class Result
|
8
|
+
include Enumerable
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@output = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def each(&block)
|
15
|
+
return to_enum(:each) unless block
|
16
|
+
@output.each(&block)
|
17
|
+
end
|
18
|
+
|
19
|
+
def add(line)
|
20
|
+
@output << line
|
21
|
+
end
|
22
|
+
alias << add
|
23
|
+
|
24
|
+
def lines
|
25
|
+
@output
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_s
|
29
|
+
@output.join("\n")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end # Font
|
33
|
+
end # TTY
|
data/lib/tty/font/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tty-font
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Murach
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- lib/tty/font.rb
|
88
88
|
- lib/tty/font/3d.yml
|
89
89
|
- lib/tty/font/doom.yml
|
90
|
+
- lib/tty/font/result.rb
|
90
91
|
- lib/tty/font/standard.yml
|
91
92
|
- lib/tty/font/starwars.yml
|
92
93
|
- lib/tty/font/straight.yml
|