forked from newspeaklanguage/newspeak
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewShell.ns
More file actions
90 lines (87 loc) · 2.21 KB
/
NewShell.ns
File metadata and controls
90 lines (87 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
Newspeak3
'ExternalProcess'
class NewShell usingPlatform: platform <Platform> = (
(*
Copyright 2008 Cadence Design Systems, Inc.
Licensed under the Apache License, Version 2.0 (the ''License''); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*)
|
private ExternalLauncher = platform squeak ExternalLauncher.
private Map = platform collections Map.
private MessageBox = platform brazil tools MessageBox.
protected launchers = Map new.
|) (
class CommandError forLauncher: l with: args = Error (|
launcher = l.
arguments = args.
stdoutContents
|) (
abort = (
super defaultAction
)
public defaultAction = (
| response |
response:: MessageBox new
message: self messageText;
buttonLabels: {'Retry'. 'Abort'. 'Debug'} selections: {[retryCommand]. [abort]. nil};
open.
response ifNotNil: [:it | self resume: it value].
super defaultAction
)
public isResumable = (
^true
)
public retryCommand = (
^launcher runWith: arguments
ifSuccess:
[:stdout <ReadStream> :stderr <ReadStream> |
stdout contents asString]
ifFailure:
[:stdout <ReadStream> :stderr <ReadStream> |
stdoutContents:: stdout contents asString.
self signal: stderr contents asString]
)
) : (
)
class CommandSession for: l <ExternalLauncher> = (|
launcher = l.
|) (
public - arg <String> = (
^self value: '-', arg
)
public value = (
^with: {}
)
public value: arg1 = (
^with: {arg1}
)
public value: arg1 value: arg2 = (
^with: {arg1. arg2}
)
public value: arg1 value: arg2 value: arg3 = (
^with: {arg1. arg2. arg3}
)
public value: arg1 value: arg2 value: arg3 value: arg4 = (
^with: {arg1. arg2. arg3. arg4}
)
public value: arg1 value: arg2 value: arg3 value: arg4 value: arg5 = (
^with: {arg1. arg2. arg3. arg4. arg5}
)
public value: arg1 value: arg2 value: arg3 value: arg4 value: arg5 value: arg6 = (
^with: {arg1. arg2. arg3. arg4. arg5. arg6}
)
public with: arguments = (
^(CommandError forLauncher: launcher with: arguments)
retryCommand
)
) : (
)
doesNotUnderstand: message <Message> = (
^CommandSession for:
(launchers
at: message selector
ifPresent: [:e | e]
ifAbsentPut: [ExternalLauncher for: message selector])
)
) : (
)