rcalc 0.1.0 → 0.1.1
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/lib/rcalc/terminal.rb +77 -6
- data/lib/rcalc/version.rb +1 -1
- data/rcalc.gemspec +3 -0
- metadata +30 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0f0e64f85b5dd6a9127f9cc0b0ac727d3a8e25ea6349b2a9783b9cc3028eb8c4
|
|
4
|
+
data.tar.gz: 5307ef4f657bf83041efd1ede8445ff4a0cacc2378afb323113b9205702d1a39
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f268e9d5a5115ebb324033e195880497631cc4a818d104a79fddd0fea81b06e3118d5265c0dbb4934b41dcc564e02510bcd025cfac83ea571a0d737869577f03
|
|
7
|
+
data.tar.gz: e1963ec1a0d6a7101da77a4579424a7142ef5694cb36d34c613ab197b145719b0c93c07b275beb823b550b23a50c2c952d73d8bada1038d70fe9a9714c51c57b
|
data/lib/rcalc/terminal.rb
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
1
|
module Rcalc
|
|
2
|
+
##
|
|
3
|
+
# This class contains utilities related to terminal. Its initializer does not take any arguments.
|
|
4
|
+
#
|
|
4
5
|
class Terminal
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
##
|
|
7
|
+
# Performs a blocking console query. Used by other functions in this class
|
|
8
|
+
#
|
|
9
9
|
def blocking_console_query(query, listen_until)
|
|
10
10
|
# send query and block wait for response
|
|
11
11
|
res = ''
|
|
@@ -26,11 +26,28 @@ module Rcalc
|
|
|
26
26
|
res
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
+
##
|
|
30
|
+
# Gets the cursor position in the terminal. Returns two variables, x and y. Takes no arguments.
|
|
31
|
+
#
|
|
32
|
+
# @return [Integer, Integer] x and y, or column, row in that order.
|
|
33
|
+
#
|
|
34
|
+
# @example
|
|
35
|
+
# t = Rcalc::Terminal.new
|
|
36
|
+
# x, y = t.pos
|
|
37
|
+
#
|
|
29
38
|
def pos
|
|
30
39
|
m = blocking_console_query('6n', 'R').match(/(?<row>\d+);(?<column>\d+)/)
|
|
31
40
|
[Integer(m[:column]), Integer(m[:row])]
|
|
32
41
|
end
|
|
33
42
|
|
|
43
|
+
##
|
|
44
|
+
# Gets the size of the terminal in characters. Returns two variables, width and height. Takes no arguments.
|
|
45
|
+
#
|
|
46
|
+
# @return [Integer, Integer] width and height, or columns, rows in that order.
|
|
47
|
+
# @example
|
|
48
|
+
# t = Rcalc::Terminal.new
|
|
49
|
+
# w, h = t.size
|
|
50
|
+
#
|
|
34
51
|
def size
|
|
35
52
|
# get current position
|
|
36
53
|
x, y = pos
|
|
@@ -47,10 +64,16 @@ module Rcalc
|
|
|
47
64
|
[tx, ty]
|
|
48
65
|
end
|
|
49
66
|
|
|
67
|
+
##
|
|
68
|
+
# Function to get the CSI sequence. Used by other functions in the class
|
|
69
|
+
#
|
|
50
70
|
def esc
|
|
51
71
|
"\e["
|
|
52
72
|
end
|
|
53
73
|
|
|
74
|
+
##
|
|
75
|
+
# Function to print the CSI sequence followed by some command. Used by other functions in the class
|
|
76
|
+
#
|
|
54
77
|
def e!(command)
|
|
55
78
|
print "#{esc}#{command}"
|
|
56
79
|
end
|
|
@@ -71,10 +94,24 @@ module Rcalc
|
|
|
71
94
|
end
|
|
72
95
|
end
|
|
73
96
|
|
|
97
|
+
##
|
|
98
|
+
# Sets the current text color to a number
|
|
99
|
+
#
|
|
100
|
+
# @example set text color to red
|
|
101
|
+
# t = Rcalc::Terminal.new
|
|
102
|
+
# t.color!(Rcalc::TERMINAL_COLORS[:red])
|
|
103
|
+
#
|
|
74
104
|
def color!(id)
|
|
75
105
|
e! "38;5;#{id}m"
|
|
76
106
|
end
|
|
77
107
|
|
|
108
|
+
##
|
|
109
|
+
# Sets the current background color to a number
|
|
110
|
+
#
|
|
111
|
+
# @example set background color to red
|
|
112
|
+
# t = Rcalc::Terminal.new
|
|
113
|
+
# t.bgcolor!(Rcalc::TERMINAL_COLORS[:red])
|
|
114
|
+
#
|
|
78
115
|
def bgcolor!(id)
|
|
79
116
|
e! "48;5;#{id}m"
|
|
80
117
|
end
|
|
@@ -89,10 +126,35 @@ module Rcalc
|
|
|
89
126
|
end
|
|
90
127
|
end
|
|
91
128
|
|
|
129
|
+
##
|
|
130
|
+
# Sets the current text color to a RGB value
|
|
131
|
+
#
|
|
132
|
+
# @example set text color to red
|
|
133
|
+
# t = Rcalc::Terminal.new
|
|
134
|
+
# t.rgb!(255,0,0)
|
|
135
|
+
#
|
|
92
136
|
def rgb!(r, g, b)
|
|
93
137
|
e! "38;2;#{r};#{g};#{b}m"
|
|
94
138
|
end
|
|
95
139
|
|
|
140
|
+
##
|
|
141
|
+
# Sets the current background color to a RGB value
|
|
142
|
+
#
|
|
143
|
+
# @example set background color to red
|
|
144
|
+
# t = Rcalc::Terminal.new
|
|
145
|
+
# t.bgrgb!(255,0,0)
|
|
146
|
+
#
|
|
147
|
+
def bgrgb!(r, g, b)
|
|
148
|
+
e! "48;2;#{r};#{g};#{b}m"
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
##
|
|
152
|
+
# Sets cursor position
|
|
153
|
+
#
|
|
154
|
+
# @example set cursor to 10,10
|
|
155
|
+
# t = Rcalc::Terminal.new
|
|
156
|
+
# t.goto!(10, 10)
|
|
157
|
+
#
|
|
96
158
|
def goto!(x, y)
|
|
97
159
|
e! "#{y};#{x}f"
|
|
98
160
|
end
|
|
@@ -130,6 +192,15 @@ module Rcalc
|
|
|
130
192
|
res
|
|
131
193
|
end
|
|
132
194
|
|
|
195
|
+
##
|
|
196
|
+
# Listen for keypresses on the terminal
|
|
197
|
+
#
|
|
198
|
+
# @example
|
|
199
|
+
# t = Rcalc::Terminal.new
|
|
200
|
+
# t.listen! do |key|
|
|
201
|
+
# print key
|
|
202
|
+
# end
|
|
203
|
+
#
|
|
133
204
|
def listen!(&block)
|
|
134
205
|
$stdin.raw do |stdin|
|
|
135
206
|
collect = ''
|
data/lib/rcalc/version.rb
CHANGED
data/rcalc.gemspec
CHANGED
|
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
|
|
|
19
19
|
spec.metadata['homepage_uri'] = spec.homepage
|
|
20
20
|
spec.metadata['source_code_uri'] = 'https://github.com/davidsiaw/rcalc'
|
|
21
21
|
spec.metadata['changelog_uri'] = 'https://github.com/davidsiaw/rcalc'
|
|
22
|
+
spec.metadata['documentation_uri'] = 'https://rcalc.davidsiaw.net/'
|
|
22
23
|
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
23
24
|
|
|
24
25
|
spec.files = Dir['{exe,data,lib}/**/*'] + %w[Gemfile rcalc.gemspec]
|
|
@@ -31,4 +32,6 @@ Gem::Specification.new do |spec|
|
|
|
31
32
|
spec.add_development_dependency 'rubocop'
|
|
32
33
|
spec.add_development_dependency 'rubocop-rake'
|
|
33
34
|
spec.add_development_dependency 'rubocop-rspec'
|
|
35
|
+
spec.add_development_dependency 'webrick'
|
|
36
|
+
spec.add_development_dependency 'yard'
|
|
34
37
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rcalc
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- David Siaw
|
|
@@ -80,6 +80,34 @@ dependencies:
|
|
|
80
80
|
- - ">="
|
|
81
81
|
- !ruby/object:Gem::Version
|
|
82
82
|
version: '0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: webrick
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ">="
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: yard
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - ">="
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '0'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - ">="
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '0'
|
|
83
111
|
description: Terminal tools for interactive calculations
|
|
84
112
|
email:
|
|
85
113
|
- 874280+davidsiaw@users.noreply.github.com
|
|
@@ -105,6 +133,7 @@ metadata:
|
|
|
105
133
|
homepage_uri: https://github.com/davidsiaw/rcalc
|
|
106
134
|
source_code_uri: https://github.com/davidsiaw/rcalc
|
|
107
135
|
changelog_uri: https://github.com/davidsiaw/rcalc
|
|
136
|
+
documentation_uri: https://rcalc.davidsiaw.net/
|
|
108
137
|
rubygems_mfa_required: 'true'
|
|
109
138
|
post_install_message:
|
|
110
139
|
rdoc_options: []
|