Skip to content

Commit

Permalink
Win worx a little
Browse files Browse the repository at this point in the history
  • Loading branch information
natano committed Oct 19, 2008
1 parent 8455e08 commit c2f6b82
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
40 changes: 30 additions & 10 deletions console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,28 +192,48 @@ def self.restore
end

class Win
row = 0
col = 0
width = 10
height = 5
def initialize
@row = 0
@col = 0
@width = 10
@height = 5
@text = ""
end

def width=(width)
@width = width
end

def height=(height)
@height = height
end

def text=(text)
@text = text
end

def position=(arg)
row = 0
col = 0
text = ""
@row = 0
@col = 0

if not arg.is_a?(Array)
arg = [arg]
end
if arg.length > 0
row = arg[0]
@row = arg[0]
end
if arg.length > 1
col = arg[1]
@col = arg[1]
end
end

def draw

@text = @text.split("\n")
0.upto(@text.length - 1) do |i|
@text[i] = @text[i][0, @width] + "\n"
end
0.upto((@text.length > @height ? @height : @text.length) - 1) do |i|
@text[i].printAt @row + i , @col
end
end
end
10 changes: 9 additions & 1 deletion main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@
Cursor.up 4
print "lol"

Cursor.position = 10
textbox = Win.new
textbox.position = 12, 10
textbox.width = 10
textbox.height = 5
textbox.text = "Hello!\nIm a textbox\nText"
textbox.draw


Cursor.position = 18
print "\n"

0 comments on commit c2f6b82

Please sign in to comment.