Browse Source

Change all command output/error to use events.

pull/442/head
Chris Smith 8 years ago
parent
commit
c6376f4cc2

+ 2
- 2
audio/src/com/dmdirc/addons/audio/AudioCommand.java View File

@@ -64,10 +64,10 @@ public class AudioCommand extends Command {
64 64
             if (AudioPlayer.isValid(file)) {
65 65
                 new AudioPlayer(file).play();
66 66
             } else {
67
-                sendLine(origin, args.isSilent(), FORMAT_ERROR, "Invalid file type");
67
+                showError(origin, args.isSilent(), "Invalid file type");
68 68
             }
69 69
         } else {
70
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, "File does not exist");
70
+            showError(origin, args.isSilent(), "File does not exist");
71 71
         }
72 72
     }
73 73
 

+ 4
- 8
calc/src/com/dmdirc/addons/calc/CalcCommand.java View File

@@ -64,8 +64,7 @@ public class CalcCommand extends Command {
64 64
             int offset = 0;
65 65
             boolean showexpr = false;
66 66
 
67
-            if (args.getArguments().length > 0 && args.getArguments()[0]
68
-                    .equals("--showexpr")) {
67
+            if (args.getArguments().length > 0 && "--showexpr".equals(args.getArguments()[0])) {
69 68
                 showexpr = true;
70 69
                 offset++;
71 70
             }
@@ -75,14 +74,11 @@ public class CalcCommand extends Command {
75 74
             final Parser parser = new Parser(lexer);
76 75
             final Evaluator evaluator = new Evaluator(parser.parse());
77 76
             final Number result = evaluator.evaluate();
78
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
79
-                    (showexpr ? input + " = " : "") + result);
77
+            showOutput(origin, args.isSilent(), (showexpr ? input + " = " : "") + result);
80 78
         } catch (ParseException ex) {
81
-            sendLine(origin, args.isSilent(), FORMAT_ERROR,
82
-                    "Unable to parse expression: " + ex.getMessage());
79
+            showError(origin, args.isSilent(), "Unable to parse expression: " + ex.getMessage());
83 80
         } catch (ArithmeticException ex) {
84
-            sendLine(origin, args.isSilent(), FORMAT_ERROR,
85
-                    "Unable to calculate expression: " + ex.getMessage());
81
+            showError(origin, args.isSilent(), "Unable to calculate expression: " + ex.getMessage());
86 82
         }
87 83
     }
88 84
 

+ 73
- 79
conditional_execute/src/com/dmdirc/addons/conditional_execute/ConditionalExecuteCommand.java View File

@@ -72,88 +72,86 @@ public class ConditionalExecuteCommand extends Command {
72 72
             final String arg = arguments[i].toLowerCase();
73 73
             final String nextArg = i + 1 < arguments.length ? arguments[i + 1] : "";
74 74
 
75
-            if (arg.equalsIgnoreCase("--help")) {
76
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Usage:");
77
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "");
78
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, cmdname + " <args>");
79
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, cmdname
75
+            if ("--help".equalsIgnoreCase(arg)) {
76
+                showOutput(origin, args.isSilent(), "Usage:");
77
+                showOutput(origin, args.isSilent(), "");
78
+                showOutput(origin, args.isSilent(), cmdname + " <args>");
79
+                showOutput(origin, args.isSilent(), cmdname
80 80
                         + " --namespace <name> <namespace commands>");
81
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, cmdname
81
+                showOutput(origin, args.isSilent(), cmdname
82 82
                         + " --namespace <name> [--inverse] </commandToRun <command args>>");
83
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "");
84
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
83
+                showOutput(origin, args.isSilent(), "");
84
+                showOutput(origin, args.isSilent(),
85 85
                         "Commands can only be specified if no other non-namespace args are given.");
86
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "");
87
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
86
+                showOutput(origin, args.isSilent(), "");
87
+                showOutput(origin, args.isSilent(),
88 88
                         "When trying to run a command, the namespace will be checked to see if the command can be run.");
89
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
89
+                showOutput(origin, args.isSilent(),
90 90
                         "The checks performed are as follows:");
91
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
91
+                showOutput(origin, args.isSilent(),
92 92
                         "   1) Does the namespace exist? if not, run the command and create the namespace.");
93
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
93
+                showOutput(origin, args.isSilent(),
94 94
                         "   2) Is the namespace inhibited? - Do not run the command.");
95
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
95
+                showOutput(origin, args.isSilent(),
96 96
                         "   3) Is the namespace in forced mode? - Run the command.");
97
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
97
+                showOutput(origin, args.isSilent(),
98 98
                         "   4) If --inverse is specified, are we under the limit time? Run the command");
99
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
99
+                showOutput(origin, args.isSilent(),
100 100
                         "   5) If --inverse is not specified, are we over the limit time? Run the command");
101
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "   6) Do not run the command.");
102
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "");
103
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "General Arguments.");
104
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
101
+                showOutput(origin, args.isSilent(), "   6) Do not run the command.");
102
+                showOutput(origin, args.isSilent(), "");
103
+                showOutput(origin, args.isSilent(), "General Arguments.");
104
+                showOutput(origin, args.isSilent(),
105 105
                         "  --list                   - List all current namespaces and their status");
106
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
106
+                showOutput(origin, args.isSilent(),
107 107
                         "  --help                   - Print this help.");
108
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
108
+                showOutput(origin, args.isSilent(),
109 109
                         "  --reset                  - Remove all namespaces.");
110
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "");
111
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Useful things:");
112
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
110
+                showOutput(origin, args.isSilent(), "");
111
+                showOutput(origin, args.isSilent(), "Useful things:");
112
+                showOutput(origin, args.isSilent(),
113 113
                         "  --namespace <name>       - Namespace to modify. If the namespace does not exist, it will be created. Namespaces are not remembered across sessions.");
114
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "");
115
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Arguments related to a namespace:");
116
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
114
+                showOutput(origin, args.isSilent(), "");
115
+                showOutput(origin, args.isSilent(), "Arguments related to a namespace:");
116
+                showOutput(origin, args.isSilent(),
117 117
                         "  --settime <time>         - Set the limit time on this namespace. Time can be either a time in seconds, 'now' for now, or 'nowifless' to set to now only if it is currently less.");
118
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
118
+                showOutput(origin, args.isSilent(),
119 119
                         "  --delay <seconds>        - Increase the 'limit' time on this namespace by <seconds> seconds");
120
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
120
+                showOutput(origin, args.isSilent(),
121 121
                         "  --inhibit                - Prevent any attempts at running commands in this namespace from executing");
122
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
122
+                showOutput(origin, args.isSilent(),
123 123
                         "  --force                  - Any future attempts at running commands in this namespace will always execute");
124
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
124
+                showOutput(origin, args.isSilent(),
125 125
                         "  --allow                  - Disable '--force' or '--inhibit' and resume normal operation.");
126
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
126
+                showOutput(origin, args.isSilent(),
127 127
                         "  --remove                 - Remove this namespace.");
128
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
128
+                showOutput(origin, args.isSilent(),
129 129
                         "  --status                 - Show the status of this namespace.");
130
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "");
131
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Arguments when running a command:");
132
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
130
+                showOutput(origin, args.isSilent(), "");
131
+                showOutput(origin, args.isSilent(), "Arguments when running a command:");
132
+                showOutput(origin, args.isSilent(),
133 133
                         "  --inverse              - Inverse the match against the 'limit' time.");
134 134
                 return;
135
-            } else if (arg.equalsIgnoreCase("--list")) {
135
+            } else if ("--list".equalsIgnoreCase(arg)) {
136 136
                 if (namespaces.isEmpty()) {
137
-                    sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
137
+                    showOutput(origin, args.isSilent(),
138 138
                             "There are currently no known namespaces.");
139 139
                 } else {
140
-                    sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Current namespaces: ");
140
+                    showOutput(origin, args.isSilent(), "Current namespaces: ");
141 141
                     for (final Map.Entry<String, ConditionalExecuteNamespace> e : namespaces.
142 142
                             entrySet()) {
143
-                        sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "    " + e.getValue().
144
-                                toString());
143
+                        showOutput(origin, args.isSilent(),"    " + e.getValue());
145 144
                     }
146 145
                 }
147 146
                 return;
148
-            } else if (arg.equalsIgnoreCase("--reset")) {
147
+            } else if ("--reset".equalsIgnoreCase(arg)) {
149 148
                 namespaces.clear();
150
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "All namespaces removed.");
149
+                showOutput(origin, args.isSilent(), "All namespaces removed.");
151 150
                 return;
152 151
             } else if (namespace == null) {
153
-                if (arg.equalsIgnoreCase("--namespace")) {
152
+                if ("--namespace".equalsIgnoreCase(arg)) {
154 153
                     if (nextArg.isEmpty()) {
155
-                        sendLine(origin, args.isSilent(), FORMAT_ERROR,
156
-                                "Error: You must specify a namespace.");
154
+                        showError(origin, args.isSilent(), "Error: You must specify a namespace.");
157 155
                         return;
158 156
                     } else {
159 157
                         if (!namespaces.containsKey(nextArg.toLowerCase())) {
@@ -166,29 +164,28 @@ public class ConditionalExecuteCommand extends Command {
166 164
                         i++;
167 165
                     }
168 166
                 } else {
169
-                    sendLine(origin, args.isSilent(), FORMAT_ERROR,
167
+                    showError(origin, args.isSilent(),
170 168
                             "Error: You must specify a namespace first.");
171 169
                     return;
172 170
                 }
173
-            } else if (arg.equalsIgnoreCase("--inhibit")) {
171
+            } else if ("--inhibit".equalsIgnoreCase(arg)) {
174 172
                 namespace.inhibit();
175 173
                 manipulated = true;
176
-            } else if (arg.equalsIgnoreCase("--force")) {
174
+            } else if ("--force".equalsIgnoreCase(arg)) {
177 175
                 namespace.force();
178 176
                 manipulated = true;
179
-            } else if (arg.equalsIgnoreCase("--allow")) {
177
+            } else if ("--allow".equalsIgnoreCase(arg)) {
180 178
                 namespace.reset();
181 179
                 manipulated = true;
182
-            } else if (arg.equalsIgnoreCase("--settime")) {
180
+            } else if ("--settime".equalsIgnoreCase(arg)) {
183 181
                 if (nextArg.isEmpty()) {
184
-                    sendLine(origin, args.isSilent(), FORMAT_ERROR,
185
-                            "Error: You must provide a time to use.");
182
+                    showError(origin, args.isSilent(), "Error: You must provide a time to use.");
186 183
                     return;
187
-                } else if (nextArg.equalsIgnoreCase("now")) {
184
+                } else if ("now".equalsIgnoreCase(nextArg)) {
188 185
                     namespace.setLimit(System.currentTimeMillis());
189 186
                     i++;
190 187
                     manipulated = true;
191
-                } else if (nextArg.equalsIgnoreCase("nowifless")) {
188
+                } else if ("nowifless".equalsIgnoreCase(nextArg)) {
192 189
                     if (namespace.getLimitTime() < System.currentTimeMillis()) {
193 190
                         namespace.setLimit(System.currentTimeMillis());
194 191
                     }
@@ -200,15 +197,13 @@ public class ConditionalExecuteCommand extends Command {
200 197
                         i++;
201 198
                         manipulated = true;
202 199
                     } catch (final NumberFormatException nfe) {
203
-                        sendLine(origin, args.isSilent(), FORMAT_ERROR, "Error: Invalid time: "
204
-                                + nextArg);
200
+                        showError(origin, args.isSilent(), "Error: Invalid time: " + nextArg);
205 201
                         return;
206 202
                     }
207 203
                 }
208
-            } else if (arg.equalsIgnoreCase("--delay")) {
204
+            } else if ("--delay".equalsIgnoreCase(arg)) {
209 205
                 if (nextArg.isEmpty()) {
210
-                    sendLine(origin, args.isSilent(), FORMAT_ERROR,
211
-                            "Error: You must provide a delay to use.");
206
+                    showError(origin, args.isSilent(),  "Error: You must provide a delay to use.");
212 207
                     return;
213 208
                 } else {
214 209
                     try {
@@ -216,24 +211,23 @@ public class ConditionalExecuteCommand extends Command {
216 211
                         i++;
217 212
                         manipulated = true;
218 213
                     } catch (final NumberFormatException nfe) {
219
-                        sendLine(origin, args.isSilent(), FORMAT_ERROR, "Error: Invalid delay: "
220
-                                + nextArg);
214
+                        showError(origin, args.isSilent(), "Error: Invalid delay: " + nextArg);
221 215
                         return;
222 216
                     }
223 217
                 }
224
-            } else if (arg.equalsIgnoreCase("--remove")) {
218
+            } else if ("--remove".equalsIgnoreCase(arg)) {
225 219
                 namespaces.remove(namespace.getName());
226
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Removed namespace '" + namespace.
227
-                        getName() + "'");
220
+                showOutput(origin, args.isSilent(),
221
+                        "Removed namespace '" + namespace.getName() + '\'');
228 222
                 return;
229
-            } else if (arg.equalsIgnoreCase("--status")) {
223
+            } else if ("--status".equalsIgnoreCase(arg)) {
230 224
                 // Show the current status, in case some manipulations occurred prior to this.
231
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, namespaces.get(namespace.getName()));
225
+                showOutput(origin, args.isSilent(), namespaces.get(namespace.getName()).toString());
232 226
                 return;
233
-            } else if (arg.equalsIgnoreCase("--inverse")) {
227
+            } else if ("--inverse".equalsIgnoreCase(arg)) {
234 228
                 inverse = true;
235 229
             } else if (manipulated) {
236
-                sendLine(origin, args.isSilent(), FORMAT_ERROR,
230
+                showError(origin, args.isSilent(),
237 231
                         "You can't run commands and manipulate the namespace at the same time, ignored.");
238 232
             } else {
239 233
                 // Command to run!
@@ -246,19 +240,19 @@ public class ConditionalExecuteCommand extends Command {
246 240
 
247 241
         // If we get here, we either manipulated something, or should show the usage text.
248 242
         if (manipulated) {
249
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Namespace updated.");
250
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, namespace.toString());
243
+            showOutput(origin, args.isSilent(), "Namespace updated.");
244
+            showOutput(origin, args.isSilent(), namespace.toString());
251 245
             namespaces.put(namespace.getName(), namespace);
252 246
         } else {
253
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, "Usage:");
254
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, "");
255
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, cmdname + " <args>");
256
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, cmdname
247
+            showError(origin, args.isSilent(), "Usage:");
248
+            showError(origin, args.isSilent(), "");
249
+            showError(origin, args.isSilent(), cmdname + " <args>");
250
+            showError(origin, args.isSilent(), cmdname
257 251
                     + " --namespace <name> <namespace commands>");
258
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, cmdname
252
+            showError(origin, args.isSilent(), cmdname
259 253
                     + " --namespace <name> [--inverse] </commandToRun <command args>>");
260
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, "");
261
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, "For more information, see " + cmdname
254
+            showError(origin, args.isSilent(), "");
255
+            showError(origin, args.isSilent(), "For more information, see " + cmdname
262 256
                     + " --help");
263 257
         }
264 258
     }

+ 11
- 3
conditional_execute/test/com/dmdirc/addons/conditional_execute/ConditionalExecuteCommandTest.java View File

@@ -22,20 +22,24 @@
22 22
 
23 23
 package com.dmdirc.addons.conditional_execute;
24 24
 
25
+import com.dmdirc.DMDircMBassador;
25 26
 import com.dmdirc.commandparser.CommandArguments;
26 27
 import com.dmdirc.commandparser.commands.context.CommandContext;
27 28
 import com.dmdirc.commandparser.parsers.CommandParser;
29
+import com.dmdirc.events.CommandErrorEvent;
28 30
 import com.dmdirc.interfaces.CommandController;
29 31
 import com.dmdirc.interfaces.WindowModel;
30 32
 
31 33
 import org.junit.Before;
32 34
 import org.junit.Test;
33 35
 import org.junit.runner.RunWith;
36
+import org.mockito.ArgumentCaptor;
37
+import org.mockito.Captor;
34 38
 import org.mockito.Mock;
35 39
 import org.mockito.runners.MockitoJUnitRunner;
36 40
 
41
+import static org.junit.Assert.assertTrue;
37 42
 import static org.mockito.Matchers.anyString;
38
-import static org.mockito.Matchers.contains;
39 43
 import static org.mockito.Matchers.eq;
40 44
 import static org.mockito.Matchers.same;
41 45
 import static org.mockito.Mockito.never;
@@ -49,6 +53,8 @@ public class ConditionalExecuteCommandTest {
49 53
     @Mock private CommandParser commandParser;
50 54
     @Mock private WindowModel container;
51 55
     @Mock private CommandContext context;
56
+    @Mock private DMDircMBassador eventbus;
57
+    @Captor private ArgumentCaptor<CommandErrorEvent> errorEventCaptor;
52 58
     private ConditionalExecuteCommand command;
53 59
 
54 60
     @Before
@@ -57,6 +63,7 @@ public class ConditionalExecuteCommandTest {
57 63
         when(commandController.getSilenceChar()).thenReturn('/');
58 64
         when(container.getCommandParser()).thenReturn(commandParser);
59 65
         when(container.isWritable()).thenReturn(true);
66
+        when(container.getEventBus()).thenReturn(eventbus);
60 67
 
61 68
         command = new ConditionalExecuteCommand(commandController);
62 69
     }
@@ -166,8 +173,9 @@ public class ConditionalExecuteCommandTest {
166 173
         verify(commandParser, never()).parseCommand(same(container), anyString());
167 174
     }
168 175
 
169
-    private void verifyErrorOutput(final String substring) {
170
-        verify(container).addLine(eq("commandError"), contains(substring));
176
+    private void verifyErrorOutput(final CharSequence substring) {
177
+        verify(eventbus).publishAsync(errorEventCaptor.capture());
178
+        assertTrue(errorEventCaptor.getValue().getMessage().contains(substring));
171 179
     }
172 180
 
173 181
 }

+ 2
- 4
dcc/src/com/dmdirc/addons/dcc/DCCCommand.java View File

@@ -138,8 +138,7 @@ public class DCCCommand extends Command implements IntelligentCommand {
138 138
                 sendFile(target, origin, connection, true,
139 139
                         args.getArgumentsAsString(2));
140 140
             } else {
141
-                sendLine(origin, args.isSilent(), FORMAT_ERROR,
142
-                        "Unknown DCC Type: '" + type + "'");
141
+                showError(origin, args.isSilent(), "Unknown DCC Type: '" + type + '\'');
143 142
             }
144 143
         } else {
145 144
             showUsage(origin, true, INFO.getName(), INFO.getHelp());
@@ -229,8 +228,7 @@ public class DCCCommand extends Command implements IntelligentCommand {
229 228
             eventBus.publish(new DccSendRequestEvent(connection, target, selectedFile.
230 229
                     getAbsolutePath()));
231 230
 
232
-            sendLine(origin, isSilent, FORMAT_OUTPUT,
233
-                    "Starting DCC Send with: " + target);
231
+            showOutput(origin, isSilent, "Starting DCC Send with: " + target);
234 232
 
235 233
             send.setFileName(selectedFile.getAbsolutePath());
236 234
             send.setFileSize(selectedFile.length());

+ 1
- 1
dcop/src/com/dmdirc/addons/dcop/DcopCommand.java View File

@@ -73,7 +73,7 @@ public class DcopCommand extends Command {
73 73
 
74 74
         final List<String> res = executor.getDcopResult(arguments[0], arguments[1], arguments[2]);
75 75
         for (String line : res) {
76
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, line);
76
+            showOutput(origin, args.isSilent(), line);
77 77
         }
78 78
     }
79 79
 

+ 1
- 0
debug/src/com/dmdirc/addons/debug/Debug.java View File

@@ -109,6 +109,7 @@ public class Debug extends Command implements IntelligentCommand {
109 109
      * @param type     The type of message to send
110 110
      * @param args     The arguments of the message
111 111
      */
112
+    @Deprecated
112 113
     public void proxySendLine(final WindowModel target,
113 114
             final boolean isSilent, final String type, final Object... args) {
114 115
         sendLine(target, isSilent, type, args);

+ 3
- 3
dns/src/com/dmdirc/addons/dns/DNSCommand.java View File

@@ -71,7 +71,7 @@ public class DNSCommand extends Command {
71 71
             return;
72 72
         }
73 73
 
74
-        sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Resolving: " + args.getArguments()[0]);
74
+        showOutput(origin, args.isSilent(), "Resolving: " + args.getArguments()[0]);
75 75
         new Timer("DNS Command Timer").schedule(new TimerTask() {
76 76
 
77 77
             @Override
@@ -85,10 +85,10 @@ public class DNSCommand extends Command {
85 85
             final String arg) {
86 86
         try {
87 87
             final InetAddress address = InetAddresses.forString(arg);
88
-            sendLine(origin, isSilent, FORMAT_OUTPUT, "Resolved: "
88
+            showOutput(origin, isSilent, "Resolved: "
89 89
                     + arg + ": " + address.getCanonicalHostName());
90 90
         } catch (IllegalArgumentException ex) {
91
-            sendLine(origin, isSilent, FORMAT_OUTPUT, "Resolved: "
91
+            showOutput(origin, isSilent, "Resolved: "
92 92
                     + arg + ": " + getIPs(arg));
93 93
         }
94 94
     }

+ 4
- 4
exec/src/com/dmdirc/addons/exec/ExecCommand.java View File

@@ -72,10 +72,10 @@ public class ExecCommand extends Command {
72 72
             // This checks the command to execute has correct quotes
73 73
             // (if necessary). Without this /exec "command arg1 arg2 would error.
74 74
             if (commandArray.length == 0) {
75
-                sendLine(origin, args.isSilent(), FORMAT_ERROR,
75
+                showError(origin, args.isSilent(),
76 76
                         "Could not execute: Invalid file name provided");
77 77
             } else if (!new File(commandArray[0]).exists()) {
78
-                sendLine(origin, args.isSilent(), FORMAT_ERROR,
78
+                showError(origin, args.isSilent(),
79 79
                         "Could not execute: " + commandArray[0] + " does not exist.");
80 80
             } else {
81 81
                 final Process p = Runtime.getRuntime().exec(commandArray);
@@ -88,10 +88,10 @@ public class ExecCommand extends Command {
88 88
                     final List<String> errorOutput = CharStreams.readLines(
89 89
                             new InputStreamReader(p.getErrorStream()));
90 90
                     for (String line : execOutput) {
91
-                        sendLine(origin, args.isSilent(), FORMAT_OUTPUT, line);
91
+                        showOutput(origin, args.isSilent(), line);
92 92
                     }
93 93
                     for (String line : errorOutput) {
94
-                        sendLine(origin, args.isSilent(), FORMAT_ERROR, line);
94
+                        showError(origin, args.isSilent(), line);
95 95
                     }
96 96
                 }
97 97
             }

+ 7
- 8
logging/src/com/dmdirc/addons/logging/LoggingCommand.java View File

@@ -67,21 +67,20 @@ public class LoggingCommand extends Command implements IntelligentCommand {
67 67
         if (args.getArguments().length > 0) {
68 68
             if ("history".equalsIgnoreCase(args.getArguments()[0])) {
69 69
                 if (!manager.showHistory(origin)) {
70
-                    sendLine(origin, args.isSilent(), FORMAT_ERROR,
71
-                            "Unable to open history for this window.");
70
+                    showError(origin, args.isSilent(), "Unable to open history for this window.");
72 71
                 }
73 72
             } else if ("help".equalsIgnoreCase(args.getArguments()[0])) {
74
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, LOGGING
73
+                showOutput(origin, args.isSilent(), LOGGING
75 74
                         + " history          - Open the history of this window, if available.");
76
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, LOGGING
75
+                showOutput(origin, args.isSilent(), LOGGING
77 76
                         + " help             - Show this help.");
78 77
             } else {
79
-                sendLine(origin, args.isSilent(), FORMAT_ERROR, "Unknown command '" + args.
80
-                        getArguments()[0] + "'. Use " + LOGGING + " help for a list of commands.");
78
+                showError(origin, args.isSilent(), "Unknown command '"
79
+                        + args.getArguments()[0] + "'. Use " + LOGGING
80
+                        + " help for a list of commands.");
81 81
             }
82 82
         } else {
83
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, "Use " + LOGGING
84
-                    + " help for a list of commands.");
83
+            showError(origin, args.isSilent(), "Use " + LOGGING + " help for a list of commands.");
85 84
         }
86 85
     }
87 86
 

+ 2
- 3
nma/src/com/dmdirc/addons/nma/NotifyMyAndroidCommand.java View File

@@ -85,11 +85,10 @@ public class NotifyMyAndroidCommand extends Command {
85 85
         new Thread(() -> {
86 86
             try {
87 87
                 client.notify(parts[0], parts[1]);
88
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Notification sent");
88
+                showOutput(origin, args.isSilent(), "Notification sent");
89 89
             } catch (IOException ex) {
90 90
                 LOG.info("Exception when trying to notify NMA", ex);
91
-                sendLine(origin, args.isSilent(), FORMAT_ERROR, "Unable to send: " + ex.
92
-                        getMessage());
91
+                showError(origin, args.isSilent(), "Unable to send: " + ex.getMessage());
93 92
             }
94 93
         }, "NMA Thread").start();
95 94
     }

+ 5
- 8
notifications/src/com/dmdirc/addons/notifications/NotificationCommand.java View File

@@ -79,20 +79,18 @@ public class NotificationCommand extends Command implements
79 79
                 final NotificationHandler handler = manager.getHandler(sourceName);
80 80
 
81 81
                 if (handler == null) {
82
-                    sendLine(origin, args.isSilent(), FORMAT_ERROR,
83
-                            "Method not found.");
82
+                    showError(origin, args.isSilent(), "Method not found.");
84 83
                 } else {
85 84
                     handler.showNotification("DMDirc", args.getArgumentsAsString(2));
86 85
                 }
87 86
             } else {
88
-                sendLine(origin, args.isSilent(), FORMAT_ERROR,
87
+                showError(origin, args.isSilent(),
89 88
                         "You must specify a method when using --method.");
90 89
             }
91 90
         } else if (manager.hasActiveHandler()) {
92 91
             manager.getPreferredHandler().showNotification("DMDirc", args.getArgumentsAsString(0));
93 92
         } else {
94
-            sendLine(origin, args.isSilent(), FORMAT_ERROR,
95
-                    "No active notification methods available.");
93
+            showError(origin, args.isSilent(), "No active notification methods available.");
96 94
         }
97 95
     }
98 96
 
@@ -107,8 +105,7 @@ public class NotificationCommand extends Command implements
107 105
         final Collection<String> handlers = manager.getHandlerNames();
108 106
 
109 107
         if (handlers.isEmpty()) {
110
-            sendLine(origin, isSilent, FORMAT_ERROR, "No notification "
111
-                    + "methods available.");
108
+            showError(origin, isSilent, "No notification methods available.");
112 109
         } else {
113 110
             final String[] headers = {"Method"};
114 111
             final String[][] data = new String[handlers.size()][1];
@@ -118,7 +115,7 @@ public class NotificationCommand extends Command implements
118 115
                 i++;
119 116
             }
120 117
 
121
-            sendLine(origin, isSilent, FORMAT_OUTPUT, doTable(headers, data));
118
+            showOutput(origin, isSilent, doTable(headers, data));
122 119
         }
123 120
     }
124 121
 

+ 6
- 7
nowplaying/src/com/dmdirc/addons/nowplaying/NowPlayingCommand.java View File

@@ -101,17 +101,17 @@ public class NowPlayingCommand extends Command implements IntelligentCommand {
101 101
                 final MediaSource source = manager.getSource(sourceName);
102 102
 
103 103
                 if (source == null) {
104
-                    sendLine(origin, args.isSilent(), FORMAT_ERROR, "Source not found.");
104
+                    showError(origin, args.isSilent(), "Source not found.");
105 105
                 } else {
106 106
                     if (source.getState() == MediaSourceState.CLOSED) {
107
-                        sendLine(origin, args.isSilent(), FORMAT_ERROR, "Source is not running.");
107
+                        showError(origin, args.isSilent(), "Source is not running.");
108 108
                     } else {
109 109
                         target.getWindowModel().getCommandParser().parseCommand(origin,
110 110
                                 getInformation(source, args.getArgumentsAsString(2)));
111 111
                     }
112 112
                 }
113 113
             } else {
114
-                sendLine(origin, args.isSilent(), FORMAT_ERROR,
114
+                showError(origin, args.isSilent(),
115 115
                         "You must specify a source when using --source.");
116 116
             }
117 117
         } else {
@@ -120,8 +120,7 @@ public class NowPlayingCommand extends Command implements IntelligentCommand {
120 120
                         getInformation(manager.getBestSource(), args.
121 121
                                 getArgumentsAsString(0)));
122 122
             } else {
123
-                sendLine(origin, args.isSilent(), FORMAT_ERROR,
124
-                        "No running media sources available.");
123
+                showError(origin, args.isSilent(), "No running media sources available.");
125 124
             }
126 125
         }
127 126
     }
@@ -138,7 +137,7 @@ public class NowPlayingCommand extends Command implements IntelligentCommand {
138 137
         final List<MediaSource> sources = manager.getSources();
139 138
 
140 139
         if (sources.isEmpty()) {
141
-            sendLine(origin, isSilent, FORMAT_ERROR, "No media sources available.");
140
+            showError(origin, isSilent, "No media sources available.");
142 141
         } else {
143 142
             final String[] headers = {"Source", "Status", "Information"};
144 143
             final String[][] data = new String[sources.size()][3];
@@ -158,7 +157,7 @@ public class NowPlayingCommand extends Command implements IntelligentCommand {
158 157
                 i++;
159 158
             }
160 159
 
161
-            sendLine(origin, isSilent, FORMAT_OUTPUT, doTable(headers, data));
160
+            showOutput(origin, isSilent, doTable(headers, data));
162 161
         }
163 162
     }
164 163
 

+ 5
- 6
osd/src/com/dmdirc/addons/osd/OsdCommand.java View File

@@ -86,8 +86,8 @@ public class OsdCommand extends Command implements IntelligentCommand {
86 86
         } else if (args.getArguments().length > 0
87 87
                 && "--timeout".equalsIgnoreCase(args.getArguments()[0])) {
88 88
             if (args.getArguments().length < 2) {
89
-                sendLine(origin, args.isSilent(), FORMAT_ERROR, "You "
90
-                        + "must specify a valid number for the OSD timeout.");
89
+                showError(origin, args.isSilent(),
90
+                        "You must specify a valid number for the OSD timeout.");
91 91
                 return;
92 92
             }
93 93
 
@@ -95,8 +95,8 @@ public class OsdCommand extends Command implements IntelligentCommand {
95 95
                 showOSD(Integer.parseInt(args.getArguments()[1]), null,
96 96
                         args.getArgumentsAsString(2));
97 97
             } catch (NumberFormatException ex) {
98
-                sendLine(origin, args.isSilent(), FORMAT_ERROR, "You "
99
-                        + "must specify a valid number for the OSD timeout.");
98
+                showError(origin, args.isSilent(),
99
+                        "You must specify a valid number for the OSD timeout.");
100 100
             }
101 101
         } else {
102 102
             showOSD(-1, null, args.getArgumentsAsString());
@@ -111,8 +111,7 @@ public class OsdCommand extends Command implements IntelligentCommand {
111 111
         if (arg == 0) {
112 112
             res.add("--close");
113 113
             res.add("--timeout");
114
-        } else if (arg > 0 && context.getPreviousArgs().get(0)
115
-                .equals("--close")) {
114
+        } else if (arg > 0 && "--close".equals(context.getPreviousArgs().get(0))) {
116 115
             res.excludeAll();
117 116
         }
118 117
 

+ 3
- 3
parserdebug/src/com/dmdirc/addons/parserdebug/ParserDebugCommand.java View File

@@ -82,15 +82,15 @@ public final class ParserDebugCommand extends Command {
82 82
         final Optional<Parser> parser = connection.getParser();
83 83
 
84 84
         if (!parser.isPresent()) {
85
-            sendLine(origin, isSilent, FORMAT_ERROR, "Unable to get a parser for this window.");
85
+            showError(origin, isSilent, "Unable to get a parser for this window.");
86 86
             return;
87 87
         }
88 88
         if (parserDebugManager.containsParser(parser.get())) {
89 89
             parserDebugManager.removeParser(parser.get(), false);
90
-            sendLine(origin, isSilent, FORMAT_OUTPUT, "Removed callback");
90
+            showOutput(origin, isSilent, "Removed callback");
91 91
         } else {
92 92
             parserDebugManager.addParser(parser.get(), connection);
93
-            sendLine(origin, isSilent, FORMAT_OUTPUT, "Added callback");
93
+            showOutput(origin, isSilent, "Added callback");
94 94
         }
95 95
     }
96 96
 

+ 28
- 32
scriptplugin/src/com/dmdirc/addons/scriptplugin/ScriptCommand.java View File

@@ -99,29 +99,28 @@ public class ScriptCommand extends Command implements IntelligentCommand {
99 99
 
100 100
         if (sargs.length > 0 && ("rehash".equalsIgnoreCase(sargs[0]) ||
101 101
                 "reload".equalsIgnoreCase(sargs[0]))) {
102
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Reloading scripts");
102
+            showOutput(origin, args.isSilent(), "Reloading scripts");
103 103
             scriptManager.rehash();
104 104
         } else if (sargs.length > 0 && "load".equalsIgnoreCase(sargs[0])) {
105 105
             if (sargs.length > 1) {
106 106
                 final String filename = args.getArgumentsAsString(1);
107
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Loading: " + filename + " ["
107
+                showOutput(origin, args.isSilent(), "Loading: " + filename + " ["
108 108
                         + scriptManager.loadScript(scriptDirectory + filename) + ']');
109 109
             } else {
110
-                sendLine(origin, args.isSilent(), FORMAT_ERROR, "You must specify a script to load");
110
+                showError(origin, args.isSilent(), "You must specify a script to load");
111 111
             }
112 112
         } else if (sargs.length > 0 && "unload".equalsIgnoreCase(sargs[0])) {
113 113
             if (sargs.length > 1) {
114 114
                 final String filename = args.getArgumentsAsString(1);
115
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Unloading: " + filename + " ["
115
+                showOutput(origin, args.isSilent(), "Unloading: " + filename + " ["
116 116
                         + scriptManager.loadScript(scriptDirectory + filename) + ']');
117 117
             } else {
118
-                sendLine(origin, args.isSilent(), FORMAT_ERROR,
119
-                        "You must specify a script to unload");
118
+                showError(origin, args.isSilent(), "You must specify a script to unload");
120 119
             }
121 120
         } else if (sargs.length > 0 && "eval".equalsIgnoreCase(sargs[0])) {
122 121
             if (sargs.length > 1) {
123 122
                 final String script = args.getArgumentsAsString(1);
124
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Evaluating: " + script);
123
+                showOutput(origin, args.isSilent(), "Evaluating: " + script);
125 124
                 try {
126 125
                     final ScriptEngineWrapper wrapper;
127 126
                     if (globalConfig.hasOptionString(domain, "eval.baseFile")) {
@@ -138,30 +137,29 @@ public class ScriptCommand extends Command implements IntelligentCommand {
138 137
                     wrapper.getScriptEngine().put("cmd_origin", origin);
139 138
                     wrapper.getScriptEngine().put("cmd_isSilent", args.isSilent());
140 139
                     wrapper.getScriptEngine().put("cmd_args", sargs);
141
-                    sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Result: " + wrapper.
142
-                            getScriptEngine().eval(script));
140
+                    showOutput(origin, args.isSilent(), "Result: "
141
+                            + wrapper.getScriptEngine().eval(script));
143 142
                 } catch (ScriptException e) {
144
-                    sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Exception: " + e + " -> " + e.
145
-                            getMessage());
143
+                    showOutput(origin, args.isSilent(), "Exception: " + e + " -> "
144
+                            + e.getMessage());
146 145
 
147 146
                     if (globalConfig.getOptionBool(domain, "eval.showStackTrace")) {
148 147
                         final String[] stacktrace = getTrace(e);
149 148
                         for (String line : stacktrace) {
150
-                            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Stack trace: " + line);
149
+                            showOutput(origin, args.isSilent(), "Stack trace: " + line);
151 150
                         }
152 151
                     }
153 152
 
154 153
                 }
155 154
             } else {
156
-                sendLine(origin, args.isSilent(), FORMAT_ERROR,
157
-                        "You must specify some script to eval.");
155
+                showError(origin, args.isSilent(), "You must specify some script to eval.");
158 156
             }
159 157
         } else if (sargs.length > 0 && "savetobasefile".equalsIgnoreCase(sargs[0])) {
160 158
             if (sargs.length > 2) {
161 159
                 final String[] bits = sargs[1].split("/");
162 160
                 final String functionName = bits[0];
163 161
                 final String script = args.getArgumentsAsString(2);
164
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Saving as '" + functionName
162
+                showOutput(origin, args.isSilent(), "Saving as '" + functionName
165 163
                         + "': " + script);
166 164
                 if (globalConfig.hasOptionString(domain, "eval.baseFile")) {
167 165
                     try {
@@ -181,43 +179,41 @@ public class ScriptCommand extends Command implements IntelligentCommand {
181 179
                             writer.flush();
182 180
                         }
183 181
                     } catch (IOException ioe) {
184
-                        sendLine(origin, args.isSilent(), FORMAT_ERROR, "IOException: " + ioe.
185
-                                getMessage());
182
+                        showError(origin, args.isSilent(), "IOException: " + ioe.getMessage());
186 183
                     }
187 184
                 } else {
188
-                    sendLine(origin, args.isSilent(), FORMAT_ERROR,
185
+                    showError(origin, args.isSilent(),
189 186
                             "No baseFile specified, please /set " + domain
190 187
                             + " eval.baseFile filename (stored in scripts dir of profile)");
191 188
                 }
192 189
             } else if (sargs.length > 1) {
193
-                sendLine(origin, args.isSilent(), FORMAT_ERROR,
194
-                        "You must specify some script to save.");
190
+                showError(origin, args.isSilent(), "You must specify some script to save.");
195 191
             } else {
196
-                sendLine(origin, args.isSilent(), FORMAT_ERROR,
192
+                showError(origin, args.isSilent(),
197 193
                         "You must specify a function name and some script to save.");
198 194
             }
199 195
         } else if (sargs.length > 0 && "help".equalsIgnoreCase(sargs[0])) {
200
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
196
+            showOutput(origin, args.isSilent(),
201 197
                     "This command allows you to interact with the script plugin");
202
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "-------------------");
203
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
198
+            showOutput(origin, args.isSilent(), "-------------------");
199
+            showOutput(origin, args.isSilent(),
204 200
                     "reload/rehash                  - Reload all loaded scripts");
205
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
201
+            showOutput(origin, args.isSilent(),
206 202
                     "load <script>                  - load scripts/<script> (file name relative to scripts dir)");
207
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
203
+            showOutput(origin, args.isSilent(),
208 204
                     "unload <script>                - unload <script> (full file name)");
209
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
205
+            showOutput(origin, args.isSilent(),
210 206
                     "eval <script>                  - evaluate the code <script> and return the result");
211
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
207
+            showOutput(origin, args.isSilent(),
212 208
                     "savetobasefile <name> <script> - save the code <script> to the eval basefile ("
213 209
                     + domain + ".eval.basefile)");
214
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
210
+            showOutput(origin, args.isSilent(),
215 211
                     "                                 as the function <name> (name/foo/bar will save it as 'name' with foo and");
216
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
212
+            showOutput(origin, args.isSilent(),
217 213
                     "                                 bar as arguments.");
218
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "-------------------");
214
+            showOutput(origin, args.isSilent(), "-------------------");
219 215
         } else {
220
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, "Unknown subcommand.");
216
+            showError(origin, args.isSilent(), "Unknown subcommand.");
221 217
         }
222 218
     }
223 219
 

+ 1
- 2
ui_swing/src/com/dmdirc/addons/ui_swing/commands/PopInCommand.java View File

@@ -70,8 +70,7 @@ public class PopInCommand extends Command {
70 70
         UIUtilities.invokeLater(() -> {
71 71
             final TextFrame swingWindow = windowFactory.getSwingWindow(origin);
72 72
             if (swingWindow == null) {
73
-                sendLine(origin, args.isSilent(), FORMAT_ERROR, "There is"
74
-                        + " currently no window to pop in.");
73
+                showError(origin, args.isSilent(), "There is currently no window to pop in.");
75 74
             } else {
76 75
                 swingWindow.setPopout(false);
77 76
             }

+ 1
- 2
ui_swing/src/com/dmdirc/addons/ui_swing/commands/PopOutCommand.java View File

@@ -70,8 +70,7 @@ public class PopOutCommand extends Command {
70 70
         UIUtilities.invokeLater(() -> {
71 71
             final TextFrame swingWindow = windowFactory.getSwingWindow(origin);
72 72
             if (swingWindow == null) {
73
-                sendLine(origin, args.isSilent(), FORMAT_ERROR, "There is"
74
-                        + " currently no window to pop out.");
73
+                showError(origin, args.isSilent(), "There is currently no window to pop out.");
75 74
             } else {
76 75
                 swingWindow.setPopout(true);
77 76
             }

Loading…
Cancel
Save