File tree Expand file tree Collapse file tree 3 files changed +42
-1
lines changed Expand file tree Collapse file tree 3 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -34,12 +34,14 @@ func quitAndSave() {
34
34
case <- quitChannel :
35
35
// press "*" and "enter"
36
36
save ()
37
+ writeSetting ()
37
38
quit ()
38
39
case <- controlC :
39
40
// press "control-c"
40
41
if strings .Compare (runtime .GOOS , "windows" ) != 0 {
41
42
fmt .Printf ("\n \n " )
42
43
save ()
44
+ writeSetting ()
43
45
}
44
46
quit ()
45
47
}
@@ -51,12 +53,14 @@ func quitAndSave() {
51
53
case <- quitChannel :
52
54
// press "*" and "enter"
53
55
save ()
56
+ writeSetting ()
54
57
quit ()
55
58
case <- controlC :
56
59
// press "control-c"
57
60
if strings .Compare (runtime .GOOS , "windows" ) != 0 {
58
61
fmt .Printf ("\n \n " )
59
62
save ()
63
+ writeSetting ()
60
64
}
61
65
quit ()
62
66
}
@@ -70,6 +74,18 @@ func save() {
70
74
fmt .Printf (information )
71
75
}
72
76
77
+ func writeSetting () {
78
+ var err error
79
+ err = mydictionary .Setting .Write ()
80
+ if err != nil {
81
+ fmt .Printf (err .Error () + "\n \n " )
82
+ }
83
+ err = setting .Write ()
84
+ if err != nil {
85
+ fmt .Printf (err .Error () + "\n \n " )
86
+ }
87
+ }
88
+
73
89
func quit () {
74
90
var tm time.Time
75
91
tm = time .Now ()
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import (
10
10
"github.com/zzc-tongji/vocabulary4mydictionary"
11
11
)
12
12
13
- const version = "v2.0 .0"
13
+ const version = "v2.1 .0"
14
14
15
15
var (
16
16
setting settingStruct
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package main
3
3
import (
4
4
"encoding/json"
5
5
"io/ioutil"
6
+ "os"
6
7
7
8
"github.com/zzc-tongji/rtoa"
8
9
)
@@ -45,3 +46,27 @@ func (setting *settingStruct) read() (content string, err error) {
45
46
content = string (buf )
46
47
return
47
48
}
49
+
50
+ // Write : write setting
51
+ func (setting * settingStruct ) Write () (err error ) {
52
+ var (
53
+ buf []byte
54
+ path string
55
+ )
56
+ // convert path
57
+ path , err = rtoa .Convert ("mydictionary-local-cli.setting.json" , "" )
58
+ if err != nil {
59
+ return
60
+ }
61
+ // write
62
+ buf , err = json .MarshalIndent (setting , "" , "\t " )
63
+ if err != nil {
64
+ return
65
+ }
66
+ err = os .Remove (path )
67
+ if err != nil {
68
+ return
69
+ }
70
+ err = ioutil .WriteFile (path , buf , 0644 )
71
+ return
72
+ }
You can’t perform that action at this time.
0 commit comments