ruber 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. data/CHANGES +54 -0
  2. data/bin/ruber +12 -1
  3. data/data/share/apps/ruber/ruberui.rc +5 -0
  4. data/data/share/icons/pin.png +0 -0
  5. data/lib/ruber/application/application.rb +1 -1
  6. data/lib/ruber/documents/document_list.rb +1 -1
  7. data/lib/ruber/editor/document.rb +26 -6
  8. data/lib/ruber/editor/editor_view.rb +21 -2
  9. data/lib/ruber/filtered_output_widget.rb +1 -1
  10. data/lib/ruber/ktexteditor_sugar.rb +124 -0
  11. data/lib/ruber/main_window/main_window.rb +34 -16
  12. data/lib/ruber/main_window/main_window_actions.rb +98 -5
  13. data/lib/ruber/main_window/main_window_internal.rb +1 -1
  14. data/lib/ruber/main_window/plugin.yaml +5 -0
  15. data/lib/ruber/main_window/ui/choose_plugins_widget.rb +2 -2
  16. data/lib/ruber/main_window/ui/main_window_settings_widget.rb +67 -34
  17. data/lib/ruber/main_window/ui/main_window_settings_widget.ui +77 -30
  18. data/lib/ruber/main_window/ui/new_project_widget.rb +2 -2
  19. data/lib/ruber/main_window/ui/open_file_in_project_dlg.rb +2 -2
  20. data/lib/ruber/main_window/ui/output_color_widget.rb +2 -2
  21. data/lib/ruber/main_window/ui/workspace_settings_widget.rb +1 -1
  22. data/lib/ruber/main_window/view_manager.rb +14 -1
  23. data/lib/ruber/output_widget.rb +409 -288
  24. data/lib/ruber/pane.rb +22 -0
  25. data/lib/ruber/projects/ui/project_files_rule_chooser_widget.rb +2 -2
  26. data/lib/ruber/projects/ui/project_files_widget.rb +2 -2
  27. data/lib/ruber/qt_sugar.rb +11 -0
  28. data/lib/ruber/version.rb +1 -1
  29. data/plugins/auto_end/auto_end.rb +122 -0
  30. data/plugins/auto_end/plugin.yaml +11 -0
  31. data/plugins/autosave/ui/autosave_config_widget.rb +2 -2
  32. data/plugins/command/command.rb +71 -12
  33. data/plugins/command/output.rb +592 -0
  34. data/plugins/command/ui/tool_widget.rb +143 -0
  35. data/plugins/command/ui/tool_widget.ui +147 -0
  36. data/plugins/find_in_files/ui/config_widget.rb +2 -2
  37. data/plugins/find_in_files/ui/find_in_files_widget.rb +2 -2
  38. data/plugins/rake/ui/add_quick_task_widget.rb +2 -2
  39. data/plugins/rake/ui/choose_task_widget.rb +2 -2
  40. data/plugins/rake/ui/config_widget.rb +2 -2
  41. data/plugins/rake/ui/project_widget.rb +2 -2
  42. data/plugins/rspec/plugin.yaml +7 -2
  43. data/plugins/rspec/rspec.rb +178 -53
  44. data/plugins/rspec/rspecui.rc +2 -3
  45. data/plugins/rspec/ui/config_widget.rb +79 -0
  46. data/plugins/rspec/ui/config_widget.ui +89 -0
  47. data/plugins/rspec/ui/rspec_project_widget.rb +2 -2
  48. data/plugins/ruby_development/ruby_development.rb +1 -1
  49. data/plugins/ruby_development/ui/config_widget.rb +1 -1
  50. data/plugins/ruby_development/ui/project_widget.rb +2 -2
  51. data/plugins/ruby_runner/ruby_runner.rb +13 -12
  52. data/plugins/ruby_runner/ui/config_widget.rb +2 -2
  53. data/plugins/ruby_runner/ui/project_widget.rb +2 -2
  54. data/plugins/ruby_runner/ui/ruby_runnner_plugin_option_widget.rb +2 -2
  55. data/plugins/state/ui/config_widget.rb +2 -2
  56. data/plugins/syntax_checker/syntax_checker.rb +1 -1
  57. data/spec/auto_end_spec.rb +272 -0
  58. data/spec/common.rb +1 -0
  59. data/spec/document_spec.rb +83 -0
  60. data/spec/editor_view_spec.rb +41 -0
  61. data/spec/filtered_output_widget_spec.rb +2 -2
  62. data/spec/ktexteditor_sugar_spec.rb +190 -0
  63. data/spec/output_widget_spec.rb +120 -11
  64. data/spec/pane_spec.rb +1 -1
  65. data/spec/qt_sugar_spec.rb +14 -0
  66. data/spec/state_spec.rb +0 -26
  67. metadata +14 -3
@@ -96,6 +96,10 @@ allow to resize it. It *must not* be used to add or remove widgets to or from it
96
96
  margins.top = margins.left = margins.bottom = margins.right = 0
97
97
  layout.contents_margins = margins
98
98
  @label = Qt::Label.new '', self
99
+ # Use the following three lines when attempting to debug issue number 10, as it
100
+ # helps understanding which pane each label belongs to
101
+ # color = Qt::Color.new(rand(256), rand(256), rand(256))
102
+ # @label.style_sheet = "background-color: #{color.name};"
99
103
  @label.hide unless parent_pane
100
104
  layout.add_widget @label
101
105
  end
@@ -314,6 +318,22 @@ Iterates on child panes
314
318
  self
315
319
  end
316
320
 
321
+ =begin rdoc
322
+ The panes contained in this pane
323
+
324
+ @overload panes(:recursive)
325
+ @return [Array<Pane>] an array containing the panes contained in this pane,
326
+ directly or indirectly. Returns an empty array if the pane is in single view
327
+ mode
328
+ @overload panes
329
+ @return [Array<Pane>] an array containing the panes directly contained in this pane.
330
+ Returns an empty array if the pane is in single view mode
331
+ @return [Array<Pane>]
332
+ =end
333
+ def panes mode = :flat
334
+ single_view? ? [] : each_pane(mode).to_a
335
+ end
336
+
317
337
  =begin rdoc
318
338
  Changes the text of the label for the given view
319
339
 
@@ -500,6 +520,8 @@ It does nothing if the splitter is already in single view mode
500
520
  self.label = label
501
521
  @label.visible = false unless parent_pane
502
522
  connect @view, SIGNAL('closing(QWidget*)'), self, SLOT('remove_view(QWidget*)')
523
+ @splitter.delete_later
524
+ @splitter = nil
503
525
  self
504
526
  end
505
527
  end
@@ -1,8 +1,8 @@
1
1
  =begin
2
2
  ** Form generated from reading ui file 'project_files_rule_chooser_widget.ui'
3
3
  **
4
- ** Created: mar nov 16 11:52:49 2010
5
- ** by: Qt User Interface Compiler version 4.7.0
4
+ ** Created: mer gen 12 12:12:11 2011
5
+ ** by: Qt User Interface Compiler version 4.7.1
6
6
  **
7
7
  ** WARNING! All changes made in this file will be lost when recompiling ui file!
8
8
  =end
@@ -1,8 +1,8 @@
1
1
  =begin
2
2
  ** Form generated from reading ui file 'project_files_widget.ui'
3
3
  **
4
- ** Created: mar nov 16 11:52:49 2010
5
- ** by: Qt User Interface Compiler version 4.7.0
4
+ ** Created: mer gen 12 12:12:11 2011
5
+ ** by: Qt User Interface Compiler version 4.7.1
6
6
  **
7
7
  ** WARNING! All changes made in this file will be lost when recompiling ui file!
8
8
  =end
@@ -728,6 +728,17 @@ is given
728
728
 
729
729
  end
730
730
 
731
+ class Enum
732
+
733
+ =begin rdoc
734
+ Converts the enum to an integer
735
+ @return [Integer] the integer value of the enum
736
+ =end
737
+ def to_int
738
+ to_i
739
+ end
740
+ end
741
+
731
742
  end
732
743
 
733
744
  =begin rdoc
@@ -1,5 +1,5 @@
1
1
  module Ruber
2
2
 
3
- VERSION = '0.0.7'
3
+ VERSION = '0.0.8'
4
4
 
5
5
  end
@@ -0,0 +1,122 @@
1
+ =begin
2
+ Copyright (C) 2011 by Stefano Crocco
3
+ stefano.crocco@alice.it
4
+
5
+ This program is free software; you can redistribute it andor modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation; either version 2 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program; if not, write to the
17
+ Free Software Foundation, Inc.,
18
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
+ =end
20
+
21
+ module Ruber
22
+
23
+ module AutoEnd
24
+
25
+ class Extension < Qt::Object
26
+
27
+ include Ruber::Extension
28
+
29
+ Insertion = Struct.new :line_number, :lines, :final_position
30
+
31
+ IDENTIFIER_PATTERN = RUBY_VERSION >= '1.9.2' ? '\p{Word}+' : '\w+'
32
+
33
+ MULTI_ID_PATTERN = "#{IDENTIFIER_PATTERN}(?:::#{IDENTIFIER_PATTERN})*"
34
+
35
+ PATTERNS = [
36
+ [/^\s*if\s/, "\nend", [0, -1]],
37
+ [/=\s*if\s/, "\nend", [0, -1]],
38
+ [/\bdo\s*$/, "\nend", [0, -1]],
39
+ [/\bdo\s+\|/, "\nend", [0, -1]],
40
+ [/^\s*def\s/, "\nend", [0, -1]],
41
+ [/^class\s+#{IDENTIFIER_PATTERN}\s*$/, "\nend", [0, -1]],
42
+ [/^class\s+#{MULTI_ID_PATTERN}\s*<{1,2}\s*#{MULTI_ID_PATTERN}\s*$/, "\nend", [0, -1]],
43
+ [/^\s*module\s+#{MULTI_ID_PATTERN}\s*$/, "\nend", [0,-1]],
44
+ [/^=begin(\s|$)/, "\n=end", [0, -1]],
45
+ [/^\s*begin\s/, "\nend", [0, -1]],
46
+ [/=\s*begin\s/, "\nend", [0, -1]],
47
+ ]
48
+
49
+ def initialize prj
50
+ super
51
+ @doc = prj.document
52
+ @insertion = nil
53
+ connect_slots
54
+ end
55
+
56
+ def text_inserted range
57
+ text = @doc.text range
58
+ return unless text.end_with? "\n"
59
+ @insertion = nil
60
+ line = @doc.line( range.end.line - 1)
61
+ pattern = PATTERNS.find{|pat| pat[0].match line}
62
+ if pattern and !line.start_with? '#'
63
+ indentation = line.match(/^\s*/)[0].size
64
+ next_indentation = @doc.line(range.end.line + 1).match(/^\s*/)[0].size
65
+ unless next_indentation > indentation
66
+ @insertion = Insertion.new range.end.line, pattern[1], pattern[2]
67
+ end
68
+ end
69
+ end
70
+ slots 'text_inserted(KTextEditor::Range)'
71
+
72
+ def text_changed
73
+ if @insertion
74
+ insert_text KTextEditor::Cursor.new(@insertion.line_number, 0),
75
+ @insertion.lines, @insertion.final_position
76
+ @insertion = nil
77
+ end
78
+ end
79
+ slots :text_changed
80
+
81
+ def remove_from_project
82
+ disconnect_slots
83
+ end
84
+
85
+ private
86
+
87
+ def connect_slots
88
+ connect @doc, SIGNAL('text_inserted(KTextEditor::Range, QObject*)'), self, SLOT('text_inserted(KTextEditor::Range)')
89
+ connect @doc, SIGNAL('text_changed(QObject*)'), self, SLOT(:text_changed)
90
+ end
91
+
92
+ def disconnect_slots
93
+ disconnect @doc, SIGNAL('text_inserted(KTextEditor::Range, QObject*)'), self, SLOT('text_inserted(KTextEditor::Range)')
94
+ disconnect @doc, SIGNAL('text_changed(QObject*)'), self, SLOT(:text_changed)
95
+ end
96
+
97
+ def insert_text insert_pos, lines, dest
98
+ view = @doc.active_view
99
+ return unless view
100
+ disconnect_slots
101
+ replace_pos = KTextEditor::Cursor.new insert_pos.line, @doc.line_length(insert_pos.line)
102
+ insert_pos.column = @doc.line_length insert_pos.line
103
+ @doc.insert_text insert_pos, lines
104
+ final_pos = KTextEditor::Cursor.new insert_pos.line + lines.size - 1,
105
+ lines[-1].size
106
+ do_indentation view
107
+ dest_line = insert_pos.line+dest[0]
108
+ dest_col = dest[1]
109
+ dest_col += @doc.line_length(dest_line) + 1 if dest_col < 0
110
+ view.go_to dest_line, dest_col
111
+ connect_slots
112
+ end
113
+
114
+ def do_indentation view
115
+ view.execute_action 'tools_align'
116
+ end
117
+
118
+ end
119
+
120
+ end
121
+
122
+ end
@@ -0,0 +1,11 @@
1
+ name: auto_end
2
+ version: 0.0.1
3
+ about:
4
+ authors: [Stefano Crocco, stefano.crocco@alice.it]
5
+ license: gpl
6
+ description: Automatically inserts end keywords after if, do and similar statements
7
+ bug_address: stefano.crocco@alice.it
8
+ require: auto_end
9
+ extensions:
10
+ auto_end: {class: Ruber::AutoEnd::Extension, scope: document, file_extension: ['*.rb', 'Rakefile', 'rakefile', '*.gemspec'], mimetype: ['application/x-ruby']}
11
+
@@ -1,8 +1,8 @@
1
1
  =begin
2
2
  ** Form generated from reading ui file 'autosave_config_widget.ui'
3
3
  **
4
- ** Created: mar nov 16 11:52:49 2010
5
- ** by: Qt User Interface Compiler version 4.7.0
4
+ ** Created: mer gen 12 12:12:11 2011
5
+ ** by: Qt User Interface Compiler version 4.7.1
6
6
  **
7
7
  ** WARNING! All changes made in this file will be lost when recompiling ui file!
8
8
  =end
@@ -1,3 +1,26 @@
1
+ =begin
2
+ Copyright (C) 2010,2011 by Stefano Crocco
3
+ stefano.crocco@alice.it
4
+
5
+ This program is free software; you can redistribute it andor modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation; either version 2 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program; if not, write to the
17
+ Free Software Foundation, Inc.,
18
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
+ =end
20
+
21
+ require 'command/output'
22
+ require_relative 'ui/tool_widget'
23
+
1
24
  module Ruber
2
25
 
3
26
  =begin rdoc
@@ -7,7 +30,9 @@ plugin, which simply starts a new ruby interpreter and runs a script in it).
7
30
 
8
31
  This plugin doesn't provide a plugin class but just a tool widget where the user
9
32
  can enter the code and a button to execute it. It also doesn't provide any
10
- API for the feature.
33
+ API for the feature. Beside the editor widget, the plugin also provides an output
34
+ widget, where the text written to standard output and standard error by the code
35
+ executed will be displayed.
11
36
 
12
37
  *Note:* the ruby code is executed in the top level context. Any exception
13
38
  raised by the code won't cause Ruber to crash, but will be displayed in a dialog.
@@ -18,7 +43,7 @@ raised by the code won't cause Ruber to crash, but will be displayed in a dialog
18
43
  The tool widget where the user can enter the ruby code to execute.
19
44
  =end
20
45
  class ToolWidget < Qt::Widget
21
-
46
+
22
47
  slots :execute_command, :load_settings
23
48
 
24
49
  =begin rdoc
@@ -26,13 +51,13 @@ The tool widget where the user can enter the ruby code to execute.
26
51
  =end
27
52
  def initialize parent = nil
28
53
  super
29
- self.layout = Qt::VBoxLayout.new self
30
- @editor = Qt::PlainTextEdit.new
31
- layout.add_widget @editor
32
- self.focus_proxy = @editor
33
- @button = Qt::PushButton.new("Execute")
34
- connect @button, SIGNAL(:clicked), self, SLOT(:execute_command)
35
- layout.add_widget @button
54
+ @ui = Ui::CommandToolWidget.new
55
+ @ui.setup_ui self
56
+ self.focus_proxy = @ui.editor
57
+ connect @ui.execute, SIGNAL(:clicked), self, SLOT(:execute_command)
58
+ connect @ui.show_output, SIGNAL('toggled(bool)'), self, SLOT('output_visible=(bool)')
59
+ @ui.clear.connect(SIGNAL(:clicked)){@ui.output.clear}
60
+ self.output_visible = @ui.show_output.checked?
36
61
  end
37
62
 
38
63
  =begin rdoc
@@ -44,15 +69,23 @@ it will be displayed on standard error and in a message box.
44
69
  was raised.
45
70
  =end
46
71
  def execute_command
47
- code = @editor.to_plain_text
72
+ code = @ui.editor.to_plain_text
48
73
  begin
74
+ old_stdout = $stdout
75
+ old_stderr = $stderr
76
+ $stdout = Output.new @ui.output, Ruber[:config][:output_colors, :output], $stdout.fileno
77
+ $stderr = Output.new @ui.output, Ruber[:config][:output_colors, :error], $stderr.fileno
49
78
  eval code, TOPLEVEL_BINDING, 'COMMAND'
50
79
  true
51
80
  rescue Exception => ex
52
- dlg = ExceptionDialog.new ex, Ruber[:main_window], false,
81
+ dlg = ExceptionDialog.new ex, Ruber[:main_window], true,
53
82
  'The command you issued raised the following exception:'
83
+ dlg.set_button_text KDE::Dialog::Ok, i18n('Ok')
54
84
  dlg.exec
55
85
  false
86
+ ensure
87
+ $stdout = old_stdout
88
+ $stderr = old_stderr
56
89
  end
57
90
  end
58
91
 
@@ -63,10 +96,36 @@ Sets the font of the editor to the font chosen by the user as the output font
63
96
  @return [nil]
64
97
  =end
65
98
  def load_settings
66
- @editor.font = Ruber[:config][:general, :output_font]
99
+ font = Ruber[:config][:general, :output_font]
100
+ metrics = Qt::FontMetrics.new font
101
+ tab_width = metrics.max_width * 2
102
+ @ui.editor.font = font
103
+ @ui.editor.tab_stop_width = tab_width
104
+ @ui.output.font = font
105
+ @ui.output.tab_stop_width = tab_width
67
106
  nil
68
107
  end
69
108
 
109
+ private
110
+
111
+ =begin rdoc
112
+ Shows or hides the output widget and related widgets
113
+
114
+ It also changes the text of the Show Output button so that it becomes 'Hide Output'
115
+ if the button is visible.
116
+
117
+ @param [Boolean] visible whether the output widget should be shown or hidden
118
+ @return [nil]
119
+ =end
120
+ def output_visible= visible
121
+ @ui.output.visible = visible
122
+ @ui.clear.visible = visible
123
+ @ui.output_label.visible = visible
124
+ @ui.show_output.text = i18n(visible ? '&Hide Output' : '&Show Output')
125
+ nil
126
+ end
127
+ slots 'output_visible=(bool)'
128
+
70
129
  end
71
130
 
72
131
  end
@@ -0,0 +1,592 @@
1
+ =begin
2
+ Copyright (C) 2011 by Stefano Crocco
3
+ stefano.crocco@alice.it
4
+
5
+ This program is free software; you can redistribute it andor modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation; either version 2 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program; if not, write to the
17
+ Free Software Foundation, Inc.,
18
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
+ =end
20
+
21
+ module Ruber
22
+
23
+ module CommandPlugin
24
+
25
+ =begin rdoc
26
+ Fake IO object for use by the command plugin. Despite the name, it can be used
27
+ to display standard error as well as standard output.
28
+
29
+ It displays the text in a @Qt::PlainTextEdit@ using a given color.
30
+
31
+ All the methods in this class are implementations of the API provided by IO.
32
+
33
+ @example Typical usage
34
+
35
+ old_stdout = $stdout #store the old standard output to restore it later
36
+ $stdout = Output.new plain_text_edit, Qt::Color.new(Qt.blue)
37
+ puts "hello" # => the string "hello" is displayed in the widget
38
+ $stdout = old_stout # restore the old standard output
39
+ =end
40
+ class Output
41
+
42
+ =begin rdoc
43
+ @param [Qt::PlainTextEdit] widget the widget to display the output into
44
+ @param [Qt::Color] color the color to use for the text
45
+ @param [Integer] fileno the number that the {#fileno} method should return
46
+ =end
47
+ def initialize widget, color, fileno = 1
48
+ @widget = widget
49
+ @close_on_exec = false
50
+ @closed = false
51
+ @sync = true
52
+ @brush = Qt::Brush.new color
53
+ @fileno = fileno
54
+ end
55
+
56
+ =begin rdoc
57
+ @return [Boolean] whether byffering is disabled or enabled. This class doesn't buffer
58
+ output, so this makes no difference. It's only provided for compatibility with
59
+ @IO@ API
60
+ =end
61
+ attr_accessor :sync
62
+
63
+ =begin rdoc
64
+ As @IO#<<@
65
+
66
+ @return [Output] self
67
+ =end
68
+ def << text
69
+ write text
70
+ self
71
+ end
72
+
73
+ =begin rdoc
74
+ As @IO#binmode@
75
+
76
+ This method doesn't actually do anything. It's just for compatibility with the @IO@
77
+ API
78
+ @return [nil]
79
+ =end
80
+ def binmode
81
+ end
82
+
83
+ =begin rdoc
84
+ As @IO#binmode?@
85
+
86
+ This method always returns *true*. It's just for compatibility with the @IO@
87
+ API
88
+ @return [TrueClass] *true*
89
+ =end
90
+ def binmode?
91
+ true
92
+ end
93
+
94
+ =begin rdoc
95
+ As @IO#bytes@
96
+
97
+ @return [Enumerator] an enumerator which calls {#each_byte}
98
+ =end
99
+ def bytes
100
+ each_byte
101
+ end
102
+
103
+ =begin rdoc
104
+ As @IO#chars@
105
+
106
+ @return [Enumerator] an enumerator which calls {#each_char}
107
+ =end
108
+
109
+ def chars
110
+ each_char
111
+ end
112
+
113
+ =begin rdoc
114
+ As @IO#close@
115
+
116
+ @return [nil]
117
+ =end
118
+ def close
119
+ @closed = true
120
+ nil
121
+ end
122
+
123
+ =begin rdoc
124
+ As @IO#close_on_exec@
125
+
126
+ This method does nothing. It's only for compatibility with @IO@ API
127
+ @param [Object] val the new value
128
+ @return [Object] _val_
129
+ =end
130
+
131
+ def close_on_exec= val
132
+ @close_on_exec = val.to_bool
133
+ end
134
+
135
+ =begin rdoc
136
+ As @IO#close_on_exec?@
137
+
138
+ {#close_on_exec=} has no influence on this class, so the value returned here is
139
+ meaningless. It's only provided for compatibility with @IO@ API
140
+ @return [Boolean] whether close on exec is enabled or not. Nothing changes in either
141
+ case
142
+ =end
143
+ def close_on_exec?
144
+ @close_on_exec
145
+ end
146
+
147
+ =begin rdoc
148
+ As @IO#close_read@
149
+
150
+ @raise [IOError] always as this class isn't open for reading
151
+ @return [nil]
152
+ =end
153
+ def close_read
154
+ raise IOError, 'closing non-duplex IO for reading'
155
+ end
156
+
157
+ =begin rdoc
158
+ As @IO#close_write@
159
+
160
+ @return [nil]
161
+ =end
162
+ def close_write
163
+ @closed = true
164
+ nil
165
+ end
166
+
167
+ =begin rdoc
168
+ As @IO#closed?@
169
+
170
+ @return [Boolean] whether the stream is closed or not
171
+ =end
172
+ def closed?
173
+ @closed
174
+ end
175
+
176
+ =begin rdoc
177
+ As @IO#each@
178
+
179
+ @raise [IOError] when called with a block because the stream is not open for reading
180
+ @return [Enumerator] an enumerator which calls {#each} when called without a block
181
+ =end
182
+ def each
183
+ raise IOError, "not opened for reading" if block_given?
184
+ to_enum
185
+ end
186
+
187
+ =begin rdoc
188
+ As @IO#each_byte@
189
+
190
+ @raise [IOError] when called with a block because the stream is not open for reading
191
+ @return [Enumerator] an enumerator which calls {#each_byte} when called without a block
192
+ =end
193
+ def each_byte
194
+ raise IOError, "not opened for reading" if block_given?
195
+ to_enum :each_byte
196
+ end
197
+
198
+ =begin rdoc
199
+ As @IO#each_char@
200
+
201
+ @raise [IOError] when called with a block because the stream is not open for reading
202
+ @return [Enumerator] an enumerator which calls {#each_char} when called without a block
203
+ =end
204
+ def each_char
205
+ raise IOError, "not opened for reading" if block_given?
206
+ to_enum :each_char
207
+ end
208
+
209
+ =begin rdoc
210
+ As @IO#each@
211
+
212
+ @raise [IOError] when called with a block because the stream is not open for reading
213
+ @return [Enumerator] an enumerator which calls {#each_line} when called without a block
214
+ =end
215
+ def each_line sep
216
+ raise IOError, "not opened for reading" if block_given?
217
+ to_enum :each_line
218
+ end
219
+
220
+ =begin rdoc
221
+ As @IO#eof@
222
+
223
+ @raise [IOError] always because the stream is not open for reading
224
+ @return [nil]
225
+ =end
226
+ def eof
227
+ raise IOError, "not opened for reading"
228
+ end
229
+
230
+ =begin rdoc
231
+ As @IO#eof?@
232
+
233
+ @raise [IOError] always because the stream is not open for reading
234
+ @return [nil]
235
+ =end
236
+ def eof?
237
+ raise IOError, "not opened for reading"
238
+ end
239
+
240
+ =begin rdoc
241
+ As @IO#external_encoding@
242
+
243
+ @return [nil]
244
+ =end
245
+ def external_encoding
246
+ nil
247
+ end
248
+
249
+ =begin rdoc
250
+ As @IO#fileno@
251
+
252
+ @return [Integer] the third argument passed to the constructor
253
+ =end
254
+ def fileno
255
+ @fileno
256
+ end
257
+
258
+ =begin rdoc
259
+ As @IO#flush@
260
+
261
+ As this class doesn't do any buffering, this method does nothing and is only
262
+ provided for compatibility with @IO@ API
263
+
264
+ @return [Output] *self*
265
+ =end
266
+ def flush
267
+ self
268
+ end
269
+
270
+ =begin rdoc
271
+ As @IO#getbyte@
272
+
273
+ @raise [IOError] always because the stream is not open for reading
274
+ @return [nil]
275
+ =end
276
+ def getbyte
277
+ raise IOError, "not opened for reading"
278
+ end
279
+
280
+ =begin rdoc
281
+ As @IO#getc@
282
+
283
+ @raise [IOError] always because the stream is not open for reading
284
+ @return [nil]
285
+ =end
286
+ def getc
287
+ raise IOError, "not opened for reading"
288
+ end
289
+
290
+ =begin rdoc
291
+ As @IO#gets@
292
+
293
+ @raise [IOError] always because the stream is not open for reading
294
+ @return [nil]
295
+ =end
296
+ def gets
297
+ raise IOError, "not opened for reading"
298
+ end
299
+
300
+ =begin rdoc
301
+ As @IO#internal_encoding@
302
+
303
+ @return [nil]
304
+ =end
305
+ def internal_encoding
306
+ nil
307
+ end
308
+
309
+ =begin rdoc
310
+ As @IO#isatty@
311
+
312
+ @return [false]
313
+ =end
314
+ def isatty
315
+ false
316
+ end
317
+ alias_method :tty?, :isatty
318
+
319
+ =begin rdoc
320
+ As @IO#lineno@
321
+
322
+ @raise [IOError] always because the stream is not open for reading
323
+ @return [nil]
324
+ =end
325
+ def lineno
326
+ raise IOError, "not opened for reading"
327
+ end
328
+
329
+ =begin rdoc
330
+ As @IO#lineno=@
331
+
332
+ @raise [IOError] always because the stream is not open for reading
333
+ @return [nil]
334
+ =end
335
+ def lineno= val
336
+ raise IOError, "not opened for reading"
337
+ end
338
+
339
+ =begin rdoc
340
+ As @IO#lines@
341
+
342
+ @return [Enumerator] an enumerator which calls {#each_line}
343
+ =end
344
+ def lines
345
+ each_line
346
+ end
347
+
348
+ =begin rdoc
349
+ As @IO#pid@
350
+
351
+ @return [nil]
352
+ =end
353
+ def pid
354
+ nil
355
+ end
356
+
357
+ =begin rdoc
358
+ As @IO#print@
359
+
360
+ @param [Array<Object>] args the objects to print
361
+ @return [nil]
362
+ =end
363
+ def print *args
364
+ args = [$_] if args.empty?
365
+ args.each{|a| write a}
366
+ STDOUT.write $\
367
+ write $\ if $\
368
+ nil
369
+ end
370
+
371
+ =begin rdoc
372
+ As @IO#printf@
373
+
374
+ @param [String] format_string the format string. See @Kernel.sprintf@
375
+ @param [Array<Object>] args the parameter to substitute in the format string
376
+ @return [nil]
377
+ =end
378
+ def printf format_string, *args
379
+ str = sprintf format_string, *args
380
+ write str
381
+ nil
382
+ end
383
+
384
+ =begin rdoc
385
+ As @IO#putc@
386
+
387
+ @param [Object] obj the object
388
+ @return [Object] obj
389
+ =end
390
+ def putc obj
391
+ if obj.is_a? Numeric then write obj.floor.chr
392
+ else obj.to_s.each_char.to_a[0]
393
+ end
394
+ obj
395
+ end
396
+
397
+ =begin rdoc
398
+ As @IO#puts@
399
+
400
+ @param [Array<Object>] args the objects to write
401
+ @return [nil]
402
+ =end
403
+ def puts *args
404
+ args << '' if args.empty?
405
+ args.each do |a|
406
+ a = a.to_s
407
+ write a
408
+ write "\n" unless a.end_with? "\n"
409
+ end
410
+ nil
411
+ end
412
+
413
+ =begin rdoc
414
+ As @IO#read@
415
+
416
+ @raise [IOError] always because the stream is not open for reading
417
+ @param [Integer] length unused
418
+ @param [String] buffer unused
419
+ @return [nil]
420
+ =end
421
+ def read length, buffer = nil
422
+ raise IOError, "not opened for reading"
423
+ end
424
+
425
+ =begin rdoc
426
+ As @IO#read_nonblock@
427
+
428
+ @raise [IOError] always because the stream is not open for reading
429
+ @param [Integer] max unused
430
+ @param [String] outbuf unused
431
+ @return [nil]
432
+ =end
433
+ def read_nonblock max, outbuf = nil
434
+ raise IOError, "not opened for reading"
435
+ end
436
+
437
+ =begin rdoc
438
+ As @IO#readbyte@
439
+
440
+ @raise [IOError] always because the stream is not open for reading
441
+ @return [nil]
442
+ =end
443
+ def readbyte
444
+ raise IOError, "not opened for reading"
445
+ end
446
+
447
+ =begin rdoc
448
+ As @IO#readchar@
449
+
450
+ @raise [IOError] always because the stream is not open for reading
451
+ @return [nil]
452
+ =end
453
+ def readchar
454
+ raise IOError, "not opened for reading"
455
+ end
456
+
457
+ =begin rdoc
458
+ As @IO#readline@
459
+
460
+ @raise [IOError] always because the stream is not open for reading
461
+ @param [String] sep unused
462
+ @param [Integer] limit unused
463
+ @return [nil]
464
+ =end
465
+ def readline sep, limit
466
+ raise IOError, "not opened for reading"
467
+ end
468
+
469
+ =begin rdoc
470
+ As @IO#readlines@
471
+
472
+ @raise [IOError] always because the stream is not open for reading
473
+ @param [String] sep unused
474
+ @param [Integer] limit unused
475
+ @return [nil]
476
+ =end
477
+ def readlines sep, limit
478
+ raise IOError, "not opened for reading"
479
+ end
480
+
481
+ =begin rdoc
482
+ As @IO#readpartial@
483
+
484
+ @raise [IOError] always because the stream is not open for reading
485
+ @param [Integer] maxlen unused
486
+ @param [String] outbuf unused
487
+ @return [nil]
488
+ =end
489
+ def readpartial maxlen, outbuf = nil
490
+ raise IOError, "not opened for reading"
491
+ end
492
+
493
+ =begin rdoc
494
+ As @IO#reopen@
495
+
496
+ @raise [RuntimeError] always
497
+ @param [String,IO] a path or another IO. Unused
498
+ @param [String] the mode. Unused
499
+ @return [nil]
500
+ =end
501
+ def reopen arg1, arg2 = 'r'
502
+ raise RuntimeError, "You can\'t reopen #{self.class}"
503
+ end
504
+
505
+ =begin rdoc
506
+ As @IO#set_encoding@
507
+
508
+ This method does nothing. It's only provided for compatibility with @IO@ API
509
+ @param [Array<Object>] args the arguments. See @IO#set_encoding@
510
+ =end
511
+ def set_encoding *args
512
+ end
513
+
514
+ =begin rdoc
515
+ As @IO#stat@
516
+
517
+ @return [nil] as this class isn't associated with any file
518
+ =end
519
+ def stat
520
+ nil
521
+ end
522
+
523
+ =begin rdoc
524
+ As @IO#sysread@
525
+
526
+ @raise [IOError] always because the stream is not open for reading
527
+ @param [Integer] num unused
528
+ @param [String] outbuf unused
529
+ @return [nil]
530
+ =end
531
+ def sysread num, outbuf = nil
532
+ raise IOError, "not opened for reading"
533
+ end
534
+
535
+ =begin rdoc
536
+ As @IO#to_io@
537
+
538
+ @return [Output] self
539
+ =end
540
+ def to_io
541
+ self
542
+ end
543
+
544
+ =begin rdoc
545
+ As @IO#ungetbyte@
546
+
547
+ @raise [IOError] always because the stream is not open for reading
548
+ @param [String,Integer] arg unused
549
+ @return [nil]
550
+ =end
551
+ def ungetbyte arg
552
+ raise IOError, "not opened for reading"
553
+ end
554
+
555
+ =begin rdoc
556
+ As @IO#ungetc@
557
+
558
+ @raise [IOError] always because the stream is not open for reading
559
+ @param [String] str unused
560
+ @return [nil]
561
+ =end
562
+ def ungetc str
563
+ raise IOError, "not opened for reading"
564
+ end
565
+
566
+ =begin rdoc
567
+ As @IO#write@
568
+
569
+ @param [Object] obj the object to write
570
+ @raise [IOError] if the stream has been closed
571
+ @return [Integer] the number of written bytes
572
+ =end
573
+ def write obj
574
+ if !@closed
575
+ cur = @widget.text_cursor
576
+ cur.move_position Qt::TextCursor::End
577
+ text = obj.to_s
578
+ format = cur.char_format
579
+ format.foreground = @brush
580
+ cur.insert_text text, format
581
+ text.bytes.count
582
+ else raise IOError, 'closed stream'
583
+ end
584
+ end
585
+ alias_method :syswrite, :write
586
+ alias_method :write_nonblock, :write
587
+
588
+ end
589
+
590
+ end
591
+
592
+ end