bash-visual 1.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ *~
2
+ .gitignore
3
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bash-visual.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,14 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bash-visual (1.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+
10
+ PLATFORMS
11
+ ruby
12
+
13
+ DEPENDENCIES
14
+ bash-visual!
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Alexander Suslov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Bash::Visual
2
+
3
+ Bash visualisation tools
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'bash-visual'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install bash-visual
18
+
19
+ ## Usage
20
+
21
+ include Bash_Visual;
22
+ font = Font.new(Font::STD, Font::LIGHT_BLUE)
23
+ console = Console.new(font)
24
+ console.clear()
25
+ console.draw_window(2, 2, 20, 5, 'Example', font, Console::BORDER_UTF_DOUBLE)
26
+ console.write_to_position(5, 3, 'Hello World!', Font.new(Font::BOLD, Font::LIGHT_GREEN))
27
+ console.position = [0, 8]
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,16 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/bash-visual/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = 'bash-visual'
6
+ gem.author = 'Alexander Suslov'
7
+ gem.email = ['a.s.suslov@gmail.com']
8
+ gem.description = %q{Bash visualisation tools}
9
+ gem.summary = %q{Bash visualisation tools}
10
+ gem.homepage = 'https://github.com/AlmazKo/BashConsole'
11
+
12
+ gem.files = `git ls-files`.split($\)
13
+ gem.require_paths = ['lib']
14
+ gem.version = Bash_Visual::VERSION
15
+ gem.license = 'MIT'
16
+ end
@@ -0,0 +1,10 @@
1
+ # coding: utf-8
2
+ $:.unshift(File.dirname(__FILE__))
3
+
4
+ require "bash-visual/version"
5
+ require "bash-visual/console"
6
+ require "bash-visual/font"
7
+ require "bash-visual/scroll"
8
+ require "bash-visual/builder"
9
+ require "bash-visual/horizontal_scroll"
10
+ require "bash-visual/vertical_scroll"
@@ -0,0 +1,60 @@
1
+ module Bash_Visual
2
+ class Builder
3
+
4
+ def initialize (font = Font.new)
5
+ @default_font = font
6
+ end
7
+
8
+ def clear
9
+ set_position(0, 0) + "\e[2J"
10
+ end
11
+
12
+ def erase_to_end_line
13
+ "\e[K"
14
+ end
15
+
16
+ def restore_position
17
+ "\e[u"
18
+ end
19
+
20
+ def save_position
21
+ "\e[s"
22
+ end
23
+
24
+ def set_position (x, y)
25
+ "\e[#{y.to_i};#{x.to_i}H"
26
+ end
27
+
28
+ def move_position(offset_x, offset_y)
29
+ bash = ''
30
+ if (offset_y > 0)
31
+ bash << "\e[#{offset_y}B"
32
+ else
33
+ bash << "\e[#{offset_y.abs}A"
34
+ end
35
+ if (offset_x > 0)
36
+ bash << "\e[#{offset_x}C"
37
+ else
38
+ bash << "\e[#{offset_x.abs}D"
39
+ end
40
+ bash
41
+ end
42
+
43
+ def write_to_position (x, y, text, font = @default_font)
44
+ bash = ''
45
+ bash << save_position()
46
+ bash << move_position(x, y)
47
+ bash << write(text, font)
48
+ bash << restore_position()
49
+ bash
50
+ end
51
+
52
+ def write (text, font = @default_font)
53
+ font.to_bash + text + Font::RESET
54
+ end
55
+
56
+ def write_ln (text, font = @default_font)
57
+ font.to_bash + text << "\n" << Font::RESET
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,140 @@
1
+ module Bash_Visual
2
+ class Console
3
+ @@mutex = Mutex.new
4
+
5
+ OUTPUT_STRING = 0
6
+ OUTPUT_WITHOUT_BLOCK = 1
7
+ OUTPUT_WITH_BLOCK = 2
8
+ # see: http://en.wikipedia.org/wiki/Box-drawing_characters
9
+ BORDER_UTF = ["\u250C","\u2500","\u2510",
10
+ "\u2502", "\u2502",
11
+ "\u2514","\u2500","\u2518"]
12
+
13
+ BORDER_UTF_ROUND = ["\u256D","\u2500","\u256E",
14
+ "\u2502", "\u2502",
15
+ "\u2570","\u2500","\u256F"]
16
+
17
+ BORDER_UTF_DOUBLE = ["\u2554","\u2550","\u2557",
18
+ "\u2551", "\u2551",
19
+ "\u255A","\u2550","\u255D"]
20
+
21
+ attr_reader :current_x, :current_y, :font;
22
+
23
+ def initialize (font = Font.new, way_outnput = OUTPUT_WITHOUT_BLOCK, builder = Builder.new)
24
+ @current_x = 0
25
+ @current_y = 0
26
+ @font = font
27
+ @way_output = way_outnput
28
+ @builder = builder
29
+ end
30
+
31
+ def position= coord
32
+ @current_x , @current_y = *coord
33
+ print @builder.set_position(@current_x, @current_y)
34
+ end
35
+
36
+ def move_position(offset_x, offset_y)
37
+ @current_x += offset_x
38
+ @current_y += offset_y
39
+ print @builder.move_position(offset_x, offset_y)
40
+ end
41
+
42
+ # Записать что-то в определенной позиции, а потом вернуться на текущую
43
+ # Если необходимо сохранить позицию после записи - используйте связку
44
+ # move_position/position= и write
45
+ def write_to_position (x, y, text, font = @font)
46
+ print @builder.write_to_position(x, y, text, font)
47
+ end
48
+
49
+ def write (text, font = @font)
50
+ print @builder.write(text, font)
51
+ end
52
+
53
+ def write_ln (text, font = @font)
54
+ print @builder.write_ln(text, font)
55
+ end
56
+
57
+ def erase_to_end_line
58
+ print @builder.erase_to_end_line
59
+ end
60
+
61
+ def draw_rectangle(x, y, width, height, font = nil)
62
+ bash = ''
63
+ bash << @builder.save_position()
64
+ bash << @builder.set_position(x,y)
65
+ height.times do
66
+ bash << @builder.write(' ' * width, font)
67
+ bash << @builder.move_position(-width, 1)
68
+ end
69
+ bash << @builder.restore_position()
70
+ print @builder.write(bash, font)
71
+ end
72
+
73
+ def draw_border(x, y, width, height, font = nil, border = BORDER_UTF)
74
+ raise 'width,height must be great than 1' if (width < 2 or height < 2)
75
+
76
+ bash = ''
77
+ bash << @builder.save_position()
78
+ bash << @builder.set_position(x,y)
79
+
80
+ bash << @builder.write(border[0] + border[1] * (width - 2) + border[2], font)
81
+ (height - 2).times do
82
+ bash << @builder.move_position(-width, 1)
83
+ bash << @builder.write(border[3] + ' ' * (width - 2) + border[4], font)
84
+ end
85
+ bash << @builder.move_position(-width, 1)
86
+ bash << @builder.write(border[5] + border[6] * (width - 2) + border[7], font)
87
+
88
+ bash << @builder.restore_position()
89
+ print @builder.write(bash, font)
90
+ end
91
+
92
+ def draw_window(x, y, width, height, text = '', font = nil, border = BORDER_UTF_DOUBLE, text_wrap = ["\u2561","\u255E"])
93
+ raise 'width,height must be great than 2' if (width < 3 or height < 3)
94
+
95
+ text = text.slice(0, width - 2)
96
+ if text.size < (width - 3) && (text_wrap.instance_of? Array)
97
+ text = text_wrap[0] + text + text_wrap[1]
98
+ end
99
+ text = text.center(width - 2, border[1])
100
+ bash = ''
101
+ bash << @builder.save_position()
102
+ bash << @builder.set_position(x,y)
103
+
104
+ bash << @builder.write(border[0] + text + border[2], font)
105
+ (height - 2).times do
106
+ bash << @builder.move_position(-width, 1)
107
+ bash << @builder.write(border[3] + ' ' * (width - 2) + border[4], font)
108
+ end
109
+ bash << @builder.move_position(-width, 1)
110
+ bash << @builder.write(border[5] + border[6] * (width - 2) + border[7], font)
111
+
112
+ bash << @builder.restore_position()
113
+ print @builder.write(bash, font)
114
+ end
115
+
116
+ # Clear the screen and move to (0,0)
117
+ def clear
118
+ @current_x = 0
119
+ @current_y = 0
120
+ print @builder.clear
121
+ end
122
+
123
+ def font= font
124
+ @font = font
125
+ end
126
+
127
+ private
128
+ def print string
129
+
130
+ return string if OUTPUT_STRING == @way_output
131
+
132
+ if OUTPUT_WITH_BLOCK == @way_output
133
+ @@mutex.synchronize {super}
134
+ else
135
+ super
136
+ end
137
+ end
138
+
139
+ end
140
+ end
@@ -0,0 +1,92 @@
1
+ module Bash_Visual
2
+ class Font
3
+ BLACK = 0
4
+ RED = 1
5
+ GREEN = 2
6
+ BROWN = 3
7
+ BLUE = 4
8
+ MAGENTA = 5
9
+ CYAN = 6
10
+ LIGHT_GRAY = 7
11
+
12
+ GRAY = 10
13
+ LIGHT_RED = 11
14
+ LIGHT_GREEN = 12
15
+ YELLOW = 13
16
+ LIGHT_BLUE = 14
17
+ LIGHT_MAGENTA = 15
18
+ LIGHT_CYAN = 16
19
+ WHITE = 17
20
+
21
+ RESET = "\e[0m"
22
+
23
+ #types font
24
+ STD = 0
25
+ BOLD = 1
26
+ UNDERLINE = 2
27
+ BLINK = 4
28
+
29
+ attr_reader :font, :foreground, :background
30
+
31
+ def initialize (font = STD, foreground = WHITE, background = nil)
32
+ raise "not found color #{foreground}" unless (0..7).cover? foreground or (10..17).cover? foreground
33
+ @font, @foreground, @background = font, foreground, background
34
+
35
+ @bash_command = ''
36
+
37
+ @string = "<type=%s, foreground=%s, background=%s>" % [@font, @foreground, @background]
38
+ if font == STD
39
+ if foreground and foreground < 10
40
+ @bash_command << "\e[3#{foreground}m"
41
+ else
42
+ @bash_command << "\e[9#{foreground-10}m"
43
+ end
44
+ end
45
+
46
+ if font & BOLD != 0
47
+ if foreground < 10
48
+ @bash_command << "\e[1;3#{foreground}m"
49
+ else
50
+ @bash_command << "\e[1;9#{foreground-10}m"
51
+ end
52
+ end
53
+
54
+ if font & UNDERLINE != 0
55
+ if foreground < 10
56
+ @bash_command << "\e[4;3#{foreground}m"
57
+ else
58
+ @bash_command << "\e[4;9#{foreground-10}m"
59
+ end
60
+ end
61
+
62
+ if background.instance_of? Fixnum
63
+ if background < 10
64
+ @bash_command << "\e[4#{background}m"
65
+ else
66
+ @bash_command << "\e[10#{background-10}m"
67
+ end
68
+ end
69
+
70
+ end
71
+
72
+ def to_bash
73
+ @bash_command
74
+ end
75
+
76
+ def to_s
77
+ @string
78
+ end
79
+
80
+ class << self
81
+ def rand_color (exclude_color = nil)
82
+ color = rand(14)
83
+ color += 1 if color == exclude_color
84
+ color = 0 if color > 14
85
+ color += 3 if color > 7
86
+ color
87
+ end
88
+ end
89
+
90
+
91
+ end
92
+ end
File without changes
@@ -0,0 +1,3 @@
1
+ module Bash_Visual
2
+ VERSION = '1.0.1'
3
+ end
metadata CHANGED
@@ -1,62 +1,61 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: bash-visual
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
4
5
  prerelease:
5
- version: "1.0"
6
6
  platform: ruby
7
- authors:
8
- - Almazko
7
+ authors:
8
+ - Alexander Suslov
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-12-25 00:00:00 Z
12
+ date: 2012-04-26 00:00:00.000000000 Z
14
13
  dependencies: []
15
-
16
- description:
17
- email: a.s.suslov@gmail.com
14
+ description: Bash visualisation tools
15
+ email:
16
+ - a.s.suslov@gmail.com
18
17
  executables: []
19
-
20
18
  extensions: []
21
-
22
19
  extra_rdoc_files: []
23
-
24
- files:
25
- - ./lib/scroll.rb
26
- - ./lib/example1.rb
27
- - ./lib/vertical_scroll.rb
28
- - ./lib/main.rb
29
- - ./lib/horizontal_scroll.rb
30
- - ./lib/common/random_text.rb
31
- - ./lib/bash/builder.rb
32
- - ./lib/bash/console.rb
33
- - ./lib/bash/font.rb
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - Gemfile.lock
24
+ - LICENSE
25
+ - README.md
26
+ - Rakefile
27
+ - bash-visual.gemspec
28
+ - lib/bash-visual.rb
29
+ - lib/bash-visual/builder.rb
30
+ - lib/bash-visual/console.rb
31
+ - lib/bash-visual/font.rb
32
+ - lib/bash-visual/horizontal_scroll.rb
33
+ - lib/bash-visual/scroll.rb
34
+ - lib/bash-visual/version.rb
35
+ - lib/bash-visual/vertical_scroll.rb
34
36
  homepage: https://github.com/AlmazKo/BashConsole
35
- licenses:
37
+ licenses:
36
38
  - MIT
37
39
  post_install_message:
38
40
  rdoc_options: []
39
-
40
- require_paths:
41
+ require_paths:
41
42
  - lib
42
- required_ruby_version: !ruby/object:Gem::Requirement
43
+ required_ruby_version: !ruby/object:Gem::Requirement
43
44
  none: false
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: "0"
48
- required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
50
  none: false
50
- requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- version: "0"
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
54
55
  requirements: []
55
-
56
56
  rubyforge_project:
57
57
  rubygems_version: 1.8.11
58
58
  signing_key:
59
59
  specification_version: 3
60
- summary: Bash visualization tools.
60
+ summary: Bash visualisation tools
61
61
  test_files: []
62
-
data/lib/bash/builder.rb DELETED
@@ -1,60 +0,0 @@
1
- require 'font'
2
-
3
- class Builder
4
-
5
- def initialize (font = Font.new)
6
- @default_font = font
7
- end
8
-
9
- def clear
10
- set_position(0, 0) + "\e[2J"
11
- end
12
-
13
- def erase_to_end_line
14
- "\e[K"
15
- end
16
-
17
- def restore_position
18
- "\e[u"
19
- end
20
-
21
- def save_position
22
- "\e[s"
23
- end
24
-
25
- def set_position (x, y)
26
- "\e[#{y.to_i};#{x.to_i}H"
27
- end
28
-
29
- def move_position(offset_x, offset_y)
30
- bash = ''
31
- if (offset_y > 0)
32
- bash << "\e[#{offset_y}B"
33
- else
34
- bash << "\e[#{offset_y.abs}A"
35
- end
36
- if (offset_x > 0)
37
- bash << "\e[#{offset_x}C"
38
- else
39
- bash << "\e[#{offset_x.abs}D"
40
- end
41
- bash
42
- end
43
-
44
- def write_to_position (x, y, text, font = @default_font)
45
- bash = ''
46
- bash << save_position()
47
- bash << move_position(x, y)
48
- bash << write(text, font)
49
- bash << restore_position()
50
- bash
51
- end
52
-
53
- def write (text, font = @default_font)
54
- font.to_bash + text + Font::RESET
55
- end
56
-
57
- def write_ln (text, font = @default_font)
58
- font.to_bash + text << "\n" << Font::RESET
59
- end
60
- end
data/lib/bash/console.rb DELETED
@@ -1,143 +0,0 @@
1
- # coding: utf-8
2
- $:.unshift(File.dirname(__FILE__))
3
- require 'font'
4
- require 'builder'
5
-
6
- class Console
7
- @@mutex = Mutex.new
8
-
9
- OUTPUT_STRING = 0
10
- OUTPUT_WITHOUT_BLOCK = 1
11
- OUPUT_WITH_BLOCK = 2
12
- # see: http://en.wikipedia.org/wiki/Box-drawing_characters
13
- BORDER_UTF = ["\u250C","\u2500","\u2510",
14
- "\u2502", "\u2502",
15
- "\u2514","\u2500","\u2518"]
16
-
17
- BORDER_UTF_ROUND = ["\u256D","\u2500","\u256E",
18
- "\u2502", "\u2502",
19
- "\u2570","\u2500","\u256F"]
20
-
21
- BORDER_UTF_DOUBLE = ["\u2554","\u2550","\u2557",
22
- "\u2551", "\u2551",
23
- "\u255A","\u2550","\u255D"]
24
-
25
- attr_reader :current_x, :current_y, :font;
26
-
27
- def initialize (font = Font.new, way_outnput = OUTPUT_WITHOUT_BLOCK, builder = Builder.new)
28
- @current_x = 0
29
- @current_y = 0
30
- @font = font
31
- @way_output = way_outnput
32
- @builder = builder
33
- end
34
-
35
- def position= coord
36
- @current_x , @current_y = *coord
37
- print @builder.set_position(@current_x, @current_y)
38
- end
39
-
40
- def move_position(offset_x, offset_y)
41
- @current_x += offset_x
42
- @current_y += offset_y
43
- print @builder.move_position(offset_x, offset_y)
44
- end
45
-
46
- # Записать что-то в определенной позиции, а потом вернуться на текущую
47
- # Если необходимо сохранить позицию после записи - используйте связку
48
- # move_position/position= и write
49
- def write_to_position (x, y, text, font = @font)
50
- print @builder.write_to_position(x, y, text, font)
51
- end
52
-
53
- def write (text, font = @font)
54
- print @builder.write(text, font)
55
- end
56
-
57
- def write_ln (text, font = @font)
58
- print @builder.write_ln(text, font)
59
- end
60
-
61
- def erase_to_end_line
62
- print @builder.erase_to_end_line
63
- end
64
-
65
- def draw_rectangle(x, y, width, height, font = nil)
66
- bash = ''
67
- bash << @builder.save_position()
68
- bash << @builder.set_position(x,y)
69
- height.times do
70
- bash << @builder.write(' ' * width, font)
71
- bash << @builder.move_position(-width, 1)
72
- end
73
- bash << @builder.restore_position()
74
- print @builder.write(bash, font)
75
- end
76
-
77
- def draw_border(x, y, width, height, font = nil, border = BORDER_UTF)
78
- raise 'width,height must be great than 1' if (width < 2 or height < 2)
79
-
80
- bash = ''
81
- bash << @builder.save_position()
82
- bash << @builder.set_position(x,y)
83
-
84
- bash << @builder.write(border[0] + border[1] * (width - 2) + border[2], font)
85
- (height - 2).times do
86
- bash << @builder.move_position(-width, 1)
87
- bash << @builder.write(border[3] + ' ' * (width - 2) + border[4], font)
88
- end
89
- bash << @builder.move_position(-width, 1)
90
- bash << @builder.write(border[5] + border[6] * (width - 2) + border[7], font)
91
-
92
- bash << @builder.restore_position()
93
- print @builder.write(bash, font)
94
- end
95
-
96
- def draw_window(x, y, width, height, text = '', font = nil, border = BORDER_UTF_DOUBLE, text_wrap = ["\u2561","\u255E"])
97
- raise 'width,height must be great than 2' if (width < 3 or height < 3)
98
-
99
- text = text.slice(0, width - 2)
100
- if text.size < (width - 3) && (text_wrap.instance_of? Array)
101
- text = text_wrap[0] + text + text_wrap[1]
102
- end
103
- text = text.center(width - 2, border[1])
104
- bash = ''
105
- bash << @builder.save_position()
106
- bash << @builder.set_position(x,y)
107
-
108
- bash << @builder.write(border[0] + text + border[2], font)
109
- (height - 2).times do
110
- bash << @builder.move_position(-width, 1)
111
- bash << @builder.write(border[3] + ' ' * (width - 2) + border[4], font)
112
- end
113
- bash << @builder.move_position(-width, 1)
114
- bash << @builder.write(border[5] + border[6] * (width - 2) + border[7], font)
115
-
116
- bash << @builder.restore_position()
117
- print @builder.write(bash, font)
118
- end
119
-
120
- # Clear the screen and move to (0,0)
121
- def clear
122
- @current_x = 0
123
- @current_y = 0
124
- print @builder.clear
125
- end
126
-
127
- def font= font
128
- @font = font
129
- end
130
-
131
- private
132
- def print string
133
-
134
- return string if OUTPUT_STRING == @way_output
135
-
136
- if OUPUT_WITH_BLOCK == @way_output
137
- @@mutex.synchronize {super}
138
- else
139
- super
140
- end
141
- end
142
-
143
- end
data/lib/bash/font.rb DELETED
@@ -1,91 +0,0 @@
1
-
2
- class Font
3
- BLACK = 0
4
- RED = 1
5
- GREEN = 2
6
- BROWN = 3
7
- BLUE = 4
8
- MAGENTA = 5
9
- CYAN = 6
10
- LIGHT_GRAY = 7
11
-
12
- GRAY = 10
13
- LIGHT_RED = 11
14
- LIGHT_GREEN = 12
15
- YELLOW = 13
16
- LIGHT_BLUE = 14
17
- LIGHT_MAGENTA = 15
18
- LIGHT_CYAN = 16
19
- WHITE = 17
20
-
21
- RESET = "\e[0m"
22
-
23
- #types font
24
- STD = 0
25
- BOLD = 1
26
- UNDERLINE = 2
27
- BLINK = 4
28
-
29
- attr_reader :font, :foreground, :background
30
-
31
- def initialize (font = STD, foreground = WHITE, background = nil)
32
- raise "not found color #{foreground}" unless (0..7).cover? foreground or (10..17).cover? foreground
33
- @font, @foreground, @background = font, foreground, background
34
-
35
- @bash_command = ''
36
-
37
- @string = "<type=%s, foreground=%s, background=%s>" % [@font, @foreground, @background]
38
- if font == STD
39
- if foreground and foreground < 10
40
- @bash_command << "\e[3#{foreground}m"
41
- else
42
- @bash_command << "\e[9#{foreground-10}m"
43
- end
44
- end
45
-
46
- if font & BOLD != 0
47
- if foreground < 10
48
- @bash_command << "\e[1;3#{foreground}m"
49
- else
50
- @bash_command << "\e[1;9#{foreground-10}m"
51
- end
52
- end
53
-
54
- if font & UNDERLINE != 0
55
- if foreground < 10
56
- @bash_command << "\e[4;3#{foreground}m"
57
- else
58
- @bash_command << "\e[4;9#{foreground-10}m"
59
- end
60
- end
61
-
62
- if background.instance_of? Fixnum
63
- if background < 10
64
- @bash_command << "\e[4#{background}m"
65
- else
66
- @bash_command << "\e[10#{background-10}m"
67
- end
68
- end
69
-
70
- end
71
-
72
- def to_bash
73
- @bash_command
74
- end
75
-
76
- def to_s
77
- @string
78
- end
79
-
80
- class << self
81
- def rand_color (exclude_color = nil)
82
- color = rand(14)
83
- color += 1 if color == exclude_color
84
- color = 0 if color > 14
85
- color += 3 if color > 7
86
- color
87
- end
88
- end
89
-
90
-
91
- end
@@ -1,12 +0,0 @@
1
- $:.unshift(File.dirname(__FILE__))
2
- class RandomText
3
- @@text = File.open(File.dirname(__FILE__)+'/utf') { |file| file.read }
4
- class << self
5
- def get
6
- aText = @@text.split(' ')
7
- len = Random.new.rand(1...70)
8
- max = Random.new.rand(0...aText.size-len)
9
- aText[max, len].join(' ')
10
- end
11
- end
12
- end
data/lib/example1.rb DELETED
@@ -1,86 +0,0 @@
1
- # coding: utf-8
2
- $:.unshift(File.dirname(__FILE__))
3
-
4
- require 'bash/console'
5
- require 'bash/font'
6
- require 'scroll'
7
- require 'vertical_scroll'
8
- require 'horizontal_scroll'
9
- require 'common/random_text'
10
-
11
-
12
- def join_all
13
- main = Thread.main
14
- current = Thread.current
15
- all = Thread.list
16
- all.each {|t| t.join unless t == current or t == main}
17
- end
18
-
19
- default_font = Font.new(Font::STD, Font::LIGHT_BLUE)
20
-
21
-
22
- console = Console.new(default_font)
23
- console.clear()
24
-
25
- window_font = Font.new(Font::STD, Font::WHITE, Font::BLUE)
26
-
27
-
28
- font_scroll = Font.new(Font::STD, Font::YELLOW)
29
-
30
- scroll = VerticalScroll.new(
31
- coordinates: [41, 1],
32
- window_size: [80, 28],
33
- message_block_size: 23,
34
- font: font_scroll,
35
- separator: "\u2508",
36
- start: Scroll::ENDING,
37
- adapt_size_message: true,
38
- prefix: ->{ Time.now.strftime('%H-%M-%S:%3N') << " " }
39
- )
40
-
41
-
42
- console.draw_window(4, 31, 122, 6, 'Example List', window_font, Console::BORDER_UTF_DOUBLE)
43
-
44
- scroll2 = HorizontalScroll.new(
45
- coordinates: [4, 31],
46
- window_size: [120, 4],
47
- message_block_size: 10,
48
- font: font_scroll,
49
- separator: true,
50
- start: Scroll::BEGINNING
51
- )
52
-
53
- 1.upto(28) { |y|
54
- if (10..20).include? y
55
- console.write_to_position(121, y, "\u2503")
56
- else
57
- console.write_to_position(121, y, "\u2502")
58
- end
59
-
60
- }
61
-
62
- Thread.new do
63
- 1000.times do
64
- font = Font.new(Font::BOLD, rand(7), nil)
65
- x = rand(40)
66
- y = rand(30)
67
- console.write_to_position(x, y, '.', font)
68
-
69
- font = Font.new(Font::STD, Font::rand_color(window_font.background), window_font.background)
70
- scroll.add(RandomText::get(), font)
71
- scroll2.add(RandomText::get(), font)
72
-
73
- sleep(0.7)
74
- end
75
- end
76
- Thread.new do
77
- 1000.times do
78
- font = Font.new(Font::STD, window_font.foreground, window_font.background)
79
- scroll2.add(RandomText::get(), font)
80
-
81
- sleep(0.3)
82
- end
83
- end
84
-
85
-
86
- join_all
data/lib/main.rb DELETED
@@ -1,71 +0,0 @@
1
- ####!> coding:
2
- $:.unshift(File.dirname(__FILE__))
3
- print "\u2580"
4
- exit
5
- 255.downto(0) { |i|
6
- puts i.chr
7
- }
8
-
9
- exit
10
- require 'bash/console'
11
- require 'bash/font'
12
- require 'scroll'
13
-
14
- font = Font.new(Font::STD, Font::LIGHT_BLUE)
15
-
16
- #
17
- console = Console.new(font)
18
- console.clear()
19
- #console.write_ln('+' << '-' * 59 << '+')
20
- #console.write_ln(("| %9s " % 'Thread') * 5 << '|')
21
- #console.write_ln('+' << '-' * 59 << '+')
22
-
23
- #####console.draw_rectangle(1, 1, 100, 40, Font::get(Font::STD, Font::STD, nil))
24
-
25
- font_scroll = Font.new(Font::STD, Font::YELLOW, Font::BLACK)
26
-
27
- font_scroll1 = Font.new(Font::STD, Font::LIGHT_GREEN, Font::BLACK)
28
-
29
-
30
- scroll = Scroll.new(
31
- coordinates: [100, 3],
32
- size: [80, 20],
33
- message_block_size: [80, 3],
34
- message_crop?: true,
35
- message_keep: 0,
36
- type: Scroll::VERTICAL,
37
- font: font_scroll,
38
- separator: ' ',
39
- start: Scroll::BEGINNING
40
- # prefix: ->{ Time.now.strftime('%H-%M-%S:%3N') << "\n" }
41
- )
42
-
43
- at_exit do |unusedlocal|
44
- #console.clear()
45
- end
46
-
47
- #Thread.new {
48
- #
49
- # scroll.add(gets())
50
- #}
51
-
52
- generator = ->(count){
53
- value = ''
54
- 25.times {value << (65 + rand(25)).chr}
55
- value
56
- }
57
-
58
- 100000.times {
59
- font = Font.new(Font::BOLD, rand(7), nil)
60
- x = rand(100)
61
- y = rand(40)
62
- console.write_to_position(x, y, '.', font)
63
- #
64
- #scroll.add("\n01234" * 4, font_scroll2)
65
-
66
- #scroll.add(generator.(50).to_s, font_scroll1)
67
-
68
- scroll.add('' << '[]' * rand(40) << "\n1111\n1221")
69
-
70
- sleep(0.4)
71
- }