arTTY 0.9.48

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,212 @@
1
+ # encoding: utf-8
2
+
3
+ require "hilighter"
4
+ require "pathname"
5
+ require "scoobydoo"
6
+
7
+ class ArTTY::SystemInfo
8
+ def cpu
9
+ if (Pathname.new("/proc/cpuinfo").exist?)
10
+ File.read("/proc/cpuinfo").each_line do |line|
11
+ line.match(/name\s+:\s+(.+)/) do |m|
12
+ out = m[1].gsub(/\((R|TM)\)| (@|CPU)/, "")
13
+ return out.gsub(/\s+/, " ").strip
14
+ end
15
+ end
16
+ end
17
+ return ""
18
+ end
19
+
20
+ def fields(fields)
21
+ @fields = fields
22
+ refresh
23
+ end
24
+
25
+ def fs_usage(fs = "/")
26
+ return "" if (ScoobyDoo.where_are_you("df").nil?)
27
+
28
+ df = %x(df -h #{fs} | tail -n 1)
29
+ df.match(/^\S+\s+(\S+)\s+(\S+)\s+\S+\s+(\S+)/) do |m|
30
+ return "#{m[2]} / #{m[1]} (#{m[3]})".strip
31
+ end
32
+
33
+ return ""
34
+ end
35
+
36
+ def height
37
+ return @info.keys.length
38
+ end
39
+
40
+ def hostname
41
+ return "" if (ScoobyDoo.where_are_you("hostname").nil?)
42
+ return %x(hostname).split(".")[0].strip
43
+ end
44
+
45
+ def info
46
+ info = Array.new
47
+
48
+ fillto = @info.keys.map(&:length).max
49
+ @info.each do |k, v|
50
+ if (k.empty?)
51
+ info.push("")
52
+ info.push(v)
53
+ else
54
+ lfill = " " * (fillto - k.length)
55
+ info.push("#{lfill}#{k.blue}: #{v.light_blue}")
56
+ end
57
+ end
58
+
59
+ return info
60
+ end
61
+
62
+ def initialize(fields = nil)
63
+ @info = Hash.new
64
+ @fields = fields
65
+ if (fields.nil? || fields.empty?)
66
+ @fields = [
67
+ "hostname",
68
+ "os",
69
+ "kernel",
70
+ "uptime",
71
+ "ip",
72
+ "shell",
73
+ "tty",
74
+ "cpu",
75
+ "ram",
76
+ "fs",
77
+ "colors"
78
+ ]
79
+ end
80
+ refresh
81
+ end
82
+
83
+ def ipv4
84
+ return "" if (ScoobyDoo.where_are_you("ip").nil?)
85
+ %x(ip r).match(/^default.+dev\s+(\S+)/) do |dev|
86
+ %x(ip -o a s #{dev[1]}).match(/\s+inet\s+(\S+)/) do |ip|
87
+ return ip[1].strip
88
+ end
89
+ end
90
+ return ""
91
+ end
92
+
93
+ def ipv6
94
+ return "" if (ScoobyDoo.where_are_you("ip").nil?)
95
+ %x(ip r).match(/^default.+dev\s+(\S+)/) do |dev|
96
+ %x(ip -o a s #{dev[1]}).match(
97
+ /\s+inet6\s+((?!fe[89ab])\S+)/i
98
+ ) do |ip|
99
+ return ip[1].strip
100
+ end
101
+ end
102
+ return ""
103
+ end
104
+
105
+ def kernel
106
+ return "" if (ScoobyDoo.where_are_you("uname").nil?)
107
+ return %x(uname -r).strip
108
+ end
109
+
110
+ def os
111
+ return "" if (ScoobyDoo.where_are_you("uname").nil?)
112
+
113
+ os = Pathname.new("/etc/os-release").expand_path
114
+ if (os.exist?)
115
+ File.read(os).each_line do |line|
116
+ line.match(/^PRETTY_NAME="(.+)"/) do |m|
117
+ return "#{m[1].strip} #{%x(uname -m).strip}"
118
+ end
119
+ end
120
+ end
121
+
122
+ return "#{%x(uname -s).strip} #{%x(uname -m).strip}"
123
+ end
124
+
125
+ def ram
126
+ return "" if (ScoobyDoo.where_are_you("free").nil?)
127
+
128
+ %x(free -m).match(/Mem:\s+(\d+)\s+(\d+)/) do |m|
129
+ return "#{m[2]} MB / #{m[1]} MB".strip
130
+ end
131
+
132
+ return ""
133
+ end
134
+
135
+ def refresh
136
+ @info.clear
137
+ @fields.each do |field|
138
+ case field
139
+ when /^colors$/i
140
+ @info[""] = [
141
+ "▄▄▄".light_black.on_black,
142
+ "▄▄▄".light_red.on_red,
143
+ "▄▄▄".light_green.on_green,
144
+ "▄▄▄".light_yellow.on_yellow,
145
+ "▄▄▄".light_blue.on_blue,
146
+ "▄▄▄".light_magenta.on_magenta,
147
+ "▄▄▄".light_cyan.on_cyan,
148
+ "▄▄▄".light_white.on_white
149
+ ].join
150
+ when /^cpu$/i
151
+ @info["CPU"] = cpu
152
+ when /^fs$/i
153
+ rootfs = fs_usage
154
+ homefs = fs_usage(ENV["HOME"])
155
+ @info["RootFS"] = rootfs
156
+ @info["HomeFS"] = homefs if (homefs != rootfs)
157
+ when /^host(name)?$/i
158
+ @info["Host"] = hostname
159
+ when /^ip$/i
160
+ @info["IPv4"] = ipv4
161
+ @info["IPv6"] = ipv6
162
+ when /^ipv4$/i
163
+ @info["IPv4"] = ipv4
164
+ when /^ipv6$/i
165
+ @info["IPv6"] = ipv6
166
+ when /^kernel$/i
167
+ @info["Kernel"] = kernel
168
+ when /^os$/i
169
+ @info["OS"] = os
170
+ when /^ram$/i
171
+ @info["RAM"] = ram
172
+ when /^shell$/i
173
+ @info["Shell"] = shell
174
+ when /^tty$/i
175
+ @info["TTY"] = tty
176
+ when /^uptime$/i
177
+ @info["Uptime"] = uptime
178
+ end
179
+ end
180
+ @info.delete_if do |k, v|
181
+ v.empty?
182
+ end
183
+ end
184
+
185
+ def shell
186
+ return "" if (ENV["SHELL"].nil?)
187
+ return ENV["SHELL"].strip
188
+ end
189
+
190
+ def tty
191
+ return "" if (ScoobyDoo.where_are_you("tty").nil?)
192
+ return %x(tty 2>/dev/null).strip
193
+ end
194
+
195
+ def uptime
196
+ return "" if (ScoobyDoo.where_are_you("uptime").nil?)
197
+
198
+ up = %x(uptime).gsub(/^.+up\s+|,\s+\d+\s+user.+$/, "").strip
199
+ up.gsub!(/(days?)\s+/, "\\1, ")
200
+ up.gsub!(/0?(\d+):0?(\d+)/, "\\1 hour, \\2 min")
201
+ up.gsub!(/(0 hour, |, 0 min)/, "")
202
+ up.gsub!(/((\d\d+|[2-9]) (hour|min))/, "\\1s")
203
+ return up.gsub(/\s+/, " ").strip
204
+ end
205
+
206
+ def width
207
+ return 0 if (@info.empty?)
208
+ k = @info.keys.map(&:plain).map(&:length).max
209
+ v = @info.values.map(&:plain).map(&:length).max
210
+ return k + v + 2
211
+ end
212
+ end
metadata ADDED
@@ -0,0 +1,198 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: arTTY
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.48
5
+ platform: ruby
6
+ authors:
7
+ - Miles Whittaker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-02-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.12'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 5.13.0
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '5.12'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 5.13.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: rake
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '13.0'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 13.0.1
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '13.0'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 13.0.1
53
+ - !ruby/object:Gem::Dependency
54
+ name: hilighter
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '1.5'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 1.5.9
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.5'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 1.5.9
73
+ - !ruby/object:Gem::Dependency
74
+ name: jsoncfg
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '1.2'
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 1.2.11
83
+ type: :runtime
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.2'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 1.2.11
93
+ - !ruby/object:Gem::Dependency
94
+ name: minitar
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '0.9'
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 0.9.0
103
+ type: :runtime
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '0.9'
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: 0.9.0
113
+ - !ruby/object:Gem::Dependency
114
+ name: scoobydoo
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: '1.0'
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: 1.0.1
123
+ type: :runtime
124
+ prerelease: false
125
+ version_requirements: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: '1.0'
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: 1.0.1
133
+ - !ruby/object:Gem::Dependency
134
+ name: typhoeus
135
+ requirement: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '1.3'
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: 1.3.1
143
+ type: :runtime
144
+ prerelease: false
145
+ version_requirements: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - "~>"
148
+ - !ruby/object:Gem::Version
149
+ version: '1.3'
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: 1.3.1
153
+ description: This gem will display art and some system information.
154
+ email: mj@whitta.dev
155
+ executables:
156
+ - arTTY
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - bin/arTTY
161
+ - lib/arTTY.rb
162
+ - lib/arTTY/art.rb
163
+ - lib/arTTY/cache.rb
164
+ - lib/arTTY/error.rb
165
+ - lib/arTTY/error/art_not_found.rb
166
+ - lib/arTTY/error/failed_to_download.rb
167
+ - lib/arTTY/error/image_magick_not_found.rb
168
+ - lib/arTTY/error/image_named_improperly.rb
169
+ - lib/arTTY/error/image_not_found.rb
170
+ - lib/arTTY/error/no_pixel_data_found.rb
171
+ - lib/arTTY/generator.rb
172
+ - lib/arTTY/system_info.rb
173
+ homepage: https://gitlab.com/mjwhitta/artty/tree/ruby
174
+ licenses:
175
+ - GPL-3.0
176
+ metadata:
177
+ source_code_uri: https://gitlab.com/mjwhitta/artty/tree/ruby
178
+ post_install_message:
179
+ rdoc_options: []
180
+ require_paths:
181
+ - lib
182
+ required_ruby_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ required_rubygems_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ requirements: []
193
+ rubyforge_project:
194
+ rubygems_version: 2.5.2.1
195
+ signing_key:
196
+ specification_version: 4
197
+ summary: Art for your TTY.
198
+ test_files: []