Skip to content

Commit 2a2b91a

Browse files
authored
Merge pull request #36 from jkthorne/master
ameba update block vars and if statements style
2 parents f5e55f0 + d99c000 commit 2a2b91a

20 files changed

+139
-139
lines changed

src/helpers.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ module Crysterm
108108
# Strips text of {...} tags and SGR sequences
109109
def clean_tags(text)
110110
combined_regex = /(?:#{Crysterm::Widget::TAG_REGEX.source})|(?:#{Crysterm::Widget::SGR_REGEX.source})/
111-
text.gsub(combined_regex) do |buffer, _|
111+
text.gsub(combined_regex) do |_, _|
112112
# No replacement needed, just removing matches
113113
end
114114
end

src/mixin/children.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ module Crysterm
130130

131131
# Emits `ev` on all children nodes, recursively.
132132
def emit_descendants(ev : EventHandler::Event | EventHandler::Event.class) : Nil
133-
each_descendant { |el| el.emit ev }
133+
each_descendant(&.emit(ev))
134134
end
135135

136136
# Emits `ev` on all parent nodes.
137137
def emit_ancestors(ev : EventHandler::Event | EventHandler::Event.class) : Nil
138-
each_ancestor { |el| el.emit ev }
138+
each_ancestor(&.emit(ev))
139139
end
140140
end
141141
end

src/screen.cr

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

215215
# Push resize event to screens assigned to this display. We choose this approach
216216
# because it results in less links between the components (as opposed to pull model).
217-
@_resize_handler = GlobalEvents.on(::Crysterm::Event::Resize) do |e|
217+
@_resize_handler = GlobalEvents.on(::Crysterm::Event::Resize) do |_|
218218
schedule_resize
219219
end
220220
end

src/screen_angles.cr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module Crysterm
4848
ch = lines[y][x].char
4949

5050
if lines[y][x - 1]? && L_ANGLES.includes? lines[y][x - 1].char
51-
if (lines[y][x - 1].attr != attr)
51+
if lines[y][x - 1].attr != attr
5252
case @dock_contrast
5353
when DockContrast::DontDock
5454
return ch
@@ -62,7 +62,7 @@ module Crysterm
6262
end
6363

6464
if lines[y - 1]? && U_ANGLES.includes? lines[y - 1][x].char
65-
if (lines[y - 1][x].attr != attr)
65+
if lines[y - 1][x].attr != attr
6666
case @dock_contrast
6767
when DockContrast::DontDock
6868
return ch
@@ -76,7 +76,7 @@ module Crysterm
7676
end
7777

7878
if lines[y][x + 1]? && R_ANGLES.includes? lines[y][x + 1].char
79-
if (lines[y][x + 1].attr != attr)
79+
if lines[y][x + 1].attr != attr
8080
case @dock_contrast
8181
when DockContrast::DontDock
8282
return ch
@@ -90,7 +90,7 @@ module Crysterm
9090
end
9191

9292
if lines[y + 1]? && D_ANGLES.includes? lines[y + 1][x].char
93-
if (lines[y + 1][x].attr != attr)
93+
if lines[y + 1][x].attr != attr
9494
case @dock_contrast
9595
when DockContrast::DontDock
9696
return ch

src/screen_attributes.cr

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module Crysterm
1111
# i
1212

1313
code = code[2...-1].split(';')
14-
if (!code[0]? || code[0].empty?)
14+
if !code[0]? || code[0].empty?
1515
code[0] = "0"
1616
end
1717

@@ -64,46 +64,46 @@ module Crysterm
6464
bg = dfl & 0x1ff
6565
break
6666
else # color
67-
if (c == 48 && code[i + 1].to_i == 5)
67+
if c == 48 && code[i + 1].to_i == 5
6868
i += 2
6969
bg = code[i].to_i
7070
break
71-
elsif (c == 48 && code[i + 1].to_i == 2)
71+
elsif c == 48 && code[i + 1].to_i == 2
7272
i += 2
7373
bg = Colors.match(code[i].to_i, code[i + 1].to_i, code[i + 2].to_i)
74-
if (bg == -1)
74+
if bg == -1
7575
bg = dfl & 0x1ff
7676
end
7777
i += 2
7878
break
79-
elsif (c == 38 && code[i + 1].to_i == 5)
79+
elsif c == 38 && code[i + 1].to_i == 5
8080
i += 2
8181
fg = code[i].to_i
8282
break
83-
elsif (c == 38 && code[i + 1].to_i == 2)
83+
elsif c == 38 && code[i + 1].to_i == 2
8484
i += 2
8585
fg = Colors.match(code[i].to_i, code[i + 1].to_i, code[i + 2].to_i)
86-
if (fg == -1)
86+
if fg == -1
8787
fg = (dfl >> 9) & 0x1ff
8888
end
8989
i += 2 # XXX Why ameba says this is no-op?
9090
break
9191
end
92-
if (c >= 40 && c <= 47)
92+
if c >= 40 && c <= 47
9393
bg = c - 40
94-
elsif (c >= 100 && c <= 107)
94+
elsif c >= 100 && c <= 107
9595
bg = c - 100
9696
bg += 8
97-
elsif (c == 49)
97+
elsif c == 49
9898
bg = dfl & 0x1ff
99-
elsif (c >= 30 && c <= 37)
99+
elsif c >= 30 && c <= 37
100100
fg = c - 30
101-
elsif (c >= 90 && c <= 97)
101+
elsif c >= 90 && c <= 97
102102
fg = c - 90
103103
fg += 8
104-
elsif (c == 39)
104+
elsif c == 39
105105
fg = (dfl >> 9) & 0x1ff
106-
elsif (c == 100)
106+
elsif c == 100
107107
fg = (dfl >> 9) & 0x1ff
108108
bg = dfl & 0x1ff
109109
end
@@ -138,18 +138,18 @@ module Crysterm
138138
# invisible
139139
outbuf << "8;" if (flags & 16) != 0
140140

141-
if (bg != 0x1ff)
141+
if bg != 0x1ff
142142
bg = _reduce_color(bg)
143-
if (bg < 16)
143+
if bg < 16
144144
bg < 8 ? outbuf << (bg + 40) << ';' : outbuf << (bg - 8 + 100) << ';'
145145
else
146146
outbuf << "48;5;" << bg << ';'
147147
end
148148
end
149149

150-
if (fg != 0x1ff)
150+
if fg != 0x1ff
151151
fg = _reduce_color(fg)
152-
if (fg < 16)
152+
if fg < 16
153153
fg < 8 ? outbuf << (fg + 30) << ';' : outbuf << (fg - 8 + 90) << ';'
154154
else
155155
outbuf << "38;5;" << fg << ';'

src/screen_drawing.cr

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ module Crysterm
7070
# ::Log.trace { line } if line.any? &.char.!=(' ')
7171

7272
# Skip if no change in line
73-
if (!line.dirty && !(c.artificial? && (y == tput.cursor.y)))
73+
if !line.dirty && !(c.artificial? && (y == tput.cursor.y))
7474
next
7575
end
7676

@@ -92,7 +92,7 @@ module Crysterm
9292
desired_char = line[x].char
9393

9494
# Render the artificial cursor.
95-
if (c.artificial? && !c._hidden && (c._state != 0) && (x == tput.cursor.x) && (y == tput.cursor.y))
95+
if c.artificial? && !c._hidden && (c._state != 0) && (x == tput.cursor.x) && (y == tput.cursor.y)
9696
desired_attr, tmpch = _artificial_cursor_attr(c, desired_attr)
9797
desired_char = tmpch if tmpch
9898
# XXX Is this needed:
@@ -101,9 +101,9 @@ module Crysterm
101101
# Take advantage of xterm's back_color_erase feature by using a
102102
# lookahead. Stop spitting out so many damn spaces. NOTE: Is checking
103103
# the bg for non BCE terminals worth the overhead?
104-
if (@optimization.bce? && (desired_char == ' ') &&
104+
if @optimization.bce? && (desired_char == ' ') &&
105105
(tput.has?(&.back_color_erase?) || ((desired_attr & 0x1ff) == (@default_attr & 0x1ff))) &&
106-
(((desired_attr >> 18) & 8) == ((@default_attr >> 18) & 8)))
106+
(((desired_attr >> 18) & 8) == ((@default_attr >> 18) & 8))
107107
clr = true
108108
neq = false # Current line 'not equal' to line as it was on previous render (i.e. it changed content)
109109

@@ -226,34 +226,34 @@ module Crysterm
226226

227227
flags = desired_attr >> 18
228228
# bold
229-
if ((flags & 1) != 0)
229+
if (flags & 1) != 0
230230
@outbuf.print "1;"
231231
end
232232

233233
# underline
234-
if ((flags & 2) != 0)
234+
if (flags & 2) != 0
235235
@outbuf.print "4;"
236236
end
237237

238238
# blink
239-
if ((flags & 4) != 0)
239+
if (flags & 4) != 0
240240
@outbuf.print "5;"
241241
end
242242

243243
# inverse
244-
if ((flags & 8) != 0)
244+
if (flags & 8) != 0
245245
@outbuf.print "7;"
246246
end
247247

248248
# invisible
249-
if ((flags & 16) != 0)
249+
if (flags & 16) != 0
250250
@outbuf.print "8;"
251251
end
252252

253-
if (bg != 0x1ff)
253+
if bg != 0x1ff
254254
bg = _reduce_color(bg)
255-
if (bg < 16)
256-
if (bg < 8)
255+
if bg < 16
256+
if bg < 8
257257
bg += 40
258258
else # elsif (bg < 16)
259259
bg -= 8
@@ -265,10 +265,10 @@ module Crysterm
265265
end
266266
end
267267

268-
if (fg != 0x1ff)
268+
if fg != 0x1ff
269269
fg = _reduce_color(fg)
270-
if (fg < 16)
271-
if (fg < 8)
270+
if fg < 16
271+
if fg < 8
272272
fg += 30
273273
else # elsif (fg < 16)
274274
fg -= 8
@@ -339,7 +339,7 @@ module Crysterm
339339
# case that the contents of the IF/ELSE block change in incompatible
340340
# way, this should be had in mind.
341341
if s
342-
if (s.enter_alt_charset_mode? && !tput.features.broken_acs? && (tput.features.acscr[desired_char]? || acs))
342+
if s.enter_alt_charset_mode? && !tput.features.broken_acs? && (tput.features.acscr[desired_char]? || acs)
343343
# Fun fact: even if tput.brokenACS wasn't checked here,
344344
# the linux console would still work fine because the acs
345345
# table would fail the check of: tput.features.acscr[desired_char]
@@ -380,7 +380,7 @@ module Crysterm
380380
# Note: It could be the case that the $LANG
381381
# is all that matters in some cases:
382382
# if (!tput.unicode && desired_char > '~') {
383-
if (!tput.features.unicode? && (tput.terminfo.try(&.extensions.get_num?("U8")) != 1) && (desired_char > '~'))
383+
if !tput.features.unicode? && (tput.terminfo.try(&.extensions.get_num?("U8")) != 1) && (desired_char > '~')
384384
# Reduction of ACS into ASCII chars.
385385
desired_char = Tput::ACSC::Data[desired_char]?.try(&.[2]) || '?'
386386
end
@@ -403,7 +403,7 @@ module Crysterm
403403
end
404404
end
405405

406-
if (acs)
406+
if acs
407407
@main.write s.rmacs
408408
acs = false
409409
end
@@ -460,9 +460,9 @@ module Crysterm
460460
# return insert_line_nc(n, y, top, bottom)
461461
# end
462462

463-
if (!tput.has?(&.change_scroll_region?) ||
463+
if !tput.has?(&.change_scroll_region?) ||
464464
!tput.has?(&.delete_line?) ||
465-
!tput.has?(&.insert_line?))
465+
!tput.has?(&.insert_line?)
466466
STDERR.puts "Missing needed terminfo capabilities"
467467
return
468468
end
@@ -493,8 +493,8 @@ module Crysterm
493493
# Scroll down (up cursor-wise).
494494
# This will only work for top line deletion as opposed to arbitrary lines.
495495
def insert_line_nc(n, y, top, bottom)
496-
if (!tput.has?(&.change_scroll_region?) ||
497-
!tput.has?(&.delete_line?))
496+
if !tput.has?(&.change_scroll_region?) ||
497+
!tput.has?(&.delete_line?)
498498
STDERR.puts "Missing needed terminfo capabilities"
499499
return
500500
end
@@ -526,9 +526,9 @@ module Crysterm
526526
# return delete_line_nc(n, y, top, bottom)
527527
# end
528528

529-
if (!tput.has?(&.change_scroll_region?) ||
529+
if !tput.has?(&.change_scroll_region?) ||
530530
!tput.has?(&.delete_line?) ||
531-
!tput.has?(&.insert_line?))
531+
!tput.has?(&.insert_line?)
532532
STDERR.puts "Missing needed terminfo capabilities"
533533
return
534534
end
@@ -560,8 +560,8 @@ module Crysterm
560560
# Scroll down (up cursor-wise).
561561
# This will only work for top line deletion as opposed to arbitrary lines.
562562
def delete_line_nc(n, y, top, bottom)
563-
if (!tput.has?(&.change_scroll_region?) ||
564-
!tput.has?(&.delete_line?))
563+
if !tput.has?(&.change_scroll_region?) ||
564+
!tput.has?(&.delete_line?)
565565
STDERR.puts "Missing needed terminfo capabilities"
566566
return
567567
end

src/screen_interaction.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ module Crysterm
7777
# first gets the keys, then potentially passes onto children
7878
# elements.
7979
def _listen_keys(el : Widget? = nil)
80-
if (el && !@keyable.includes? el)
80+
if el && !@keyable.includes? el
8181
el.keyable = true
8282
@keyable.push el
8383
end

src/widget/bigtext.cr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ module Crysterm
9393
end
9494

9595
def render
96-
if (@width.nil? || @_shrink_width)
96+
if @width.nil? || @_shrink_width
9797
# D O:
9898
# if (awidth - iwidth < @ratio.width * @text.length + 1)
9999
@width = @ratio.width * @text.size + 1
100100
@_shrink_width = true
101101
# end
102102
end
103-
if (@height.nil? || @_shrink_height)
103+
if @height.nil? || @_shrink_height
104104
# D O:
105105
# if (aheight - iheight < @ratio.height + 0)
106106
@height = @ratio.height
@@ -146,7 +146,7 @@ module Crysterm
146146
break if mcell.nil?
147147

148148
lines[y]?.try(&.[x + mx]?).try do |cell|
149-
if (style.fchar != ' ')
149+
if style.fchar != ' '
150150
cell.attr = default_attr
151151
cell.char = mcell == 1 ? style.fchar : style.char
152152
else

src/widget/input.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ module Crysterm
1515
key = e.key
1616
ch = e.char
1717

18-
if (key == Tput::Key::Up || (@vi && ch == 'k'))
18+
if key == Tput::Key::Up || (@vi && ch == 'k')
1919
scroll(-1)
2020
self.screen.render
2121
next
2222
end
23-
if (key == Tput::Key::Down || (@vi && ch == 'j'))
23+
if key == Tput::Key::Down || (@vi && ch == 'j')
2424
scroll(1)
2525
self.screen.render
2626
next

0 commit comments

Comments
 (0)