clite 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/clite +4 -0
- data/lib/clite.rb +50 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8e6b93a6b6886a9730e6950e814438cf48139a82
|
4
|
+
data.tar.gz: cdd36af9cad9a08b01d8121e1b23cf1eef740784
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3c693d394b78de89de2dd569c4dce6428214a98fcaaed085f3980507e776723ec33be4ca5c3bb9200984d6ad0b9fec09746cd36694f22a064559f845937352d9
|
7
|
+
data.tar.gz: 9037a0e5ddd78c9ea36bbcec9cbd0a1c8beb823ba148a4ff682caa8b261eb6487b4f9eaef4c41eb678918f58a54a3db196b3be0e255528c57b39a32be1baed20
|
data/bin/clite
ADDED
data/lib/clite.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
class Clite
|
2
|
+
require 'io/console'
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@screen = Screen.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def run
|
9
|
+
@screen.update
|
10
|
+
|
11
|
+
loop do
|
12
|
+
char = STDIN.getch
|
13
|
+
@screen.update char
|
14
|
+
break if char == ?q
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class Screen
|
19
|
+
def initialize
|
20
|
+
rows_size, columns_size = STDIN.winsize
|
21
|
+
@rows = Array.new(rows_size) { String.new capacity: columns_size }
|
22
|
+
|
23
|
+
@rows[1] = '-' * columns_size
|
24
|
+
@rows[3] = '-' * columns_size
|
25
|
+
end
|
26
|
+
|
27
|
+
def update state = ''
|
28
|
+
char = state
|
29
|
+
update_line_with char
|
30
|
+
render_rows
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
def update_line_with char
|
35
|
+
line = @rows[2]
|
36
|
+
line.clear
|
37
|
+
line << char
|
38
|
+
end
|
39
|
+
|
40
|
+
def render_rows
|
41
|
+
escape '2J' # clear screen
|
42
|
+
escape '1;1H' # move to the top left corner
|
43
|
+
print @rows.join "\r\n"
|
44
|
+
end
|
45
|
+
|
46
|
+
def escape code
|
47
|
+
print "\e[#{code}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: clite
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Anatoly Chernow
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-11 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- bin/clite
|
20
|
+
- lib/clite.rb
|
21
|
+
homepage:
|
22
|
+
licenses: []
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.6.13
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: A lightweigth command-line interface.
|
44
|
+
test_files: []
|