Version bump => 0.3.
[kaya.git] / lib / console.rb
blob775d1158ed358c2c9dbd253697844df4f4d09a96
1 # Copyright (c) 2009 Paolo Capriotti <p.capriotti@gmail.com>
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 require 'qtutils'
10 class Console < Qt::Widget
11   include Observable
13   def initialize(parent)
14     super(parent)
15     
16     layout = Qt::VBoxLayout.new
17     @output = Qt::TextEdit.new(self)
18     @input = Qt::LineEdit.new(self)
19     
20     layout.add_widget(@output)
21     layout.add_widget(@input)
22     setLayout layout
23     
24     @output.read_only = true
25     f = @output.font
26     f.family = 'monospace'
27     f.point_size = 8
28     @output.font = f
29     @output.current_font = f
30     @bold_font = f
31     @bold_font.bold = true
33     @input.on(:returnPressed) do
34       text = @input.text
35       with_font(@bold_font) do
36         @output.append text
37       end
38       @input.text = ''
39       fire :input => text
40     end
41   end
43   def with_font(font)
44     old = @output.current_font
45     @output.current_font = font
46     yield
47     @output.current_font = old
48   end
49   
50   def append(text)
51     @output.append(text)
52   end
53 end