JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
refactor to fix code duplication in line shuffling
authorJason Woofenden <jason@jasonwoof.com>
Thu, 31 Jan 2013 23:58:31 +0000 (18:58 -0500)
committerJason Woofenden <jason@jasonwoof.com>
Thu, 31 Jan 2013 23:58:31 +0000 (18:58 -0500)
terminal.coffee

index 4aa522c..141165b 100644 (file)
@@ -62,19 +62,15 @@ class Terminal
                        @text[@scroll_top][i] = ' '
                        @attributes[@scroll_top][i] = 0x07
 
-               # move (newly cleared) top line to the bottom of the scrolling region
-               @text = [
-                       @text[0...@scroll_top]..., # up to but not including scroll top
-                       @text[@scroll_top + 1 .. @scroll_bottom]..., # scroll region except top line of it
-                       @text[@scroll_top], # top line of scroll region (already cleared)
-                       @text[@scroll_bottom + 1 ... @height]... # rest of screen
-               ]
-               @attributes = [
-                       @attributes[0...@scroll_top]..., # up to but not including scroll top
-                       @attributes[@scroll_top + 1 .. @scroll_bottom]..., # scroll region except top line of it
-                       @attributes[@scroll_top], # top line of scroll region (already cleared)
-                       @attributes[@scroll_bottom + 1 ... @height]... # rest of screen
-               ]
+               rearrange = (a) =>
+                       return [
+                               a[0...@scroll_top]..., # up to but not including scroll top
+                               a[@scroll_top + 1 .. @scroll_bottom]..., # scroll region except top line of it
+                               a[@scroll_top], # top line of scroll region (already cleared)
+                               a[@scroll_bottom + 1 ... @height]... # rest of screen
+                       ]
+               @text = rearrange @text
+               @attributes = rearrange @attributes
 
                # slide cursor up with rest of text
                @y -= 1
@@ -237,19 +233,15 @@ class Terminal
        csi_L: (lines) ->
                lines = parseInt @fix_esc_arg lines, '1'
 
-               # move (newly cleared) top line to the bottom of the scrolling region
-               @text = [
-                       @text[0...@y]..., # keep everything above cursor
-                       @text[@scroll_bottom - lines + 1 .. @scroll_bottom]..., # we'll clear these shortly
-                       @text[@y..@scroll_bottom - lines]..., # lines that are moving down
-                       @text[@scroll_bottom + 1 ... @height]... # rest of screen
-               ]
-               @attributes = [
-                       @attributes[0...@y]..., # keep everything above cursor
-                       @attributes[@scroll_bottom - lines + 1 .. @scroll_bottom]..., # we'll clear these shortly
-                       @attributes[@y..@scroll_bottom - lines]..., # lines that are moving down
-                       @attributes[@scroll_bottom + 1 ... @height]... # rest of screen
-               ]
+               rearrange = (a) =>
+                       return [
+                               a[0...@y]..., # keep everything above cursor
+                               a[@scroll_bottom - lines + 1 .. @scroll_bottom]..., # we'll clear these shortly
+                               a[@y..@scroll_bottom - lines]..., # lines that are moving down
+                               a[@scroll_bottom + 1 ... @height]... # rest of screen
+                       ]
+               @text = rearrange @text
+               @attributes = rearrange @attributes
 
                # clear the lines we scrolled off (and put back in as "new")
                for y in [@y...@y+lines]