termgui 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/termgui.rb +1 -1
- metadata +40 -107
- data/Gemfile +0 -14
- data/README.md +0 -321
- data/src/action.rb +0 -58
- data/src/box.rb +0 -90
- data/src/color.rb +0 -174
- data/src/cursor.rb +0 -69
- data/src/editor/editor_base.rb +0 -152
- data/src/editor/editor_base_handlers.rb +0 -116
- data/src/element.rb +0 -61
- data/src/element_bounds.rb +0 -111
- data/src/element_box.rb +0 -64
- data/src/element_render.rb +0 -102
- data/src/element_style.rb +0 -51
- data/src/emitter.rb +0 -102
- data/src/emitter_state.rb +0 -19
- data/src/enterable.rb +0 -93
- data/src/event.rb +0 -92
- data/src/focus.rb +0 -102
- data/src/geometry.rb +0 -53
- data/src/image.rb +0 -60
- data/src/input.rb +0 -85
- data/src/input_grab.rb +0 -17
- data/src/input_time.rb +0 -97
- data/src/key.rb +0 -114
- data/src/log.rb +0 -24
- data/src/node.rb +0 -117
- data/src/node_attributes.rb +0 -27
- data/src/node_visit.rb +0 -52
- data/src/renderer.rb +0 -119
- data/src/renderer_cursor.rb +0 -18
- data/src/renderer_draw.rb +0 -28
- data/src/renderer_image.rb +0 -31
- data/src/renderer_print.rb +0 -40
- data/src/screen.rb +0 -96
- data/src/screen_element.rb +0 -59
- data/src/screen_input.rb +0 -43
- data/src/screen_renderer.rb +0 -53
- data/src/style.rb +0 -149
- data/src/tco/colouring.rb +0 -248
- data/src/tco/config.rb +0 -57
- data/src/tco/palette.rb +0 -603
- data/src/tco/tco_termgui.rb +0 -30
- data/src/termgui.rb +0 -29
- data/src/util.rb +0 -110
- data/src/util/css.rb +0 -98
- data/src/util/css_query.rb +0 -23
- data/src/util/easing.rb +0 -364
- data/src/util/hash_object.rb +0 -131
- data/src/util/imagemagick.rb +0 -27
- data/src/util/justify.rb +0 -20
- data/src/util/unicode-categories.rb +0 -572
- data/src/util/wrap.rb +0 -102
- data/src/widget/button.rb +0 -33
- data/src/widget/checkbox.rb +0 -47
- data/src/widget/col.rb +0 -30
- data/src/widget/image.rb +0 -106
- data/src/widget/inline.rb +0 -40
- data/src/widget/input_number.rb +0 -73
- data/src/widget/inputbox.rb +0 -85
- data/src/widget/label.rb +0 -33
- data/src/widget/modal.rb +0 -69
- data/src/widget/row.rb +0 -26
- data/src/widget/selectbox.rb +0 -100
- data/src/widget/textarea.rb +0 -54
- data/src/xml/xml.rb +0 -80
- data/test/action_test.rb +0 -34
- data/test/box_test.rb +0 -15
- data/test/css_test.rb +0 -39
- data/test/editor/editor_base_test.rb +0 -201
- data/test/element_bounds_test.rb +0 -77
- data/test/element_box_test.rb +0 -8
- data/test/element_render_test.rb +0 -124
- data/test/element_style_test.rb +0 -85
- data/test/element_test.rb +0 -10
- data/test/emitter_test.rb +0 -108
- data/test/event_test.rb +0 -19
- data/test/focus_test.rb +0 -37
- data/test/geometry_test.rb +0 -12
- data/test/input_test.rb +0 -47
- data/test/key_test.rb +0 -14
- data/test/log_test.rb +0 -21
- data/test/node_test.rb +0 -105
- data/test/performance/performance1.rb +0 -48
- data/test/renderer_test.rb +0 -74
- data/test/renderer_test_rect.rb +0 -4
- data/test/screen_test.rb +0 -58
- data/test/style_test.rb +0 -18
- data/test/termgui_test.rb +0 -10
- data/test/test_all.rb +0 -30
- data/test/util_hash_object_test.rb +0 -93
- data/test/util_test.rb +0 -26
- data/test/widget/checkbox_test.rb +0 -99
- data/test/widget/col_test.rb +0 -87
- data/test/widget/inline_test.rb +0 -40
- data/test/widget/label_test.rb +0 -94
- data/test/widget/row_test.rb +0 -40
- data/test/wrap_test.rb +0 -11
- data/test/xml_test.rb +0 -77
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af01d169693ceefa3a955883a770af3768f7a902e526ce00cd4aa11b09afa73d
|
4
|
+
data.tar.gz: 4360e7b85f248e64074ae8371d3725d92518a1d9571ce0005884c5af3081226f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e929dcad6d63589630c51c62ffd1638e3409a613b00acdac8d661e2b16ae9a93070e90b479259518b637b14d66729a5e404a4f657fcbf7fc3e943cdbe1f1111
|
7
|
+
data.tar.gz: 34ab0ae4d6c7754b6e0b0806367c5f05584182c7d787d16c73abfeb058f2a5407da1e4bab8d666075af06399cb2fdc2ced757568858580c7a5f30f29bfd41319
|
data/lib/termgui.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require_relative '../src/termgui'
|
1
|
+
require_relative '../src/termgui'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: termgui
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastián Gurin
|
@@ -9,12 +9,39 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2020-02-10 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: chunky_png
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.3.11
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.3.11
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rexml
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.2.4
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.2.4
|
41
|
+
description: "\n * Pure Ruby library for creating desktop-like interfaces in the command
|
42
|
+
line.\n\n * Flexible and easy to use utilities for focus/actions/scroll/events/cursor.\n\n
|
43
|
+
* Support high level APIs similar to HTML DOM APIs like layouts, styles, box-model,
|
44
|
+
cascade styles, XML/ERB, boxes, fonts, images, colors, easing,\n\n * Low level utilities
|
18
45
|
can be used independently without bloating the performance\n\n * Event loop supporting
|
19
46
|
set_timeout, wait_for, set_interval\n\n * Many high level widgets, utilities implemented
|
20
47
|
expected in GUIs.\n\n * WIP (my first Ruby project)\n "
|
@@ -23,109 +50,15 @@ executables: []
|
|
23
50
|
extensions: []
|
24
51
|
extra_rdoc_files: []
|
25
52
|
files:
|
26
|
-
- Gemfile
|
27
|
-
- README.md
|
28
53
|
- lib/termgui.rb
|
29
|
-
|
30
|
-
- src/box.rb
|
31
|
-
- src/color.rb
|
32
|
-
- src/cursor.rb
|
33
|
-
- src/editor/editor_base.rb
|
34
|
-
- src/editor/editor_base_handlers.rb
|
35
|
-
- src/element.rb
|
36
|
-
- src/element_bounds.rb
|
37
|
-
- src/element_box.rb
|
38
|
-
- src/element_render.rb
|
39
|
-
- src/element_style.rb
|
40
|
-
- src/emitter.rb
|
41
|
-
- src/emitter_state.rb
|
42
|
-
- src/enterable.rb
|
43
|
-
- src/event.rb
|
44
|
-
- src/focus.rb
|
45
|
-
- src/geometry.rb
|
46
|
-
- src/image.rb
|
47
|
-
- src/input.rb
|
48
|
-
- src/input_grab.rb
|
49
|
-
- src/input_time.rb
|
50
|
-
- src/key.rb
|
51
|
-
- src/log.rb
|
52
|
-
- src/node.rb
|
53
|
-
- src/node_attributes.rb
|
54
|
-
- src/node_visit.rb
|
55
|
-
- src/renderer.rb
|
56
|
-
- src/renderer_cursor.rb
|
57
|
-
- src/renderer_draw.rb
|
58
|
-
- src/renderer_image.rb
|
59
|
-
- src/renderer_print.rb
|
60
|
-
- src/screen.rb
|
61
|
-
- src/screen_element.rb
|
62
|
-
- src/screen_input.rb
|
63
|
-
- src/screen_renderer.rb
|
64
|
-
- src/style.rb
|
65
|
-
- src/tco/colouring.rb
|
66
|
-
- src/tco/config.rb
|
67
|
-
- src/tco/palette.rb
|
68
|
-
- src/tco/tco_termgui.rb
|
69
|
-
- src/termgui.rb
|
70
|
-
- src/util.rb
|
71
|
-
- src/util/css.rb
|
72
|
-
- src/util/css_query.rb
|
73
|
-
- src/util/easing.rb
|
74
|
-
- src/util/hash_object.rb
|
75
|
-
- src/util/imagemagick.rb
|
76
|
-
- src/util/justify.rb
|
77
|
-
- src/util/unicode-categories.rb
|
78
|
-
- src/util/wrap.rb
|
79
|
-
- src/widget/button.rb
|
80
|
-
- src/widget/checkbox.rb
|
81
|
-
- src/widget/col.rb
|
82
|
-
- src/widget/image.rb
|
83
|
-
- src/widget/inline.rb
|
84
|
-
- src/widget/input_number.rb
|
85
|
-
- src/widget/inputbox.rb
|
86
|
-
- src/widget/label.rb
|
87
|
-
- src/widget/modal.rb
|
88
|
-
- src/widget/row.rb
|
89
|
-
- src/widget/selectbox.rb
|
90
|
-
- src/widget/textarea.rb
|
91
|
-
- src/xml/xml.rb
|
92
|
-
- test/action_test.rb
|
93
|
-
- test/box_test.rb
|
94
|
-
- test/css_test.rb
|
95
|
-
- test/editor/editor_base_test.rb
|
96
|
-
- test/element_bounds_test.rb
|
97
|
-
- test/element_box_test.rb
|
98
|
-
- test/element_render_test.rb
|
99
|
-
- test/element_style_test.rb
|
100
|
-
- test/element_test.rb
|
101
|
-
- test/emitter_test.rb
|
102
|
-
- test/event_test.rb
|
103
|
-
- test/focus_test.rb
|
104
|
-
- test/geometry_test.rb
|
105
|
-
- test/input_test.rb
|
106
|
-
- test/key_test.rb
|
107
|
-
- test/log_test.rb
|
108
|
-
- test/node_test.rb
|
109
|
-
- test/performance/performance1.rb
|
110
|
-
- test/renderer_test.rb
|
111
|
-
- test/renderer_test_rect.rb
|
112
|
-
- test/screen_test.rb
|
113
|
-
- test/style_test.rb
|
114
|
-
- test/termgui_test.rb
|
115
|
-
- test/test_all.rb
|
116
|
-
- test/util_hash_object_test.rb
|
117
|
-
- test/util_test.rb
|
118
|
-
- test/widget/checkbox_test.rb
|
119
|
-
- test/widget/col_test.rb
|
120
|
-
- test/widget/inline_test.rb
|
121
|
-
- test/widget/label_test.rb
|
122
|
-
- test/widget/row_test.rb
|
123
|
-
- test/wrap_test.rb
|
124
|
-
- test/xml_test.rb
|
125
|
-
homepage: https://rubygems.org/gems/termgui
|
54
|
+
homepage: https://github.com/cancerberoSgx/termgui
|
126
55
|
licenses:
|
127
56
|
- MIT
|
128
|
-
metadata:
|
57
|
+
metadata:
|
58
|
+
bug_tracker_uri: https://github.com/cancerberoSgx/termgui
|
59
|
+
documentation_uri: https://github.com/cancerberoSgx/termgui
|
60
|
+
homepage_uri: https://github.com/cancerberoSgx/termgui
|
61
|
+
source_code_uri: https://github.com/cancerberoSgx/termgui
|
129
62
|
post_install_message:
|
130
63
|
rdoc_options: []
|
131
64
|
require_paths:
|
data/Gemfile
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
|
-
|
5
|
-
gem 'chunky_png'
|
6
|
-
# gem 'justify'
|
7
|
-
gem 'rexml'
|
8
|
-
gem 'strings'
|
9
|
-
|
10
|
-
gem 'filewatcher', group: :development
|
11
|
-
gem 'rubocop', require: false, group: :development
|
12
|
-
gem 'solargraph', require: false, group: :development
|
13
|
-
gem 'test-unit', group: :development
|
14
|
-
# gem 'yarn', require: false, group: :development
|
data/README.md
DELETED
@@ -1,321 +0,0 @@
|
|
1
|
-
# termgui
|
2
|
-
|
3
|
-
Repository: https://github.com/cancerberoSgx/termgui
|
4
|
-
|
5
|
-
* Command line graphical user interface Ruby toolkit.
|
6
|
-
* Create desktop-like interfaces in the command line.
|
7
|
-
* Personal ruby-learning project at the beginning
|
8
|
-
* 100% ruby, no binaries, no dependencies
|
9
|
-
* some ideas taken from npm.org/blessed and my own npm.org/accursed
|
10
|
-
* HTML DOM like high level API with styles, layouts, box-model, cascade styles
|
11
|
-
* xml / edb support for declaring components in XML syntax
|
12
|
-
* rendered optionally supporting a buffer to print out the current screen for testing
|
13
|
-
* very well tested
|
14
|
-
* flexible managers for focus, actions, scroll, keys, input grab, input grab, cursor
|
15
|
-
* event loop supporting set_timeout, wait_for, set_interval
|
16
|
-
* text-area / editor support
|
17
|
-
* all colors and attributes
|
18
|
-
* some basic high level widgets: Button, Label, InputBox, TextArea, Editor, Select,
|
19
|
-
* independent low level APIs can be used without the high level overhead for listening stdin, drawing, etc
|
20
|
-
* box drawing, easing, css parser and dom selector
|
21
|
-
|
22
|
-
|
23
|
-
## TODO / Status
|
24
|
-
|
25
|
-
See [TODO](TODO.md)
|
26
|
-
|
27
|
-
|
28
|
-
## Motivation
|
29
|
-
|
30
|
-
* I don't want to use ncurses based dependencies since is binary
|
31
|
-
* I know there are a couple of initiatives 100% in ruby now, but I didn't knew them when I started this project
|
32
|
-
* I'm the author of npm.org/accursed which is a similar library so I can of already implemented this in JavaScript
|
33
|
-
* Initially a pet project to learn Ruby
|
34
|
-
|
35
|
-
## Usage
|
36
|
-
|
37
|
-
```
|
38
|
-
gem install termgui
|
39
|
-
```
|
40
|
-
|
41
|
-
### Example
|
42
|
-
|
43
|
-
```rb
|
44
|
-
require 'termgui'
|
45
|
-
screen = Screen.new
|
46
|
-
left = screen.append_child Col.new(width: 0.4, height: 0.99, style: { bg: 'red' })
|
47
|
-
(0..8).map { |i| left.append_child Label.new(text: "Label_#{i}") }
|
48
|
-
right = screen.append_child Col.new(width: 0.6, height: 0.99, x: 0.4, style: {bg: 'blue'))
|
49
|
-
(0..4).map do |i|
|
50
|
-
right.append_child Button.new(
|
51
|
-
text: "Button_#{i}", x: 0.5,
|
52
|
-
style: {focus: {fg: '#ed5525'}},
|
53
|
-
action: proc { open_modal(screen: screen, title: "Button_#{i}") }
|
54
|
-
)
|
55
|
-
end
|
56
|
-
screen.start
|
57
|
-
```
|
58
|
-
|
59
|
-
Result:
|
60
|
-
|
61
|
-

|
62
|
-
|
63
|
-
## Development commands
|
64
|
-
|
65
|
-
```sh
|
66
|
-
cd termui
|
67
|
-
bundler install
|
68
|
-
sh bin/test
|
69
|
-
sh bin/doc
|
70
|
-
sh bin/dev # rails server
|
71
|
-
sh bin/watch # tests in watch mode
|
72
|
-
```
|
73
|
-
|
74
|
-
## API Reference
|
75
|
-
|
76
|
-
TODO
|
77
|
-
|
78
|
-
### low level (working) examples
|
79
|
-
|
80
|
-
TODO
|
81
|
-
|
82
|
-
#### No DOM - just draw
|
83
|
-
|
84
|
-
TODO
|
85
|
-
|
86
|
-
#### Only Input
|
87
|
-
|
88
|
-
TODO
|
89
|
-
|
90
|
-
#### Only Renderer
|
91
|
-
|
92
|
-
TODO
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
## Element attributes
|
98
|
-
|
99
|
-
Some high level element attributes implemented:
|
100
|
-
|
101
|
-
### style-cascade
|
102
|
-
|
103
|
-
By default, children inherit parent style. If `element.get_attribute('style-cascade') == 'prevent'` it won't happen - this is the children won't be affected by its parent style and only its own is rendered.
|
104
|
-
|
105
|
-
### focusable, focused and screen.focus.keys, focus, blur
|
106
|
-
|
107
|
-
elements with focusable attribute will be able to be focused when user press focus keys (configurable in screen.focus.keys ). By default screen.focus.keys == { next: ['tab'], prev: ['S-tab'] }.
|
108
|
-
|
109
|
-
focusable elements will emit "focus" and "blur" events
|
110
|
-
|
111
|
-
When focused, the attribute focused will be true and the element is able to receive "action" event (see actionable, action-keys below)
|
112
|
-
|
113
|
-
### actionable, action-keys, action
|
114
|
-
|
115
|
-
this is useful to implement actionable widgets like buttons that, when focused, can emit "action" events when certain keys are pressed (by default ENTER)
|
116
|
-
|
117
|
-
focused elements with attribute "actionable" will emit "action" events if user press action-keys (enter by default) when they are focused. Action keys can be configured globally using screen.action.keys or by element with attribute action-keys. Both could be a string or array.
|
118
|
-
|
119
|
-
|
120
|
-
### action-on-focus
|
121
|
-
|
122
|
-
automatically trigger an action event wneh an element is focused. helpful for selectbox so no enter is needed for working
|
123
|
-
|
124
|
-
### escape-on-blur
|
125
|
-
|
126
|
-
automatically escapes an entered element on blur. helpful for selectbox so no escape is needed for switching focus - so it behaves like buttons
|
127
|
-
|
128
|
-
|
129
|
-
### enterable, entered, change, input, escape, escape-keys
|
130
|
-
|
131
|
-
This is useful to implement textarea / textinput widgets for which we don't want to trigger focus or action events when user is writing text. When an enterable element (that also should be focusable) receives "action" it is set to "entered" mode. (whey you are writing text, you want TAB S-tab, enter, etc to actually insert characters and don't emit "focus" "action", etc events...)
|
132
|
-
|
133
|
-
When an element is on this mode (only one at a time) the rest of the elements will stop receiving common events like focus or action until it leaves the entered mode. . This could happen programmatically or by receiving "escape" event, by default pressing ESC will provoke "escape" event which will set entered = false and enable normal events again (like focus, action, etc). When entered==true, the entered element will listen for input independently and emit "input" events.
|
134
|
-
|
135
|
-
the enter event by default is provoked by "action" (enter) so it can be configured individually using action-keys.
|
136
|
-
|
137
|
-
the escape event by default pressing "escape" can be configurable per element using attribute escape-keys (just like action-keys)
|
138
|
-
|
139
|
-
TODO: configure to better play with focus: enter-on-focus to automatically "entered" without "action" and automatically "escape" on "blur" (focus will keep working on this case). Also is not clear how escape plays with change
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
## Performance notes
|
145
|
-
|
146
|
-
* disabling renderer buffer speeds up rendering about 30%: `screen.renderer.no_buffer = true`. Genereally don't needed in production.
|
147
|
-
|
148
|
-
|
149
|
-
## API example prototypes (WIP)
|
150
|
-
|
151
|
-
** initial design stories**
|
152
|
-
|
153
|
-
### layout
|
154
|
-
|
155
|
-
TODO / proposal
|
156
|
-
|
157
|
-
```
|
158
|
-
require 'termgui'
|
159
|
-
class AppExplorer < Column
|
160
|
-
def initialize(model)
|
161
|
-
super
|
162
|
-
@model=model
|
163
|
-
@text = append_child(text: Textarea.new model.text, onChange: {|e| print e.key})
|
164
|
-
@text.onChange {|e| print e.key}
|
165
|
-
end
|
166
|
-
end
|
167
|
-
screen = Screen.new
|
168
|
-
main = Row.new
|
169
|
-
left = main.append_child(Column.new 0.3)
|
170
|
-
right = main.append_child(Column.new 0.7)
|
171
|
-
explorer = left.append_child(AppExplorer.new model)
|
172
|
-
editor = right.append_child(AppEditor.new model)
|
173
|
-
screen start
|
174
|
-
```
|
175
|
-
|
176
|
-
### structure
|
177
|
-
|
178
|
-
TODO / proposal
|
179
|
-
|
180
|
-
```
|
181
|
-
class MyWidget < Column
|
182
|
-
def initialize
|
183
|
-
super 0.5
|
184
|
-
append_children [
|
185
|
-
{type: Row, height: 0.6, children: [
|
186
|
-
{type: Input, value: 'edit me', width: 0.5, onChange: {|e|print e} },
|
187
|
-
{type: Label, text: 'edit me'},
|
188
|
-
]}
|
189
|
-
{type: Button, text: 'click me', onClick: {|e|print e}},
|
190
|
-
]
|
191
|
-
end
|
192
|
-
end
|
193
|
-
```
|
194
|
-
|
195
|
-
#### aside
|
196
|
-
|
197
|
-
```
|
198
|
-
{type: Button, text: 'click me', onclick: {|e|print e}},
|
199
|
-
vs
|
200
|
-
Button.new text: 'click me', onclick: {|e|print e}},
|
201
|
-
|
202
|
-
{type: Row, height: 0.6, children: [
|
203
|
-
{type: Input, value: 'edit me', width: 0.5, onChange: {|e|print e} },
|
204
|
-
{type: Label, text: 'hello'},
|
205
|
-
]}
|
206
|
-
vs
|
207
|
-
Row.new height: 0.6, children: [
|
208
|
-
Input.new value: 'edit me', width: 0.5, onChange: {|e|print e},
|
209
|
-
Label new: label: 'hello'
|
210
|
-
]
|
211
|
-
```
|
212
|
-
|
213
|
-
### style
|
214
|
-
|
215
|
-
style = {
|
216
|
-
'.primary': {
|
217
|
-
bg: 'red',
|
218
|
-
fg: 'black'
|
219
|
-
bold: true
|
220
|
-
}
|
221
|
-
}
|
222
|
-
screen.append_child(Column.new children: [
|
223
|
-
Label.new text: 'are you sure?',
|
224
|
-
Button.new
|
225
|
-
])
|
226
|
-
|
227
|
-
|
228
|
-
### high level no layout
|
229
|
-
|
230
|
-
TODO / proposal
|
231
|
-
|
232
|
-
```
|
233
|
-
s=Screen.new
|
234
|
-
b=Button.new(parent: s.document, width: 0.3, height: 0.3, left: 0, top: 0, label: 'click me', onClick: { |e| alert "#{e.target.label} clicked!" })
|
235
|
-
s.start
|
236
|
-
```
|
237
|
-
|
238
|
-
### example low level
|
239
|
-
|
240
|
-
(no HTML DOM at all, just drawing)
|
241
|
-
```
|
242
|
-
screen = Screen.new
|
243
|
-
screen.renderer.rect(2,3,9,3,'-', {fg: 'yellow', bg: 'gray'})
|
244
|
-
screen.renderer.text(x: 3, y: 4,text; 'click me', style: Style.new(fg: '#ffee11', bg: 'black', bold: true))
|
245
|
-
```
|
246
|
-
|
247
|
-
### events
|
248
|
-
|
249
|
-
```
|
250
|
-
screen=Screen.new
|
251
|
-
screen.event.add_listener('key', {|e| exit 0 if e.key=='q'})
|
252
|
-
renderer.text(text: 'press q to exit')
|
253
|
-
```
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
## Design
|
258
|
-
|
259
|
-
### concepts
|
260
|
-
|
261
|
-
Screen: contains document, renderer, buffer, Input
|
262
|
-
|
263
|
-
Renderer: responsible of drawing given pixels to the terminal
|
264
|
-
|
265
|
-
Buffer: maintains screen as bitmap structure (so users can read the current screen contents like a bitmap)
|
266
|
-
|
267
|
-
Document: Node subclass analog to html's (access to parent screen)
|
268
|
-
|
269
|
-
Node: DOM like representation analog to html's (children, attributes)
|
270
|
-
|
271
|
-
Element: Node subclass analog to html's (border, margin, padding)
|
272
|
-
|
273
|
-
Input: responsible of user input - notifies screen - emitter
|
274
|
-
|
275
|
-
## Summary
|
276
|
-
|
277
|
-
I'm author of npm.org/flor that although has superior terminal support (tput) I would like to re implement a similar library for ruby, writing it from scratch (currently learning ruby).
|
278
|
-
|
279
|
-
* low level html-canvas like to set attributes and write strings
|
280
|
-
* try to stick to html canvas api for Renderer
|
281
|
-
* user is responsible of setting the 'active style' like canvas' stroke-width - this simplifies renderer
|
282
|
-
* renderer of styled strings supporting cursor management,
|
283
|
-
* responsible of translating user's `{bg: 'red', s: 'hello'}` into a string with ansi codes
|
284
|
-
* screen maintains a virtual Buffer so current drawn screen can be accessed like a bitmap
|
285
|
-
* a DOM like API for children, attributes, box model, style
|
286
|
-
* supports user input events also like html dom EventSource (element.add_listener('key', ...))
|
287
|
-
* basic widget implementations: button,input,textarea
|
288
|
-
* style: fg, bg, ch, bold, etc.
|
289
|
-
* focus management: focused/focusable - element.style.focus
|
290
|
-
* input event loop : set_timeout
|
291
|
-
* easy keyboard event representation and API
|
292
|
-
|
293
|
-
## Future
|
294
|
-
|
295
|
-
add features from npm.org/flor:
|
296
|
-
|
297
|
-
* scroll (element.scrollX=0.2) - dom support
|
298
|
-
* a xmlish syntax for defining GUI.
|
299
|
-
* support function attributes for event handlers as ruby fragments
|
300
|
-
|
301
|
-
## Side projects
|
302
|
-
|
303
|
-
* cli/driver for ruby : for properly testing termgui we need cli-driver for ruby. see probes/stdin.rb for working exec and writing to process stdin async
|
304
|
-
|
305
|
-
|
306
|
-
## Design notes
|
307
|
-
|
308
|
-
TODO
|
309
|
-
|
310
|
-
Screen, renderer, input are responsible of basic terminal styles like bg, fg, bold, etc.
|
311
|
-
|
312
|
-
On top of the screen, renderer and input a document object model like HTML DOM is supported. See Node, Element, Style, etc. Some features based on HTML supported are:
|
313
|
-
|
314
|
-
* box model similar
|
315
|
-
* children rendering
|
316
|
-
* text
|
317
|
-
* element query
|
318
|
-
* border
|
319
|
-
* padding
|
320
|
-
|
321
|
-
Some high level utilities, like the focus/action management, work on top of this DOM so probably 99% of users will want to go that way for building their GUIs.
|