text-ui 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/README.md +3 -2
- data/lib/tui/block.rb +9 -7
- data/lib/tui/format.rb +2 -2
- data/lib/tui/tools.rb +15 -0
- metadata +18 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 53c472908d1c2de61f32484c61acfe607e0014c5fa911beb4ec1f1337db1e26c
|
|
4
|
+
data.tar.gz: 62299d99d131f805ee761c2cd05f6dcfa0bd20f0c237c03eb0f34a9604e381bc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 89e95aaaff98c935aacabafe43786b500c04a5c89c4b273bdb9bc2ca17697bd5fb229f44d6dffbaca23da363748ce682b530c201f492533e875a227c4a361c1e
|
|
7
|
+
data.tar.gz: 1d0541d70ea1d118e95a2148f0fff536fbce42c4b22370ab96ab24b1dc92bbf0660457f61a78802d6fb9ddd1e4658db47d0b9d4fef278a152676a8df91a005e7
|
data/README.md
CHANGED
|
@@ -20,14 +20,15 @@ After checking out the repo, run `bundle install` to install dependencies. Then,
|
|
|
20
20
|
|
|
21
21
|
Feel free to submit bug reports and merge requests.
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
## Docs
|
|
24
24
|
|
|
25
25
|
`yard doc` generates some documentation.
|
|
26
26
|
|
|
27
27
|
`yard server --reload` starts a server with documentation available at http://localhost:8808
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
## TODOs
|
|
30
30
|
|
|
31
31
|
- resurrect logging
|
|
32
32
|
- handle Ctrl+C
|
|
33
|
+
- provide a way to gracefully interrupt execution and show summary
|
|
33
34
|
- provide interface to control data fetching: frequency, caching, make it parallel
|
data/lib/tui/block.rb
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'unicode/display_width'
|
|
4
|
+
|
|
3
5
|
require_relative 'format'
|
|
6
|
+
require_relative 'tools'
|
|
4
7
|
|
|
5
8
|
module Tui
|
|
6
9
|
# Basic TUI building block.
|
|
@@ -9,8 +12,7 @@ module Tui
|
|
|
9
12
|
# So a row is a way to compose multiple columns to a single "column" (see {Block#row}), which is an {::Array} of lines anyway.
|
|
10
13
|
class Block
|
|
11
14
|
|
|
12
|
-
attr_reader :width
|
|
13
|
-
attr_reader :array
|
|
15
|
+
attr_reader :width, :array
|
|
14
16
|
|
|
15
17
|
# Mix-in formatting methods.
|
|
16
18
|
# The {Blocks} class has only methods to make nested blocks
|
|
@@ -90,7 +92,7 @@ module Tui
|
|
|
90
92
|
# @param other either {::Array} or {::String} to push back
|
|
91
93
|
def << other
|
|
92
94
|
other.is_a?(Array) ? @array += other : @array << other
|
|
93
|
-
@width = @array
|
|
95
|
+
@width = Tools.calc_width @array
|
|
94
96
|
self
|
|
95
97
|
end
|
|
96
98
|
|
|
@@ -102,12 +104,12 @@ module Tui
|
|
|
102
104
|
def >> other
|
|
103
105
|
case other
|
|
104
106
|
when Array
|
|
105
|
-
@width = [@width,
|
|
107
|
+
@width = [@width, Tools.calc_width(other)].max
|
|
106
108
|
other.reverse_each { |i|
|
|
107
109
|
@array.unshift i
|
|
108
110
|
}
|
|
109
111
|
when String
|
|
110
|
-
@width = [@width, other
|
|
112
|
+
@width = [@width, Tools.calc_width(other)].max
|
|
111
113
|
@array.unshift other
|
|
112
114
|
end
|
|
113
115
|
self
|
|
@@ -122,7 +124,7 @@ module Tui
|
|
|
122
124
|
# Modify each "row" of the {Block} inline
|
|
123
125
|
def collect! &block
|
|
124
126
|
@array.collect!(&block)
|
|
125
|
-
@width = @array
|
|
127
|
+
@width = Tools.calc_width @array
|
|
126
128
|
end
|
|
127
129
|
|
|
128
130
|
private
|
|
@@ -136,7 +138,7 @@ module Tui
|
|
|
136
138
|
when String then [arg]
|
|
137
139
|
else [arg.to_s]
|
|
138
140
|
end
|
|
139
|
-
@width = @array
|
|
141
|
+
@width = Tools.calc_width @array
|
|
140
142
|
end
|
|
141
143
|
end
|
|
142
144
|
end
|
data/lib/tui/format.rb
CHANGED
|
@@ -59,7 +59,7 @@ module Tui
|
|
|
59
59
|
return self if width.nil? || @width > width # == case makes all lines width even
|
|
60
60
|
|
|
61
61
|
@width = width
|
|
62
|
-
@array.collect! { |line| line_transformer.call line, @width - line
|
|
62
|
+
@array.collect! { |line| line_transformer.call line, @width - Tools.calc_width(line) }
|
|
63
63
|
self
|
|
64
64
|
end
|
|
65
65
|
|
|
@@ -69,7 +69,7 @@ module Tui
|
|
|
69
69
|
# @param type {Symbol} :top, :center, :bottom
|
|
70
70
|
# @param height {Integer} target block height, is ignored if less than @width (look at {fit!})
|
|
71
71
|
def h_align! type = :top, height: @height
|
|
72
|
-
return self if height.nil?
|
|
72
|
+
return self if height.nil? || @array.size > height
|
|
73
73
|
|
|
74
74
|
extra_lines_count = height - @array.size
|
|
75
75
|
case type
|
data/lib/tui/tools.rb
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Various functions
|
|
4
|
+
module Tui::Tools
|
|
5
|
+
# Calculate width of a line / array of lines on console.
|
|
6
|
+
#
|
|
7
|
+
# Code mainains width by +/- operations in the most cases,
|
|
8
|
+
# but sometimes it needs re-calculating it from scratch
|
|
9
|
+
def self.calc_width value
|
|
10
|
+
case value
|
|
11
|
+
when Array then val.collect { |row| Unicode::DisplayWidth.of(row) }.max
|
|
12
|
+
when String then Unicode::DisplayWidth.of(val)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
metadata
CHANGED
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: text-ui
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Skorobogaty Dmitry
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
12
|
-
dependencies:
|
|
11
|
+
date: 2026-01-01 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: unicode-display_width
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
13
27
|
description: |2
|
|
14
28
|
|
|
15
29
|
|
|
@@ -29,6 +43,7 @@ files:
|
|
|
29
43
|
- lib/tui/format.rb
|
|
30
44
|
- lib/tui/layout.rb
|
|
31
45
|
- lib/tui/settings.rb
|
|
46
|
+
- lib/tui/tools.rb
|
|
32
47
|
homepage: https://github.com/skorobogatydmitry/tui
|
|
33
48
|
licenses:
|
|
34
49
|
- LGPL-3.0-only
|