rutui 0.4 → 0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 09bb43480dcae85b5dbebb214e1980643f4d8d88
4
+ data.tar.gz: 487362e697b37a46373b331782ad477fe73117b5
5
+ SHA512:
6
+ metadata.gz: a38da746bfe1b3ae94da639959d9b19b00af7b8104ce6d83958aaa5b48cf6a0f251a78a494a8c6ac6e4953faed6821a56cd4f31fd993109b0a3a7b1d8b55d122
7
+ data.tar.gz: c8bf6ac48905283217387fe3021a7f0a9dc32c80294fb4bd6e6f6ecef2c1d6af32c14364a7181014837f16042a9dcf57936db01d531fe0c505ee25d2ff695f2b
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env ruby
2
1
  # encoding: UTF-8
3
2
  #
4
3
  # https://github.com/b1nary/rutui
@@ -6,10 +5,11 @@
6
5
  # Author: Roman Pramberger (roman@pramberger.ch)
7
6
  # License: MIT
8
7
  #
9
- require 'rutui/util'
8
+ require 'rutui/ansi'
10
9
  require 'rutui/pixel'
11
10
  require 'rutui/theme'
12
11
  require 'rutui/objects'
12
+ require 'rutui/input'
13
13
  require 'rutui/screen'
14
14
  require 'rutui/screenmanager'
15
15
  require 'rutui/figlet'
@@ -17,22 +17,4 @@ require 'rutui/axx'
17
17
  require 'rutui/sprites'
18
18
  require 'rutui/table'
19
19
  require 'rutui/textfield'
20
-
21
- module RuTui
22
- Ansi = ::Ansi
23
- Utils = ::Utils
24
- Pixel = ::Pixel
25
- Theme = ::Theme
26
- BaseObject = ::BaseObject
27
- Box = ::Box
28
- Line = ::Line
29
- Circle = ::Circle
30
- Text = ::Text
31
- Screen = ::Screen
32
- ScreenManager = ::ScreenManager
33
- Figlet = ::Figlet
34
- Axx = ::Axx
35
- Sprite = ::Sprite
36
- Table = ::Table
37
- Textfield = ::Textfield
38
- end
20
+ require 'rutui/checkbox'
@@ -0,0 +1,46 @@
1
+ module RuTui
2
+ ## Ansi Class
3
+ # This Class generates ansi strings for the
4
+ # Terminal based output.
5
+ #
6
+ # Its only tested on Linux, should work atleast
7
+ # on other unix based systems (Use a proper ansi,
8
+ # shell/simulator on windows, and you'll be fine)
9
+ #
10
+ class Ansi
11
+ # Calculate color from RGB values
12
+ def self.rgb(red, green, blue); 16 + (red * 36) + (green * 6) + blue; end
13
+ # Set background color
14
+ def self.bg color; "\e[48;5;#{color}m"; end
15
+ # Set text color
16
+ def self.fg color; "\e[38;5;#{color}m"; end
17
+ # "Shortcut" to background color
18
+ def self.background color; self.bg color; end
19
+ # "Shortcut" to foreground/text color
20
+ def self.foreground color; self.fg color; end
21
+ # Set bold
22
+ def self.bold text; "\e[1m#{text}"; end
23
+ # Set thin
24
+ def self.thin text; "\e[2m#{text}"; end
25
+ # Set italic
26
+ def self.italic text; "\e[3m#{text}"; end
27
+ # Set underline
28
+ def self.underline text; "\e[4m#{text}"; end
29
+ # Set blink
30
+ def self.blink text; "\e[5m#{text}"; end
31
+ # Clear all color
32
+ def self.clear_color; "\e[0m"; end
33
+ # Clear Screen/Terminal
34
+ def self.clear; "\e[2J"; end
35
+ # set start
36
+ def self.set_start; "\e[s"; end
37
+ # goto start
38
+ def self.goto_start; "\e[u"; end
39
+ # Go home
40
+ def self.go_home; "\e[H"; end
41
+ # Goto position
42
+ def self.position x,y; "\e[#{y};#{x}f"; end
43
+ # Hide cursor
44
+ def self.hide_cursor; "\e?25l"; end
45
+ end
46
+ end
@@ -1,86 +1,86 @@
1
- ## Basic Ascii Image format Axx
2
- # First implemented: here :3
3
- #
4
- # Example:
5
- # # Comments ...
6
- # nil|A:1:0|A|A:2
7
- #
8
- # nil empty pixel
9
- # A:1:0 Char is A, 1 is foreground, 0 is background
10
- # A Char only (colors default)
11
- # A:2 Char A, Foreground 2, Background default
12
- #
13
- class Axx < BaseObject
14
- def initialize options
15
- @file = options[:file]
16
- @x = options[:x]
17
- @y = options[:y]
18
-
19
- return if @file.nil?
20
- return if !File.exists? @file
1
+ module RuTui
2
+ ## Basic Ascii Image format Axx
3
+ # First implemented: here :3
4
+ #
5
+ # Example:
6
+ # # Comments ...
7
+ # nil|A:1:0|A|A:2
8
+ #
9
+ # nil empty pixel
10
+ # A:1:0 Char is A, 1 is foreground, 0 is background
11
+ # A Char only (colors default)
12
+ # A:2 Char A, Foreground 2, Background default
13
+ #
14
+ class Axx < BaseObject
15
+ def initialize options
16
+ @file = options[:file]
17
+ @x = options[:x]
18
+ @y = options[:y]
21
19
 
22
- @img = File.open(@file).read
20
+ return if @file.nil?
21
+ return if !File.exists? @file
23
22
 
24
- parse
25
- end
23
+ @img = File.open(@file).read
24
+
25
+ parse
26
+ end
26
27
 
27
- def parse
28
- out = []
29
- @img.split("\n").each_with_index do |line,li|
30
- if !line.match(/^#/)
31
- out[li] = []
32
- line.split("|").each_with_index do |elem,ei|
33
- ele = elem.split(":")
34
- if ele.size == 3
35
- out[li][ei] = Pixel.new(ele[1].to_i,ele[2].to_i,ele[0])
36
- elsif ele.size == 2
37
- out[li][ei] = Pixel.new(ele[1].to_i,nil,ele[0])
38
- else
39
- if ele[0] == "nil"
40
- out[li][ei] = nil
28
+ def parse
29
+ out = []
30
+ @img.split("\n").each_with_index do |line,li|
31
+ if !line.match(/^#/)
32
+ out[li] = []
33
+ line.split("|").each_with_index do |elem,ei|
34
+ ele = elem.split(":")
35
+ if ele.size == 3
36
+ out[li][ei] = Pixel.new(ele[1].to_i,ele[2].to_i,ele[0])
37
+ elsif ele.size == 2
38
+ out[li][ei] = Pixel.new(ele[1].to_i,nil,ele[0])
41
39
  else
42
- out[li][ei] = Pixel.new(nil,nil,ele[0])
40
+ if ele[0] == "nil"
41
+ out[li][ei] = nil
42
+ else
43
+ out[li][ei] = Pixel.new(nil,nil,ele[0])
44
+ end
43
45
  end
44
46
  end
45
47
  end
46
48
  end
47
- end
48
49
 
49
- out.each do |o|
50
- out.delete(o) if o.nil?
50
+ out.each do |o|
51
+ out.delete(o) if o.nil?
52
+ end
53
+ @obj = out
54
+ @height = out.size
55
+ @width = out.size
51
56
  end
52
- @obj = out
53
- @height = out.size
54
- @width = out.size
55
- end
56
57
 
57
- def self.parse data
58
- out = []
59
- data.split("\n").each_with_index do |line,li|
60
- if !line.match(/^#/)
61
- out[li] = []
62
- line.split("|").each_with_index do |elem,ei|
63
- ele = elem.split(":")
64
- if ele.size == 3
65
- out[li][ei] = Pixel.new(ele[1].to_i,ele[2].to_i,ele[0])
66
- elsif ele.size == 2
67
- out[li][ei] = Pixel.new(ele[1].to_i,nil,ele[0])
68
- else
69
- if ele[0] == "nil"
70
- out[li][ei] = nil
58
+ def self.parse data
59
+ out = []
60
+ data.split("\n").each_with_index do |line,li|
61
+ if !line.match(/^#/)
62
+ out[li] = []
63
+ line.split("|").each_with_index do |elem,ei|
64
+ ele = elem.split(":")
65
+ if ele.size == 3
66
+ out[li][ei] = Pixel.new(ele[1].to_i,ele[2].to_i,ele[0])
67
+ elsif ele.size == 2
68
+ out[li][ei] = Pixel.new(ele[1].to_i,nil,ele[0])
71
69
  else
72
- out[li][ei] = Pixel.new(nil,nil,ele[0])
70
+ if ele[0] == "nil"
71
+ out[li][ei] = nil
72
+ else
73
+ out[li][ei] = Pixel.new(nil,nil,ele[0])
74
+ end
73
75
  end
74
76
  end
75
77
  end
76
78
  end
77
- end
78
79
 
79
- out.each do |o|
80
- out.delete(o) if o.nil? or o == []
80
+ out.each do |o|
81
+ out.delete(o) if o.nil? or o == []
82
+ end
83
+ return out
81
84
  end
82
- return out
83
85
  end
84
-
85
86
  end
86
-
@@ -1,158 +1,157 @@
1
1
  # encoding: UTF-8
2
- ## Figlet Class
3
- # parse Figlet Font files
4
- #
5
- # Attributes (All accessable):
6
- # :x MUST
7
- # :y MUST
8
- # :text Your text
9
- # :font Use a loaded font file
10
- # :rainbow true|any
11
- # :colors Array of example pixels used for colors
12
- #
13
- #
14
- # Example:
15
- # Figlet.add :test, "path/to/font.flf"
16
- # Figlet.new({ :text => "Meh", :font => :test, :rainbow => true })
17
- #
18
- # Config content (just to remember what the figlet slug means)
19
- # 0 - name
20
- # 1 - height of a character
21
- # 2 - height of a character, not including descenders
22
- # 3 - max line length (excluding comment lines) + a fudge factor
23
- # 4 - default smushmode for this font (like "-m 0" on command line)
24
- # 5 - number of comment lines
25
- # 6 - rtol
26
- #
27
- class Figlet < BaseObject
28
- attr_accessor :text, :rainbow, :font, :colors
29
- # Figlet font: '!" #$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz[|]~ÄÖÜäöüß'
30
- @@chars = '!!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz[|]~ÄÖÜäöüß'.split("")
31
- @@rainbow = nil
32
- @@fonts = {}
33
-
34
- # Initialize (see above)
35
- def initialize options
36
- @x = options[:x]
37
- @y = options[:y]
38
-
39
- @@rainbow = Theme.get(:rainbow) if @@rainbow.nil?
40
-
41
- return if @x.nil? or @y.nil?
42
-
43
- @font = options[:font]
44
- @text = options[:text]
45
- @rainbow = options[:rainbow]
46
- @space = options[:space]
47
- @space = 0 if @space.nil?
48
- @colors = options[:colors]
49
- @colors = [Pixel.new(Theme.get(:textcolor), Theme.get(:background).bg, Theme.get(:background).symbol)] if @colors.nil?
50
-
51
- create
52
- end
53
-
54
- # Create Figlet text object
55
- # Recall it any time when attributes have changed
56
- def create
57
- obj = []
58
- @@fonts[@font]['n'].size.times do
59
- obj << []
2
+ module RuTui
3
+ ## Figlet Class
4
+ # parse Figlet Font files
5
+ #
6
+ # Attributes (All accessable):
7
+ # :x MUST
8
+ # :y MUST
9
+ # :text Your text
10
+ # :font Use a loaded font file
11
+ # :rainbow true|any
12
+ # :colors Array of example pixels used for colors
13
+ #
14
+ #
15
+ # Example:
16
+ # Figlet.add :test, "path/to/font.flf"
17
+ # Figlet.new({ :text => "Meh", :font => :test, :rainbow => true })
18
+ #
19
+ # Config content (just to remember what the figlet slug means)
20
+ # 0 - name
21
+ # 1 - height of a character
22
+ # 2 - height of a character, not including descenders
23
+ # 3 - max line length (excluding comment lines) + a fudge factor
24
+ # 4 - default smushmode for this font (like "-m 0" on command line)
25
+ # 5 - number of comment lines
26
+ # 6 - rtol
27
+ #
28
+ class Figlet < BaseObject
29
+ attr_accessor :text, :rainbow, :font, :colors
30
+ # Figlet font: '!" #$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz[|]~ÄÖÜäöüß'
31
+ @@chars = '!!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz[|]~ÄÖÜäöüß'.split("")
32
+ @@rainbow = nil
33
+ @@fonts = {}
34
+
35
+ # Initialize (see above)
36
+ def initialize options
37
+ @x = options[:x]
38
+ @y = options[:y]
39
+
40
+ @@rainbow = Theme.get(:rainbow) if @@rainbow.nil?
41
+
42
+ return if @x.nil? or @y.nil?
43
+
44
+ @font = options[:font]
45
+ @text = options[:text]
46
+ @rainbow = options[:rainbow]
47
+ @space = options[:space]
48
+ @space = 0 if @space.nil?
49
+ @colors = options[:colors]
50
+ @colors = [Pixel.new(Theme.get(:textcolor), -1, Theme.get(:background).symbol)] if @colors.nil?
51
+
52
+ create
60
53
  end
61
- current = 0
62
-
63
- count = 0
64
- @text.each_byte do |c|
65
- if @@chars.include? c.chr
66
- @@fonts[@font][c.chr].each_with_index do |fr,ri|
67
- fr.each do |fc|
68
- if @rainbow
69
- obj[ri] << Pixel.new(@@rainbow[current], @colors[0].bg,fc)
70
- else
71
- obj[ri] << Pixel.new(@colors[current].fg,@colors[current].bg,fc)
72
- end
73
54
 
74
- if @rainbow != true
75
- current += 1 if @colors.size > 1
76
- current = 0 if current > @colors.size
55
+ # Create Figlet text object
56
+ # Recall it any time when attributes have changed
57
+ def create
58
+ obj = []
59
+ @@fonts[@font]['n'].size.times do
60
+ obj << []
61
+ end
62
+ current = 0
63
+
64
+ count = 0
65
+ @text.each_byte do |c|
66
+ if @@chars.include? c.chr
67
+ @@fonts[@font][c.chr].each_with_index do |fr,ri|
68
+ fr.each do |fc|
69
+ if @rainbow
70
+ obj[ri] << Pixel.new(@@rainbow[current], @colors[0].bg,fc)
71
+ else
72
+ obj[ri] << Pixel.new(@colors[current].fg,@colors[current].bg,fc)
73
+ end
74
+
75
+ if @rainbow != true
76
+ current += 1 if @colors.size > 1
77
+ current = 0 if current > @colors.size
78
+ end
77
79
  end
78
80
  end
79
- end
80
81
 
81
- if @rainbow
82
- current += 1
83
- current = 0 if current >= @@rainbow.size
84
- end
82
+ if @rainbow
83
+ current += 1
84
+ current = 0 if current >= @@rainbow.size
85
+ end
85
86
 
86
- if count < @text.size-1
87
+ if count < @text.size-1
88
+ @@fonts[@font]['n'].size.times do |ri|
89
+ @space.times do
90
+ if @rainbow
91
+ obj[ri] << Pixel.new(@@rainbow[current], @colors[0].bg,Theme.get(:background).symbol)
92
+ else
93
+ obj[ri] << Pixel.new(@colors[current].fg,@colors[current].bg,Theme.get(:background).symbol)
94
+ end
95
+ end
96
+ end
97
+ end
98
+ # SPace
99
+ else
87
100
  @@fonts[@font]['n'].size.times do |ri|
88
- @space.times do
101
+ 3.times do
89
102
  if @rainbow
90
- obj[ri] << Pixel.new(@@rainbow[current], @colors[0].bg,Theme.get(:background).symbol)
103
+ obj[ri] << Pixel.new(@@rainbow[current], @colors[0].bg, Theme.get(:background).symbol)
91
104
  else
92
- obj[ri] << Pixel.new(@colors[current].fg,@colors[current].bg,Theme.get(:background).symbol)
105
+ obj[ri] << Pixel.new(@colors[current].fg,@colors[current].bg, Theme.get(:background).symbol)
93
106
  end
94
107
  end
95
108
  end
96
109
  end
97
- # SPace
98
- else
99
- @@fonts[@font]['n'].size.times do |ri|
100
- 3.times do
101
- if @rainbow
102
- obj[ri] << Pixel.new(@@rainbow[current], @colors[0].bg, Theme.get(:background).symbol)
103
- else
104
- obj[ri] << Pixel.new(@colors[current].fg,@colors[current].bg, Theme.get(:background).symbol)
105
- end
106
- end
107
- end
110
+ count += 1
108
111
  end
109
- count += 1
112
+ @obj = obj
110
113
  end
111
- @obj = obj
112
- end
113
114
 
114
- # Static methods to add/load new Fonts
115
- def self.add name, file
116
- if File.exists?(file)
115
+ # Static methods to add/load new Fonts
116
+ def self.add name, file
117
+ if File.exists?(file)
117
118
 
118
- data = File.new(file, "r").read.split("\n")
119
- config = data[0].split(" ")
119
+ data = File.new(file, "r").read.split("\n")
120
+ config = data[0].split(" ")
120
121
 
121
- # Remove Comments (Size is in info line)
122
- config[5].to_i.times do
122
+ # Remove Comments (Size is in info line)
123
+ config[5].to_i.times do
124
+ data.delete_at(0)
125
+ end
123
126
  data.delete_at(0)
124
- end
125
127
 
126
- # Remove empty line if exist
127
- data.delete_at(0) if data[0].strip() == ""
128
+ # Remove empty line if exist
129
+ data.delete_at(0) if data[0].strip() == ""
128
130
 
129
- height = config[2].to_i
130
- rest = config[1].to_i - height
131
+ height = config[1].to_i
132
+ rest = height - config[2].to_i
131
133
 
132
- @@fonts[name] = {}
133
-
134
- @@chars.each do |i|
135
- out = []
134
+ @@fonts[name] = {}
136
135
 
137
- (data.delete_at(0); rest -= 1) if data.size > 0 and data[0].gsub('$@','').gsub(' ','') == ''
136
+ @@chars.each do |i|
137
+ out = []
138
138
 
139
- height.times do |x|
140
- break if data.size < 1
141
- xdata = data[0].gsub("$"," ").gsub("@","").gsub("\r","").split("")
142
- out << xdata if xdata.size > 0
143
- data.delete_at(0)
144
- end
139
+ config[2].to_i.times do |x|
140
+ xdata = data[0].gsub("$"," ").gsub("@","").gsub("\r","").split("")
141
+ out << xdata if xdata.size > 0
142
+ data.delete_at(0)
143
+ end
145
144
 
146
- rest.times do
147
- data.delete_at(0)
148
- end
145
+ rest.times do
146
+ data.delete_at(0)
147
+ end
149
148
 
150
- @@fonts[name][i] = out
149
+ @@fonts[name][i] = out
150
+ end
151
+ return true
152
+ else
153
+ return false
151
154
  end
152
- return true
153
- else
154
- return false
155
155
  end
156
156
  end
157
157
  end
158
-