-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathresult.go
More file actions
50 lines (42 loc) · 1.04 KB
/
result.go
File metadata and controls
50 lines (42 loc) · 1.04 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
package libghostty
/*
#include <ghostty/vt.h>
*/
import "C"
import "fmt"
// Result represents a Ghostty result code.
//
// C: GhosttyResult
type Result int
const (
ResultSuccess Result = C.GHOSTTY_SUCCESS
ResultOutOfMemory Result = C.GHOSTTY_OUT_OF_MEMORY
ResultInvalidValue Result = C.GHOSTTY_INVALID_VALUE
ResultOutOfSpace Result = C.GHOSTTY_OUT_OF_SPACE
ResultNoValue Result = C.GHOSTTY_NO_VALUE
)
// Error holds a non-success Ghostty result.
type Error struct {
Result Result
}
func (e *Error) Error() string {
switch e.Result {
case ResultOutOfMemory:
return "ghostty: out of memory"
case ResultInvalidValue:
return "ghostty: invalid value"
case ResultOutOfSpace:
return "ghostty: out of space"
case ResultNoValue:
return "ghostty: no value"
default:
return fmt.Sprintf("ghostty: result=%d", int(e.Result))
}
}
// Convert a result code to an error, returning nil on success.
func resultError(result C.GhosttyResult) error {
if result == C.GHOSTTY_SUCCESS {
return nil
}
return &Error{Result: Result(result)}
}