Skip to content

Commit f1456a2

Browse files
committed
Minor code and documentation updates
1 parent 2a2b91a commit f1456a2

File tree

14 files changed

+60
-34
lines changed

14 files changed

+60
-34
lines changed

CRYSTAL-WISHLIST.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ Matches are:
101101

102102
https://github.com/crystal-lang/crystal/issues/10231
103103

104-
The issue has since been resolved by HertzDevil, but is not yet the default.
104+
The issue has since been resolved by @HertzDevil, but is not yet the default.
105105
To have the fix applied, you must invoke crystal with `crystal run -Dpreview_overload_order ...`.
106106

107107
## Type-safe `#==` operator:
@@ -125,10 +125,13 @@ For example, to have an operator like `#==?` that behaves like the current `#==`
125125
arguments are not comparable). And then to change `#==` to a type-safe version so that it produces an
126126
error when there is no comparison defined between its arguments.
127127

128+
@straight-shoota added this item (although with a different proposed solution) to the wishlist
129+
for the next Crystal major version (TODO: find a reference to it).
130+
128131
## API to expose a method to kill Fiber from outside code.
129132

130-
This supposedly exists in non-public API, but maybe it does not exist
131-
at all?
133+
This supposedly exists in non-public API, but I did not find it, be it public
134+
or not.
132135

133136
## Ability to create a Proc and partial from a method with named args:
134137

@@ -144,7 +147,7 @@ ppf = pf.partial(b: 10)
144147
145148
```
146149

147-
A workaround exists in https://github.com/crystal-lang/crystal/issues/11099
150+
A workaround was developed by @HertzDevil in https://github.com/crystal-lang/crystal/issues/11099
148151

149152
## Better subclassing in Procs:
150153

benchmarks/cells-vs-arrays.cr

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ require "../src/crysterm"
3434
# changing this part requires a lot of changes. See patches/2-separate-arrays.patch
3535
# as a good base to finish the work.
3636

37+
# Actually, both above and in the new tests:
38+
# user system total real
39+
# class Cell 1.278690 0.000000 1.278690 ( 1.284420)
40+
# struct Cell 0.948687 0.000000 0.948687 ( 0.952492)
41+
# separate arrays, combined access yx 0.475821 0.000000 0.475821 ( 0.477786)
42+
# separate arrays, separate access yx 0.548495 0.000000 0.548495 ( 0.550808)
43+
# separate arrays, combined access xy 1.662603 0.000000 1.662603 ( 1.669242)
44+
# separate arrays, separate access xy 1.654704 0.000000 1.654704 ( 1.661381)
45+
# separate 1d arrays, combined access yx 1.282447 0.000000 1.282447 ( 1.287833)
46+
# separate 1d arrays, combined access xy 1.288152 0.000000 1.288152 ( 1.293539)
47+
#
48+
# it appears the winning option is row 2, which is two separate arrays (1 for attrs,
49+
# 1 for chars) using combined access, e.g. attrs[width * y + x].
50+
3751
xs = 2000
3852
ys = 600
3953
reps = 1000000

documentation/positioning.md

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Positioning and sizing in Blessed
22

3+
NOTE: This document explains how positioning and sizing works in Blessed. The functionality in
4+
Crysterm is roughly the same or more flexible.
5+
36
## Positioning basics / intro
47

58
For every widget, Blessed can get, set, and/or calculate its absolute and
@@ -19,7 +22,7 @@ specify `top` and `height`. The same goes for `left`/`right` and `width`, of cou
1922

2023
Normally, position or size is specified as integer value, or is left null for auto-calculation.
2124
However, in certain cases (listed below) it can be specified as a string containing values 'center',
22-
'half', or 'xx%' (for a percentage of parent).
25+
'half', or 'xx%+-amount' (for a percentage of parent, plus or minus a certain value).
2326

2427
1. 'center' makes the widget 50% the size of parent and equally spaced from top and bottom or left and right (i.e. centered).
2528
1. 'half' equals to half of parent's width or height (i.e. "50%"), without centering.
@@ -35,7 +38,7 @@ bottom border in the parent widget). This is because percentages of parent refer
3538
not the size remaining after accounting for decorations (borders and padding).
3639
The solution is same as above, set `height: "100%-2"`.
3740

38-
Finally, not directly related, but important are variables called xi, xl, yi, and yl.
41+
Finally, not directly related but important, are variables called xi, xl, yi, and yl.
3942
Those ones do correspond to reference (0,0) on the top-left of the screen.
4043

4144
xi...xl specifies the column range in which the widget is rendered. E.g. a widget at position `left: 10`
@@ -60,7 +63,7 @@ These are offsets "R"elative to the parent widget (or to the screen if the widge
6063

6164
When rleft, rtop, rright or rbottom are set, the following takes place:
6265

63-
If the desired value is identical to the old value, the function exits.
66+
In Blessed, if the desired value is identical to the old value, the function exits.
6467

6568
If the desired value is not identical to the old value (which is stored in `self.position.*`),
6669
Blessed does the following:
@@ -71,14 +74,14 @@ Blessed does the following:
7174
- Sets `self.position.* = value` (e.g. `self.position.left = 30`)
7275
- Returns the (possibly casted) value that was set
7376

74-
Note from the above that values assigned to l/t/r/b are not kept in properties
77+
Take note above that values assigned to l/t/r/b are not kept in properties
7578
of the same name, but setting e.g. `rleft=(value)` actually saves the value to
7679
`self.position.left`.
7780

78-
Thus, it is these fields in `self.position.*` that contains values directly as
79-
specified by user (e.g. 30, "center", "30%" etc.)
81+
Thus, it is these fields in `self.position.*` that contain values directly as
82+
specified by user (e.g. 30, "center", "30%" etc.).
8083

81-
See more in `lib/widgets/element.js:1369` if interested.
84+
See more in Blessed's `lib/widgets/element.js:1369` if interested.
8285

8386
### Getters
8487

@@ -97,7 +100,7 @@ based on absolute coordinates. The code is simple:
97100

98101
### Setters
99102

100-
Setting `width` and `height` behaves the same as setting "r" fields:
103+
Setting `width` and `height` works the same like setting "r" fields described above:
101104

102105
- If value is an integer passed as a string, casts to int
103106
- Emits `Resize` event on self
@@ -123,7 +126,7 @@ If left or top value is 'center', then widget's size will be first set to 50% of
123126
The largest possible space (width or height) is calculated while taking all restrictions into account. In other words, the calculated space
124127
is limited by the size of parent, amount of parent's "i" values (inner thickness, explained below), and the current widget's desired left/top/right/bottom values.
125128

126-
Therefore, a value of null is very different from setting "100%". Setting 100% or any percentage translates to direct percentage of parent's size,
129+
Therefore, a value of null is very different from setting "100%". Setting 100% or any other percentage translates to direct percentage of parent's size,
127130
without accounting for "i" or desired left/top/right/bottom values.
128131

129132
## Absolute position
@@ -135,7 +138,7 @@ without accounting for "i" or desired left/top/right/bottom values.
135138

136139
### Setters
137140

138-
There is no place to store the absolute and relative position separately among widget's data (in `self.position.*`).
141+
There is no place in widgets' properties to store the absolute and relative position separately (in `self.position.*`).
139142

140143
Setting "a" values works similarly to the "r" values. Blessed just subtracts
141144
the parent's value from the current widget's value to convert absolute to
@@ -161,21 +164,21 @@ of the render. These coordinates are in essence the same as position and size in
161164
should match 1:1. The only exception/problem is if a widget is moved somehow and lpos values are not
162165
updated.
163166

164-
But, as Blessed's author says: "However, if we can guarantee that lpos is good and up to date, it can
165-
be more accurate than the calculated position.
167+
But, as Blessed's author says:
166168

169+
"However, if we can guarantee that lpos is good and up to date, it can be more accurate than the
170+
calculated position.
167171
If the element is being rendered, it's guaranteed that the parent will have been rendered first, in
168172
which case we can use the parent's lpos instead of recalculating its position (since that might be
169-
wrong because it doesn't handle content shrinkage)".
170-
171-
Thus, all getter functions have an optional parameter `get`, which defaults to false. When it is
172-
false, we simply use parent widget to access its width/height, "a" values and "i" values.
173+
wrong because it doesn't handle content shrinkage)."
173174

174-
When value of `get` is true, then Blessed does not use parent directly, but looks up its
175+
Thus, all getter functions have an optional parameter `get`, which defaults to false:
176+
- When it is false, we simply use parent widget to access its width/height, "a" values and "i" values.
177+
- When value of `get` is true, then Blessed does not use parent directly, but looks up its
175178
lpos. It returns parent's lpos as-is if its `aleft` (and implicitly all other 'a' values) are
176179
filled in. If they are not filled in, Blessed first produces them and then returns the lpos object
177-
which can be used in place of the parent. It produces "a" values based on screen width/height and
178-
xi...xl, yi...yl values that are/must be already present.
180+
which can be used in place of parent's calculated values. It produces "a" values based on screen
181+
width/height and xi...xl, yi...yl values that are/must be already present.
179182

180183
All position-related functions use `get=false`.
181184

@@ -235,3 +238,9 @@ them all inside `position` hash. If they're given separately, Blessed packs them
235238

236239
One can also specify `shrink = true` on a widget. This causes widget to render in minimal
237240
necessary box to accommodate its content.
241+
242+
## Changes in Crysterm
243+
244+
In Crysterm borders can be more than 1 cell big and can be set for each side separately.
245+
246+
Similarly, shadow size and sides can be chosen and set individually for each side.

examples/chat.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class MyProg
9090
end
9191
end
9292
chat.scroll_to chat.get_content.lines.size
93-
sleep rand 2
93+
sleep (rand 2).seconds
9494
lag.filled = rand 100
9595
s.render
9696
end

examples/colorchart.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ end
3333

3434
spawn do
3535
loop do
36-
sleep 1
36+
sleep 1.seconds
3737
s.render
3838
end
3939
end

examples/hello.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class MyProg
4343

4444
spawn do
4545
loop do
46-
sleep 2
46+
sleep 2.seconds
4747
b.clear_last_rendered_position
4848
b.top = rand(s.aheight - b.aheight - 1) + 1
4949
b.left = rand(s.awidth - b.awidth)

examples/tech-demo.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ module Crysterm
209209
end
210210
i += 1
211211
Fiber.yield
212-
sleep 0.2
212+
sleep 0.2.seconds
213213
end
214214
end
215215

small-tests/button.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class X
2222

2323
i.on(::Crysterm::Event::Press) do
2424
STDERR.puts "Pressed; exiting in 2 seconds"
25-
sleep 2
25+
sleep 2.seconds
2626
exit
2727
end
2828

small-tests/elements.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class X
3434

3535
i.on(::Crysterm::Event::Press) do
3636
STDERR.puts "Pressed; exiting in 2 seconds"
37-
sleep 2
37+
sleep 2.seconds
3838
exit
3939
end
4040

small-tests/pine.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module Crysterm
1818

1919
s.render
2020

21-
sleep 2
21+
sleep 2.seconds
2222

2323
sbar.status.set_content "[Already at {underline}bottom{/underline} of list]"
2424

0 commit comments

Comments
 (0)