/
global.go
85 lines (72 loc) · 2.11 KB
/
global.go
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
package app
import (
"github.com/arrow2nd/nekomata/api/sharedapi"
"github.com/arrow2nd/nekomata/app/exit"
"github.com/arrow2nd/nekomata/config"
"github.com/rivo/tview"
)
// Global : 全体共有
type Global struct {
app *tview.Application
name string
version string
currentUsername string
client sharedapi.Client
conf *config.Config
isCLI bool
enableAppKeybind bool
chStatus chan string
chIndicator chan string
chPopupModal chan *ModalOpts
chExecCommand chan string
chInputCommand chan string
chFocusView chan bool
}
var global = Global{
name: "nekomata",
version: "develop",
conf: nil,
isCLI: false,
enableAppKeybind: true,
chStatus: make(chan string, 1),
chIndicator: make(chan string, 1),
chPopupModal: make(chan *ModalOpts, 1),
chExecCommand: make(chan string, 1),
chInputCommand: make(chan string, 1),
chFocusView: make(chan bool, 1),
}
// SetStatus : ステータスメッセージを設定
func (g *Global) SetStatus(label, status string) {
message := createStatusMessage(label, status)
if g.isCLI {
exit.OK(message)
}
g.chStatus <- message
}
// SetErrorStatus : エラーメッセージを設定
func (g *Global) SetErrorStatus(label, errStatus string) {
if g.isCLI {
exit.Error(createStatusMessage(label, errStatus), exit.CodeErr)
}
g.SetStatus("ERR: "+label, errStatus)
}
// SetIndicator : インジケータを設定
func (g *Global) SetIndicator(indicator string) {
g.chIndicator <- indicator
}
// ReqestPopupModal : モーダルの表示をリクエスト
func (g *Global) ReqestPopupModal(o *ModalOpts) {
g.chPopupModal <- o
}
// RequestExecCommand : コマンドの実行をリクエスト
func (g *Global) RequestExecCommand(c string) {
g.chExecCommand <- c
}
// RequestInputCommand : コマンドの入力をリクエスト
func (g *Global) RequestInputCommand(c string) {
g.chInputCommand <- c
}
// RequestFocusView : ビューへのフォーカスを要求
func (g *Global) RequestFocusView() {
g.chFocusView <- true
}