From d99c00091236672673b787adfa77ab2321985900 Mon Sep 17 00:00:00 2001 From: Jack Thorne Date: Tue, 12 Nov 2024 21:59:56 -0600 Subject: [PATCH] ameba update block vars and if statements style --- src/helpers.cr | 2 +- src/mixin/children.cr | 4 +-- src/screen.cr | 2 +- src/screen_angles.cr | 8 +++--- src/screen_attributes.cr | 36 +++++++++++++-------------- src/screen_drawing.cr | 52 +++++++++++++++++++-------------------- src/screen_interaction.cr | 2 +- src/widget/bigtext.cr | 6 ++--- src/widget/input.cr | 4 +-- src/widget/layout.cr | 18 +++++++------- src/widget/message.cr | 2 +- src/widget/question.cr | 2 +- src/widget/textarea.cr | 12 ++++----- src/widget_children.cr | 2 +- src/widget_content.cr | 52 +++++++++++++++++++-------------------- src/widget_rendering.cr | 28 ++++++++++----------- src/widget_scrolling.cr | 24 +++++++++--------- src/widget_size.cr | 16 ++++++------ test-auto/hello/main.cr | 2 +- test/widget-prompt.cr | 4 +-- 20 files changed, 139 insertions(+), 139 deletions(-) diff --git a/src/helpers.cr b/src/helpers.cr index 9032c2d..e7dc4cb 100644 --- a/src/helpers.cr +++ b/src/helpers.cr @@ -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 diff --git a/src/mixin/children.cr b/src/mixin/children.cr index 59f9aa9..c648c42 100644 --- a/src/mixin/children.cr +++ b/src/mixin/children.cr @@ -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 diff --git a/src/screen.cr b/src/screen.cr index 8b44245..a207d09 100644 --- a/src/screen.cr +++ b/src/screen.cr @@ -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 diff --git a/src/screen_angles.cr b/src/screen_angles.cr index 9877960..a7b28a4 100644 --- a/src/screen_angles.cr +++ b/src/screen_angles.cr @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/src/screen_attributes.cr b/src/screen_attributes.cr index 57b1cd3..7d65ef1 100644 --- a/src/screen_attributes.cr +++ b/src/screen_attributes.cr @@ -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 @@ -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 @@ -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 << ';' diff --git a/src/screen_drawing.cr b/src/screen_drawing.cr index 4210b21..8bb725c 100644 --- a/src/screen_drawing.cr +++ b/src/screen_drawing.cr @@ -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 @@ -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: @@ -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) @@ -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 @@ -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 @@ -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] @@ -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 @@ -403,7 +403,7 @@ module Crysterm end end - if (acs) + if acs @main.write s.rmacs acs = false end @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/src/screen_interaction.cr b/src/screen_interaction.cr index 8cd635c..e5aac30 100644 --- a/src/screen_interaction.cr +++ b/src/screen_interaction.cr @@ -77,7 +77,7 @@ module Crysterm # first gets the keys, then potentially passes onto children # elements. def _listen_keys(el : Widget? = nil) - if (el && !@keyable.includes? el) + if el && !@keyable.includes? el el.keyable = true @keyable.push el end diff --git a/src/widget/bigtext.cr b/src/widget/bigtext.cr index 6d283d5..c9b86c4 100644 --- a/src/widget/bigtext.cr +++ b/src/widget/bigtext.cr @@ -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 @@ -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 diff --git a/src/widget/input.cr b/src/widget/input.cr index b3a14a8..63ae939 100644 --- a/src/widget/input.cr +++ b/src/widget/input.cr @@ -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 diff --git a/src/widget/layout.cr b/src/widget/layout.cr index 3cdecbd..70d055d 100644 --- a/src/widget/layout.cr +++ b/src/widget/layout.cr @@ -91,7 +91,7 @@ module Crysterm el.left = llp.xl - xi # Make sure the position matches the highest width element - if (@layout == LayoutType::Grid) + if @layout == LayoutType::Grid # D O: # Compensate with width: # el.width = el.awidth + (highWidth - el.awidth) @@ -124,20 +124,20 @@ module Crysterm end # Make sure the elements on lower rows gravitate up as much as possible - if (@layout == LayoutType::Inline) + if @layout == LayoutType::Inline above = nil abovea = Int32::MAX j = last_row_index while j < row_index l = @children[j] - if (!rendered?(l)) + if !rendered?(l) j += 1 next end abs = (el.left.as(Int) - (l.lpos.not_nil!.xi - xi)).abs # D O: # if (abs < abovea && (l.lpos.xl - l.lpos.xi) <= el.awidth) - if (abs < abovea) + if abs < abovea above = l abovea = abs end @@ -151,7 +151,7 @@ module Crysterm # If our child overflows the Layout, return @overflow which contains # instruction what to do. - if (el.top.as(Int) + el.height.as(Int) > height) + if el.top.as(Int) + el.height.as(Int) > height return @overflow end } @@ -161,17 +161,17 @@ module Crysterm _emit Crysterm::Event::PreRender coords = _render_coords - if (!coords) + if !coords @lpos = nil return end - if (coords.xl - coords.xi <= 0) + if coords.xl - coords.xi <= 0 coords.xl = Math.max(coords.xl, coords.xi) return end - if (coords.yl - coords.yi <= 0) + if coords.yl - coords.yi <= 0 coords.yl = Math.max(coords.yl, coords.yi) return end @@ -187,7 +187,7 @@ module Crysterm style.padding.try &.adjust(coords, -1) @children.each_with_index do |el, i| - if (el.screen._ci != -1) + if el.screen._ci != -1 el.index = el.screen._ci el.screen._ci += 1 end diff --git a/src/widget/message.cr b/src/widget/message.cr index 26914e9..28c64ed 100644 --- a/src/widget/message.cr +++ b/src/widget/message.cr @@ -27,7 +27,7 @@ module Crysterm spawn do sleep 10.seconds - @ev_keypress = screen.on(Crysterm::Event::KeyPress) do |e| + @ev_keypress = screen.on(Crysterm::Event::KeyPress) do |_| # ##return if e.key.try(&.name) == ::Tput::Key::Mouse # XXX # #if scrollable? # # if (e.key == ::Tput::Key::Up) || # || (@vi && e.char == 'k') # XXX diff --git a/src/widget/question.cr b/src/widget/question.cr index f7470f1..d0d5bf2 100644 --- a/src/widget/question.cr +++ b/src/widget/question.cr @@ -74,7 +74,7 @@ module Crysterm c = e.char k = e.key - if (k != Tput::Key::Enter && k != Tput::Key::Escape && c != 'q' && c != 'y' && c != 'n') + if k != Tput::Key::Enter && k != Tput::Key::Escape && c != 'q' && c != 'y' && c != 'n' next end diff --git a/src/widget/textarea.cr b/src/widget/textarea.cr index 3e61c8d..d689e65 100644 --- a/src/widget/textarea.cr +++ b/src/widget/textarea.cr @@ -112,16 +112,16 @@ module Crysterm # That check is redundant because the below logic also does # the same (no-op if cursor is already at coords.) - if (cy == display.tput.cursor.y) - if (cx > display.tput.cursor.x) + if cy == display.tput.cursor.y + if cx > display.tput.cursor.x display.tput.cuf(cx - display.tput.cursor.x) - elsif (cx < display.tput.cursor.x) + elsif cx < display.tput.cursor.x display.tput.cub(display.tput.cursor.x - cx) end - elsif (cx == display.tput.cursor.x) - if (cy > display.tput.cursor.y) + elsif cx == display.tput.cursor.x + if cy > display.tput.cursor.y display.tput.cud(cy - display.tput.cursor.y) - elsif (cy < display.tput.cursor.y) + elsif cy < display.tput.cursor.y display.tput.cuu(display.tput.cursor.y - cy) end else diff --git a/src/widget_children.cr b/src/widget_children.cr index ad94114..940dfba 100644 --- a/src/widget_children.cr +++ b/src/widget_children.cr @@ -7,7 +7,7 @@ module Crysterm # Removes node from its parent. # This is identical to calling `parent.remove(self)`. def remove_from_parent - @parent.try { |p| p.remove self } + @parent.try(&.remove(self)) end # Inserts `element` to list of children at a specified position (at end by default) diff --git a/src/widget_content.cr b/src/widget_content.cr index 1f12d7d..b85938d 100644 --- a/src/widget_content.cr +++ b/src/widget_content.cr @@ -89,7 +89,7 @@ module Crysterm ::Log.trace { "Parsing widget content: #{@content.inspect}" } colwidth = awidth - iwidth - if (@_clines.nil? || @_clines.empty? || @_clines.width != colwidth || @_clines.content != @content) + if @_clines.nil? || @_clines.empty? || @_clines.width != colwidth || @_clines.content != @content content = @content.gsub(/[\x00-\x08\x0b-\x0c\x0e-\x1a\x1c-\x1f\x7f]/, "") .gsub(/\e(?!\[[\d;]*m)/, "") # SGR @@ -271,9 +271,9 @@ module Crysterm attrs.push attr raise "indexing error" unless attrs.size == j + 1 - line.chars.each_with_index do |char, i| + line.chars.each_with_index do |char, _| if char == '\e' - if (c = line[1..].match(SGR_REGEX)) + if c = line[1..].match(SGR_REGEX) attr = screen.attr2code(c[0], attr, default_attr) end end @@ -306,7 +306,7 @@ module Crysterm margin += 1 if @scrollbar margin += 1 if is_a? Widget::TextArea - colwidth -= margin if (colwidth > margin) + colwidth -= margin if colwidth > margin lines.each_with_index do |line, no| align = default_state @@ -346,12 +346,12 @@ module Crysterm # NOTE Done with loop+break due to https://github.com/crystal-lang/crystal/issues/1277 loop do break unless i < line.size - while (line[i] == '\e') - while (line[i] && line[i] != 'm') + while line[i] == '\e' + while line[i] && line[i] != 'm' i += 1 end end - if (line[i]?.nil?) + if line[i]?.nil? break end total += 1 @@ -370,12 +370,12 @@ module Crysterm # XXX TODO # if (!screen.fullUnicode) # Try to find a char to break on. - if (i != line.size) + if i != line.size j = i # TODO how can the condition and subsequent IF ever match # with the line[j] thing? - while ((j > i - 10) && (j > 0) && (j -= 1) && (line[j] != ' ')) - if (line[j] == ' ') + while (j > i - 10) && (j > 0) && (j -= 1) && (line[j] != ' ') + if line[j] == ' ' i = j + 1 end end @@ -400,7 +400,7 @@ module Crysterm end # If only an escape code got cut off, add it to `part`. - if (line.matches? /^(?:\e[\[\d;]*m)+$/) # SGR + if line.matches? /^(?:\e[\[\d;]*m)+$/ # SGR outbuf[outbuf.size - 1] += line break :main end @@ -501,17 +501,17 @@ module Crysterm end def insert_line(i = nil, line = "") - if (line.is_a? String) + if line.is_a? String line = line.split("\n") end - if (i.nil?) + if i.nil? i = @_clines.ftor.size end i = Math.max(i, 0) - while (@_clines.fake.size < i) + while @_clines.fake.size < i @_clines.fake.push("") @_clines.ftor.push([@_clines.push("").size - 1]) @_clines.rtof[@_clines.fake.size - 1] @@ -523,7 +523,7 @@ module Crysterm # diff # real - if (i >= @_clines.ftor.size) + if i >= @_clines.ftor.size real = @_clines.ftor[@_clines.ftor.size - 1] real = real[-1] + 1 else @@ -538,9 +538,9 @@ module Crysterm diff = @_clines.size - start - if (diff > 0) + if diff > 0 pos = _get_coords - if (!pos || pos == 0) + if !pos || pos == 0 return end @@ -548,7 +548,7 @@ module Crysterm base = @child_base visible = real >= base && real - base < height - if (pos && visible && screen.clean_sides(self)) + if pos && visible && screen.clean_sides(self) screen.insert_line(diff, pos.yi + itop + real - base, pos.yi, @@ -558,7 +558,7 @@ module Crysterm end def delete_line(i = nil, n = 1) - if (i.nil?) + if i.nil? i = @_clines.ftor.size - 1 end @@ -571,7 +571,7 @@ module Crysterm # diff real = @_clines.ftor[i][0] - while (n > 0) + while n > 0 n -= 1 @_clines.fake.delete_at i end @@ -583,9 +583,9 @@ module Crysterm # XXX clear_last_rendered_position() without diff statement? height = 0 - if (diff > 0) + if diff > 0 pos = _get_coords - if (!pos || pos == 0) + if !pos || pos == 0 return end @@ -594,7 +594,7 @@ module Crysterm base = @child_base visible = real >= base && real - base < height - if (pos && visible && screen.clean_sides(self)) + if pos && visible && screen.clean_sides(self) screen.delete_line(diff, pos.yi + itop + real - base, pos.yi, @@ -602,7 +602,7 @@ module Crysterm end end - if (@_clines.size < height) + if @_clines.size < height clear_last_rendered_position end end @@ -637,7 +637,7 @@ module Crysterm def set_line(i, line) i = Math.max(i, 0) - while (@_clines.fake.size < i) + while @_clines.fake.size < i @_clines.fake.push("") end @_clines.fake[i] = line @@ -679,7 +679,7 @@ module Crysterm end def push_line(line) - if (!@content) + if !@content return set_line(0, line) end insert_line(@_clines.fake.size, line) diff --git a/src/widget_rendering.cr b/src/widget_rendering.cr index 78d138e..3e434ff 100644 --- a/src/widget_rendering.cr +++ b/src/widget_rendering.cr @@ -51,12 +51,12 @@ module Crysterm return end - if (coords.xl - coords.xi <= 0) + if coords.xl - coords.xi <= 0 coords.xl = Math.max(coords.xl, coords.xi) return end - if (coords.yl - coords.yi <= 0) + if coords.yl - coords.yi <= 0 coords.yl = Math.max(coords.yl, coords.yi) return end @@ -107,7 +107,7 @@ module Crysterm # content = clines.join('\n') # end - if (coords.base >= @_clines.ci.size) + if coords.base >= @_clines.ci.size # Can be @_pcontent, but this is the same here, plus not_nil! ci = content.size end @@ -138,7 +138,7 @@ module Crysterm # If we're in a scrollable text box, check to # see which attributes this line starts with. - if (ci > 0) + if ci > 0 attr = @_clines.attr.try(&.[Math.min(coords.base, @_clines.size - 1)]?) || 0 end @@ -185,7 +185,7 @@ module Crysterm # Determine where to place the text if it's vertically aligned. if @align.v_center? || @align.bottom? visible = yl - yi - if (@_clines.size < visible) + if @_clines.size < visible if @align.v_center? visible = visible // 2 visible -= @_clines.size // 2 @@ -199,8 +199,8 @@ module Crysterm # Draw the content and background. # yi.step to: yl-1 do |y| (yi...yl).each do |y| - if (!lines[y]?) - if (y >= screen.aheight || yl < ibottom) + if !lines[y]? + if y >= screen.aheight || yl < ibottom break else next @@ -229,7 +229,7 @@ module Crysterm # end # Handle escape codes. - while (ch == '\e') + while ch == '\e' cnt = content[(ci - 1)..] if c = cnt.match SGR_REGEX_AT_BEGINNING ci += c[0].size - 1 @@ -248,25 +248,25 @@ module Crysterm end # Handle newlines. - if (ch == '\t') + if ch == '\t' # TODO this should be something like ch = bch * style.tab_size, or just style.tab_char, # (although not as simple as that.) ch = bch end - if (ch == '\n') + if ch == '\n' # If we're on the first cell and we find a newline and the last cell # of the last line was not a newline, let's just treat this like the # newline was already "counted". - if ((x == xi) && (y != yi) && (content[ci - 2]? != '\n')) + if (x == xi) && (y != yi) && (content[ci - 2]? != '\n') x -= 1 next end # We could use fill_region here, name the # outer loop, and continue to it instead. ch = bch - while (x < xl) + while x < xl cell = lines[y][x]? - if (!cell) + if !cell break end if alpha = style.alpha? @@ -292,7 +292,7 @@ module Crysterm # TODO # if (screen.full_unicode && content[ci - 1]) - if (content[ci - 1]?) + if content[ci - 1]? # point = content.codepoint_at(ci - 1) # Unused # TODO # # Handle combining chars: diff --git a/src/widget_scrolling.cr b/src/widget_scrolling.cr index 8fc97e1..d3b3e35 100644 --- a/src/widget_scrolling.cr +++ b/src/widget_scrolling.cr @@ -77,7 +77,7 @@ module Crysterm i = get_scroll_height # p - if (height < i) + if height < i if @always_scroll p = @child_base / (i - height) else @@ -153,26 +153,26 @@ module Crysterm @child_offset += offset end - if (@child_offset > visible - 1) + if @child_offset > visible - 1 d = @child_offset - (visible - 1) @child_offset -= d @child_base += d - elsif (@child_offset < 0) + elsif @child_offset < 0 d = @child_offset @child_offset += -d @child_base += d end - if (@child_base < 0) + if @child_base < 0 @child_base = 0 - elsif (@child_base > @base_limit) + elsif @child_base > @base_limit @child_base = @base_limit end # Find max "bottom" value for # content and descendant elements. # Scroll the content if necessary. - if (@child_base == base) + if @child_base == base return emit Crysterm::Event::Scroll end @@ -186,19 +186,19 @@ module Crysterm # max = get_scroll_height - (aheight - iheight) max = @_clines.size - (aheight - iheight) - if (max < 0) + if max < 0 max = 0 end emax = _scroll_bottom - (aheight - iheight) - if (emax < 0) + if emax < 0 emax = 0 end @child_base = Math.min @child_base, Math.max(emax, max) - if (@child_base < 0) + if @child_base < 0 @child_base = 0 - elsif (@child_base > @base_limit) + elsif @child_base > @base_limit @child_base = @base_limit end @@ -214,10 +214,10 @@ module Crysterm b = p.yl - ibottom - 1 d = @child_base - base - if (d > 0 && d < visible) + if d > 0 && d < visible # scrolled down screen.delete_line(d, t, t, b) - elsif (d < 0 && -d < visible) + elsif d < 0 && -d < visible # scrolled up d = -d screen.insert_line(d, t, t, b) diff --git a/src/widget_size.cr b/src/widget_size.cr index 7170de9..d1c469b 100644 --- a/src/widget_size.cr +++ b/src/widget_size.cr @@ -175,7 +175,7 @@ module Crysterm ret.xl += ileft ret.xi += ileft end - if (el.top.nil? && !el.bottom.nil?) + if el.top.nil? && !el.bottom.nil? ret.yl = yi + (ret.yl - ret.yi) ret.yi = yi # Maybe just do this no matter what. @@ -258,9 +258,9 @@ module Crysterm end # end - if (@height.nil? && (@top.nil? || @bottom.nil?) && - (!@scrollable || @_is_list)) - if (@top.nil? && !@bottom.nil?) + if @height.nil? && (@top.nil? || @bottom.nil?) && + (!@scrollable || @_is_list) + if @top.nil? && !@bottom.nil? yi = yl - h - iheight # (iheight == 1 ? 0 : iheight) else yl = yi + h + iheight # (iheight == 1 ? 0 : iheight) @@ -278,7 +278,7 @@ module Crysterm yll = yl # Figure out which one is bigger and use it. - if (minimal_children_rectangle.xl - minimal_children_rectangle.xi > minimal_content_rectangle.xl - minimal_content_rectangle.xi) + if minimal_children_rectangle.xl - minimal_children_rectangle.xi > minimal_content_rectangle.xl - minimal_content_rectangle.xi xi = minimal_children_rectangle.xi xl = minimal_children_rectangle.xl else @@ -286,7 +286,7 @@ module Crysterm xl = minimal_content_rectangle.xl end - if (minimal_children_rectangle.yl - minimal_children_rectangle.yi > minimal_content_rectangle.yl - minimal_content_rectangle.yi) + if minimal_children_rectangle.yl - minimal_children_rectangle.yi > minimal_content_rectangle.yl - minimal_content_rectangle.yi yi = minimal_children_rectangle.yi yl = minimal_children_rectangle.yl else @@ -295,13 +295,13 @@ module Crysterm end # Recenter shrunken elements. - if (xl < xll && @left == "center") + if xl < xll && @left == "center" xll = (xll - xl) // 2 xi += xll xl += xll end - if (yl < yll && @top == "center") + if yl < yll && @top == "center" yll = (yll - yl) // 2 yi += yll yl += yll diff --git a/test-auto/hello/main.cr b/test-auto/hello/main.cr index 92a2a7f..3ef2f67 100644 --- a/test-auto/hello/main.cr +++ b/test-auto/hello/main.cr @@ -13,7 +13,7 @@ w = Widget::Box.new \ parse_tags: false, style: Style.new(fg: "yellow", bg: "blue", border: true) -s.on(Event::KeyPress) { |e| exit } +s.on(Event::KeyPress) { |_| exit } s.on(Event::Rendered) { if ARGV.includes? "--test-auto" diff --git a/test/widget-prompt.cr b/test/widget-prompt.cr index 1622aeb..9529daa 100644 --- a/test/widget-prompt.cr +++ b/test/widget-prompt.cr @@ -72,9 +72,9 @@ module Crysterm end end - prompt.read_input("Question?", "") do |err, val| + prompt.read_input("Question?", "") do |_, _| STDERR.puts :q1 - question.ask("Question?") do |err, val| + question.ask("Question?") do |_, _| STDERR.puts :q2 msg.display("Hello world!", 3.seconds) do # |err| msg.display("Hello world again!", -1.seconds) do # |err|