@@ -194,8 +194,8 @@ def initialize(width, height, top_frame:)
194194 @height = height
195195 @width = width
196196 @top_frame = TopFrame . new ( @width , TopFrame ::HEIGHT , type : top_frame )
197- # we need to leave 1 line for the input
198- @repl = REPL . new ( @width , height - @top_frame . height - 1 )
197+ # we need to leave 1 line for the input and 1 line for overflow buffer
198+ @repl = REPL . new ( @width , height - @top_frame . height - 2 )
199199 end
200200
201201 def render
@@ -215,6 +215,7 @@ class Window
215215
216216 def initialize ( width , height )
217217 @width = width
218+ @content_width = @width
218219 @height = height
219220 @content_height = @height
220221 @lines = [ ]
@@ -225,7 +226,22 @@ def puts line = ""
225226 @lines . slice! ( 0 )
226227 end
227228
228- @lines << line
229+ # if the current line will break into multiple lines, we need to skip more lines for it. otherwise it'll affect the overall layout
230+ if line . length > @content_width
231+ n_lines = ( line . length /@content_width . to_f ) . ceil
232+
233+ start = 0
234+ n_lines . times do
235+ if @lines . length >= @content_height
236+ @lines . slice! ( 0 )
237+ end
238+
239+ @lines << line [ start ..( start + @content_width - 1 ) ]
240+ start += @content_width
241+ end
242+ else
243+ @lines << line
244+ end
229245 end
230246
231247 def render ( io )
@@ -242,8 +258,11 @@ def clear!
242258 class TopFrame < Window
243259 HEIGHT = 15
244260
245- def initialize ( *args , type :)
246- super ( *args )
261+ def initialize ( width , height , type :)
262+ super ( width , height )
263+ # border and padding
264+ @content_width = @width - 2
265+ # top and bottom border
247266 @content_height = @height - 2
248267 @type = type
249268 end
0 commit comments