CommandLineToolkit
111 строк · 2.3 Кб
1import Foundation
2import Signals
3
4// swiftlint:disable sync
5public enum Signal: Hashable, CustomStringConvertible, RawRepresentable {
6case hup
7case int
8case quit
9case abrt
10case kill
11case alrm
12case term
13case pipe
14case user(Int32)
15
16public init(rawValue: Int32) {
17self = switch rawValue {
18case SIGHUP:
19.hup
20case SIGINT:
21.int
22case SIGQUIT:
23.quit
24case SIGABRT:
25.abrt
26case SIGKILL:
27.kill
28case SIGALRM:
29.alrm
30case SIGTERM:
31.term
32case SIGPIPE:
33.pipe
34default:
35.user(rawValue)
36}
37}
38
39public var description: String {
40switch self {
41case .hup:
42return "SIGHUP"
43case .int:
44return "SIGINT"
45case .quit:
46return "SIGQUIT"
47case .abrt:
48return "SIGABRT"
49case .kill:
50return "SIGKILL"
51case .alrm:
52return "SIGALRM"
53case .term:
54return "SIGTERM"
55case .pipe:
56return "SIGPIPE"
57case .user(let value):
58return "SIGUSR(\(value))"
59}
60}
61
62public var intValue: Int32 {
63switch self {
64case .hup:
65return SIGHUP
66case .int:
67return SIGINT
68case .quit:
69return SIGQUIT
70case .abrt:
71return SIGABRT
72case .kill:
73return SIGKILL
74case .alrm:
75return SIGALRM
76case .term:
77return SIGTERM
78case .pipe:
79return SIGPIPE
80case .user(let value):
81return Int32(value)
82}
83}
84
85public var rawValue: Int32 {
86intValue
87}
88
89var blueSignal: Signals.Signal {
90switch self {
91case .hup:
92return .hup
93case .int:
94return .int
95case .quit:
96return .quit
97case .abrt:
98return .abrt
99case .kill:
100return .kill
101case .alrm:
102return .alrm
103case .term:
104return .term
105case .pipe:
106return .pipe
107case .user(let value):
108return .user(Int(value))
109}
110}
111}
112