Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ameba update block vars and if statements style #36

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/helpers.cr
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ module Crysterm
# Strips text of {...} tags and SGR sequences
def clean_tags(text)
combined_regex = /(?:#{Crysterm::Widget::TAG_REGEX.source})|(?:#{Crysterm::Widget::SGR_REGEX.source})/
text.gsub(combined_regex) do |buffer, _|
text.gsub(combined_regex) do |_, _|
# No replacement needed, just removing matches
end
end
Expand Down
4 changes: 2 additions & 2 deletions src/mixin/children.cr
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ module Crysterm

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

# Emits `ev` on all parent nodes.
def emit_ancestors(ev : EventHandler::Event | EventHandler::Event.class) : Nil
each_ancestor { |el| el.emit ev }
each_ancestor(&.emit(ev))
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/screen.cr
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ module Crysterm

# Push resize event to screens assigned to this display. We choose this approach
# because it results in less links between the components (as opposed to pull model).
@_resize_handler = GlobalEvents.on(::Crysterm::Event::Resize) do |e|
@_resize_handler = GlobalEvents.on(::Crysterm::Event::Resize) do |_|
schedule_resize
end
end
Expand Down
8 changes: 4 additions & 4 deletions src/screen_angles.cr
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module Crysterm
ch = lines[y][x].char

if lines[y][x - 1]? && L_ANGLES.includes? lines[y][x - 1].char
if (lines[y][x - 1].attr != attr)
if lines[y][x - 1].attr != attr
case @dock_contrast
when DockContrast::DontDock
return ch
Expand All @@ -62,7 +62,7 @@ module Crysterm
end

if lines[y - 1]? && U_ANGLES.includes? lines[y - 1][x].char
if (lines[y - 1][x].attr != attr)
if lines[y - 1][x].attr != attr
case @dock_contrast
when DockContrast::DontDock
return ch
Expand All @@ -76,7 +76,7 @@ module Crysterm
end

if lines[y][x + 1]? && R_ANGLES.includes? lines[y][x + 1].char
if (lines[y][x + 1].attr != attr)
if lines[y][x + 1].attr != attr
case @dock_contrast
when DockContrast::DontDock
return ch
Expand All @@ -90,7 +90,7 @@ module Crysterm
end

if lines[y + 1]? && D_ANGLES.includes? lines[y + 1][x].char
if (lines[y + 1][x].attr != attr)
if lines[y + 1][x].attr != attr
case @dock_contrast
when DockContrast::DontDock
return ch
Expand Down
36 changes: 18 additions & 18 deletions src/screen_attributes.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Crysterm
# i

code = code[2...-1].split(';')
if (!code[0]? || code[0].empty?)
if !code[0]? || code[0].empty?
code[0] = "0"
end

Expand Down Expand Up @@ -64,46 +64,46 @@ module Crysterm
bg = dfl & 0x1ff
break
else # color
if (c == 48 && code[i + 1].to_i == 5)
if c == 48 && code[i + 1].to_i == 5
i += 2
bg = code[i].to_i
break
elsif (c == 48 && code[i + 1].to_i == 2)
elsif c == 48 && code[i + 1].to_i == 2
i += 2
bg = Colors.match(code[i].to_i, code[i + 1].to_i, code[i + 2].to_i)
if (bg == -1)
if bg == -1
bg = dfl & 0x1ff
end
i += 2
break
elsif (c == 38 && code[i + 1].to_i == 5)
elsif c == 38 && code[i + 1].to_i == 5
i += 2
fg = code[i].to_i
break
elsif (c == 38 && code[i + 1].to_i == 2)
elsif c == 38 && code[i + 1].to_i == 2
i += 2
fg = Colors.match(code[i].to_i, code[i + 1].to_i, code[i + 2].to_i)
if (fg == -1)
if fg == -1
fg = (dfl >> 9) & 0x1ff
end
i += 2 # XXX Why ameba says this is no-op?
break
end
if (c >= 40 && c <= 47)
if c >= 40 && c <= 47
bg = c - 40
elsif (c >= 100 && c <= 107)
elsif c >= 100 && c <= 107
bg = c - 100
bg += 8
elsif (c == 49)
elsif c == 49
bg = dfl & 0x1ff
elsif (c >= 30 && c <= 37)
elsif c >= 30 && c <= 37
fg = c - 30
elsif (c >= 90 && c <= 97)
elsif c >= 90 && c <= 97
fg = c - 90
fg += 8
elsif (c == 39)
elsif c == 39
fg = (dfl >> 9) & 0x1ff
elsif (c == 100)
elsif c == 100
fg = (dfl >> 9) & 0x1ff
bg = dfl & 0x1ff
end
Expand Down Expand Up @@ -138,18 +138,18 @@ module Crysterm
# invisible
outbuf << "8;" if (flags & 16) != 0

if (bg != 0x1ff)
if bg != 0x1ff
bg = _reduce_color(bg)
if (bg < 16)
if bg < 16
bg < 8 ? outbuf << (bg + 40) << ';' : outbuf << (bg - 8 + 100) << ';'
else
outbuf << "48;5;" << bg << ';'
end
end

if (fg != 0x1ff)
if fg != 0x1ff
fg = _reduce_color(fg)
if (fg < 16)
if fg < 16
fg < 8 ? outbuf << (fg + 30) << ';' : outbuf << (fg - 8 + 90) << ';'
else
outbuf << "38;5;" << fg << ';'
Expand Down
52 changes: 26 additions & 26 deletions src/screen_drawing.cr
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ module Crysterm
# ::Log.trace { line } if line.any? &.char.!=(' ')

# Skip if no change in line
if (!line.dirty && !(c.artificial? && (y == tput.cursor.y)))
if !line.dirty && !(c.artificial? && (y == tput.cursor.y))
next
end

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

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

Expand Down Expand Up @@ -226,34 +226,34 @@ module Crysterm

flags = desired_attr >> 18
# bold
if ((flags & 1) != 0)
if (flags & 1) != 0
@outbuf.print "1;"
end

# underline
if ((flags & 2) != 0)
if (flags & 2) != 0
@outbuf.print "4;"
end

# blink
if ((flags & 4) != 0)
if (flags & 4) != 0
@outbuf.print "5;"
end

# inverse
if ((flags & 8) != 0)
if (flags & 8) != 0
@outbuf.print "7;"
end

# invisible
if ((flags & 16) != 0)
if (flags & 16) != 0
@outbuf.print "8;"
end

if (bg != 0x1ff)
if bg != 0x1ff
bg = _reduce_color(bg)
if (bg < 16)
if (bg < 8)
if bg < 16
if bg < 8
bg += 40
else # elsif (bg < 16)
bg -= 8
Expand All @@ -265,10 +265,10 @@ module Crysterm
end
end

if (fg != 0x1ff)
if fg != 0x1ff
fg = _reduce_color(fg)
if (fg < 16)
if (fg < 8)
if fg < 16
if fg < 8
fg += 30
else # elsif (fg < 16)
fg -= 8
Expand Down Expand Up @@ -339,7 +339,7 @@ module Crysterm
# case that the contents of the IF/ELSE block change in incompatible
# way, this should be had in mind.
if s
if (s.enter_alt_charset_mode? && !tput.features.broken_acs? && (tput.features.acscr[desired_char]? || acs))
if s.enter_alt_charset_mode? && !tput.features.broken_acs? && (tput.features.acscr[desired_char]? || acs)
# Fun fact: even if tput.brokenACS wasn't checked here,
# the linux console would still work fine because the acs
# table would fail the check of: tput.features.acscr[desired_char]
Expand Down Expand Up @@ -380,7 +380,7 @@ module Crysterm
# Note: It could be the case that the $LANG
# is all that matters in some cases:
# if (!tput.unicode && desired_char > '~') {
if (!tput.features.unicode? && (tput.terminfo.try(&.extensions.get_num?("U8")) != 1) && (desired_char > '~'))
if !tput.features.unicode? && (tput.terminfo.try(&.extensions.get_num?("U8")) != 1) && (desired_char > '~')
# Reduction of ACS into ASCII chars.
desired_char = Tput::ACSC::Data[desired_char]?.try(&.[2]) || '?'
end
Expand All @@ -403,7 +403,7 @@ module Crysterm
end
end

if (acs)
if acs
@main.write s.rmacs
acs = false
end
Expand Down Expand Up @@ -460,9 +460,9 @@ module Crysterm
# return insert_line_nc(n, y, top, bottom)
# end

if (!tput.has?(&.change_scroll_region?) ||
if !tput.has?(&.change_scroll_region?) ||
!tput.has?(&.delete_line?) ||
!tput.has?(&.insert_line?))
!tput.has?(&.insert_line?)
STDERR.puts "Missing needed terminfo capabilities"
return
end
Expand Down Expand Up @@ -493,8 +493,8 @@ module Crysterm
# Scroll down (up cursor-wise).
# This will only work for top line deletion as opposed to arbitrary lines.
def insert_line_nc(n, y, top, bottom)
if (!tput.has?(&.change_scroll_region?) ||
!tput.has?(&.delete_line?))
if !tput.has?(&.change_scroll_region?) ||
!tput.has?(&.delete_line?)
STDERR.puts "Missing needed terminfo capabilities"
return
end
Expand Down Expand Up @@ -526,9 +526,9 @@ module Crysterm
# return delete_line_nc(n, y, top, bottom)
# end

if (!tput.has?(&.change_scroll_region?) ||
if !tput.has?(&.change_scroll_region?) ||
!tput.has?(&.delete_line?) ||
!tput.has?(&.insert_line?))
!tput.has?(&.insert_line?)
STDERR.puts "Missing needed terminfo capabilities"
return
end
Expand Down Expand Up @@ -560,8 +560,8 @@ module Crysterm
# Scroll down (up cursor-wise).
# This will only work for top line deletion as opposed to arbitrary lines.
def delete_line_nc(n, y, top, bottom)
if (!tput.has?(&.change_scroll_region?) ||
!tput.has?(&.delete_line?))
if !tput.has?(&.change_scroll_region?) ||
!tput.has?(&.delete_line?)
STDERR.puts "Missing needed terminfo capabilities"
return
end
Expand Down
2 changes: 1 addition & 1 deletion src/screen_interaction.cr
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ module Crysterm
# first gets the keys, then potentially passes onto children
# elements.
def _listen_keys(el : Widget? = nil)
if (el && [email protected]? el)
if el && [email protected]? el
el.keyable = true
@keyable.push el
end
Expand Down
6 changes: 3 additions & 3 deletions src/widget/bigtext.cr
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ module Crysterm
end

def render
if (@width.nil? || @_shrink_width)
if @width.nil? || @_shrink_width
# D O:
# if (awidth - iwidth < @ratio.width * @text.length + 1)
@width = @ratio.width * @text.size + 1
@_shrink_width = true
# end
end
if (@height.nil? || @_shrink_height)
if @height.nil? || @_shrink_height
# D O:
# if (aheight - iheight < @ratio.height + 0)
@height = @ratio.height
Expand Down Expand Up @@ -146,7 +146,7 @@ module Crysterm
break if mcell.nil?

lines[y]?.try(&.[x + mx]?).try do |cell|
if (style.fchar != ' ')
if style.fchar != ' '
cell.attr = default_attr
cell.char = mcell == 1 ? style.fchar : style.char
else
Expand Down
4 changes: 2 additions & 2 deletions src/widget/input.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ module Crysterm
key = e.key
ch = e.char

if (key == Tput::Key::Up || (@vi && ch == 'k'))
if key == Tput::Key::Up || (@vi && ch == 'k')
scroll(-1)
self.screen.render
next
end
if (key == Tput::Key::Down || (@vi && ch == 'j'))
if key == Tput::Key::Down || (@vi && ch == 'j')
scroll(1)
self.screen.render
next
Expand Down
Loading
Loading