vt100 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +19 -0
- data/LICENSE.txt +21 -0
- data/README.md +5 -0
- data/Rakefile +4 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/vt100.rb +12 -0
- data/lib/vt100/cursor.rb +25 -0
- data/lib/vt100/display_attributes.rb +85 -0
- data/lib/vt100/erase.rb +37 -0
- data/lib/vt100/terminal.rb +19 -0
- data/lib/vt100/version.rb +5 -0
- data/vt100.gemspec +22 -0
- metadata +59 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fd7d70e5b27ff7caee4f4d93fd17cf100a0824f6df98a04d227e3f800cce4700
|
4
|
+
data.tar.gz: 18c17b2738affdab4923ca429635208addfdbecc050bb5492724a97521d7e9d0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e9af039308e729368069ef831f147276bf4e9a354232192d400e041db9ebbec46f72ed0643b2642b2f6974903166c8a8945875fc17a4eeb97193a30780b9e754
|
7
|
+
data.tar.gz: 160bd91dfbe1f56f4b3540d66b57dc217653e40510e13f62f682315ed68546c2a4b1fcd3d097aaeb94338139eb9cdf000d8b66558e8a2d3ecacf2fb452eb2baa
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Benjamin Nguyen
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "vt100"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/vt100.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "vt100/version"
|
4
|
+
require_relative "vt100/display_attributes"
|
5
|
+
require_relative "vt100/erase"
|
6
|
+
require_relative "vt100/cursor"
|
7
|
+
require_relative "vt100/terminal"
|
8
|
+
|
9
|
+
module Vt100
|
10
|
+
include DisplayAttributes
|
11
|
+
class Error < StandardError; end
|
12
|
+
end
|
data/lib/vt100/cursor.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Vt100
|
4
|
+
module Cursor
|
5
|
+
def cursor_up(n)
|
6
|
+
print "\x1B[#{n}A"
|
7
|
+
end
|
8
|
+
|
9
|
+
def cursor_down(n)
|
10
|
+
print "\x1B[#{n}B"
|
11
|
+
end
|
12
|
+
|
13
|
+
def cursor_forward(n)
|
14
|
+
print "\x1B[#{n}C"
|
15
|
+
end
|
16
|
+
|
17
|
+
def cursor_backward(n)
|
18
|
+
print "\x1B[#{n}D"
|
19
|
+
end
|
20
|
+
|
21
|
+
def cursor_home
|
22
|
+
print "\x1B[H"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Vt100
|
4
|
+
module DisplayAttributes
|
5
|
+
def display_attr_esc(attr, txt)
|
6
|
+
"\x1B[#{attr}m#{txt}\x1B[0m"
|
7
|
+
end
|
8
|
+
|
9
|
+
def bright(txt)
|
10
|
+
display_attr_esc 1, txt
|
11
|
+
end
|
12
|
+
|
13
|
+
def underscore(txt)
|
14
|
+
display_attr_esc 4, txt
|
15
|
+
end
|
16
|
+
|
17
|
+
def hidden(txt)
|
18
|
+
display_attr_esc 8, txt
|
19
|
+
end
|
20
|
+
|
21
|
+
def fg_black(txt)
|
22
|
+
display_attr_esc 30, txt
|
23
|
+
end
|
24
|
+
|
25
|
+
def fg_red(txt)
|
26
|
+
display_attr_esc 31, txt
|
27
|
+
end
|
28
|
+
|
29
|
+
def fg_green(txt)
|
30
|
+
display_attr_esc 32, txt
|
31
|
+
end
|
32
|
+
|
33
|
+
def fg_yellow(txt)
|
34
|
+
display_attr_esc 33, txt
|
35
|
+
end
|
36
|
+
|
37
|
+
def fg_blue(txt)
|
38
|
+
display_attr_esc 34, txt
|
39
|
+
end
|
40
|
+
|
41
|
+
def fg_magenta(txt)
|
42
|
+
display_attr_esc 35, txt
|
43
|
+
end
|
44
|
+
|
45
|
+
def fg_cyan(txt)
|
46
|
+
display_attr_esc 36, txt
|
47
|
+
end
|
48
|
+
|
49
|
+
def fg_white(txt)
|
50
|
+
display_attr_esc 37, txt
|
51
|
+
end
|
52
|
+
|
53
|
+
def bg_black(txt)
|
54
|
+
display_attr_esc 40, txt
|
55
|
+
end
|
56
|
+
|
57
|
+
def bg_red(txt)
|
58
|
+
display_attr_esc 41, txt
|
59
|
+
end
|
60
|
+
|
61
|
+
def bg_green(txt)
|
62
|
+
display_attr_esc 42, txt
|
63
|
+
end
|
64
|
+
|
65
|
+
def bg_yellow(txt)
|
66
|
+
display_attr_esc 43, txt
|
67
|
+
end
|
68
|
+
|
69
|
+
def bg_blue(txt)
|
70
|
+
display_attr_esc 44, txt
|
71
|
+
end
|
72
|
+
|
73
|
+
def bg_magenta(txt)
|
74
|
+
display_attr_esc 45, txt
|
75
|
+
end
|
76
|
+
|
77
|
+
def bg_cyan(txt)
|
78
|
+
display_attr_esc 46, txt
|
79
|
+
end
|
80
|
+
|
81
|
+
def bg_white(txt)
|
82
|
+
display_attr_esc 47, txt
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
data/lib/vt100/erase.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Vt100
|
4
|
+
module Erase
|
5
|
+
def erase_line_esc(attr)
|
6
|
+
"\x1B[#{attr}K"
|
7
|
+
end
|
8
|
+
|
9
|
+
def erase_screen_esc(attr)
|
10
|
+
"\x1B[#{attr}J"
|
11
|
+
end
|
12
|
+
|
13
|
+
def erase_end_of_line
|
14
|
+
print erase_line_esc ""
|
15
|
+
end
|
16
|
+
|
17
|
+
def erase_start_of_line
|
18
|
+
print erase_line_esc 1
|
19
|
+
end
|
20
|
+
|
21
|
+
def erase_line
|
22
|
+
print erase_line_esc 2
|
23
|
+
end
|
24
|
+
|
25
|
+
def erase_down
|
26
|
+
print erase_screen_esc ""
|
27
|
+
end
|
28
|
+
|
29
|
+
def erase_up
|
30
|
+
print erase_sceen_esc 1
|
31
|
+
end
|
32
|
+
|
33
|
+
def erase_screen
|
34
|
+
print erase_screen_esc 2
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "io/console"
|
4
|
+
|
5
|
+
module Vt100
|
6
|
+
module Terminal
|
7
|
+
def terminal_dimensions
|
8
|
+
$stdout.winsize
|
9
|
+
end
|
10
|
+
|
11
|
+
def unbuffer_stdin
|
12
|
+
system "stty", "-f", "/dev/tty", "cbreak", "min", "1"
|
13
|
+
end
|
14
|
+
|
15
|
+
def unecho_stdin
|
16
|
+
system "stty", "-f", "/dev/tty", "-echo"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/vt100.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/vt100/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "vt100"
|
7
|
+
spec.version = Vt100::VERSION
|
8
|
+
spec.authors = ["Benjamin Nguyen"]
|
9
|
+
spec.email = ["benjamin.van.nguyen@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "ANSI escape sequences to control the terminal's font, color, and cusor with ease."
|
12
|
+
spec.homepage = "https://github.com/solidiquis/vt100"
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
15
|
+
|
16
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
17
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vt100
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Benjamin Nguyen
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-03-21 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- benjamin.van.nguyen@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- Gemfile
|
22
|
+
- Gemfile.lock
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- bin/console
|
27
|
+
- bin/setup
|
28
|
+
- lib/vt100.rb
|
29
|
+
- lib/vt100/cursor.rb
|
30
|
+
- lib/vt100/display_attributes.rb
|
31
|
+
- lib/vt100/erase.rb
|
32
|
+
- lib/vt100/terminal.rb
|
33
|
+
- lib/vt100/version.rb
|
34
|
+
- vt100.gemspec
|
35
|
+
homepage: https://github.com/solidiquis/vt100
|
36
|
+
licenses:
|
37
|
+
- MIT
|
38
|
+
metadata: {}
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.4.0
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubygems_version: 3.0.8
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: ANSI escape sequences to control the terminal's font, color, and cusor with
|
58
|
+
ease.
|
59
|
+
test_files: []
|