Skip to content

Commit 5596dd3

Browse files
committed
[feat] ui process list
1 parent bf48d92 commit 5596dd3

File tree

15 files changed

+484
-217
lines changed

15 files changed

+484
-217
lines changed

.vscode/launch.json

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Attach to Process",
9+
"type": "go",
10+
"request": "attach",
11+
"mode": "local",
12+
"processId": 266935
13+
},
14+
{
15+
"name": "Launch Package",
16+
"type": "go",
17+
"request": "launch",
18+
"mode": "debug",
19+
"program": "${workspaceFolder}"
20+
},
21+
{
22+
"name": "Launch",
23+
"type": "go",
24+
"request": "launch",
25+
"mode": "auto",
26+
"program": "${fileDirname}",
27+
"env": {},
28+
"args": []
29+
}
30+
]
31+
}

at.log

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2020/07/04 20:13:17 Start
2+
2020/07/04 20:13:17 Config setup 10
3+
2020/07/04 20:13:17 Config length 10
4+
2020/07/04 20:13:17 Setup Main GUI
5+
2020/07/04 20:13:17 Config setup 10
6+
2020/07/04 20:13:17 Config length 10
7+
2020/07/04 20:13:22 Config setup 10
8+
2020/07/04 20:13:22 Config length 10
9+
2020/07/04 20:13:23 Config setup 10
10+
2020/07/04 20:13:23 Config length 10
11+
2020/07/04 20:13:25 Config setup 10
12+
2020/07/04 20:13:25 Config length 10
13+
2020/07/04 20:13:25 Config setup 10
14+
2020/07/04 20:13:25 Config length 10
15+
2020/07/04 20:13:27 Config setup 10
16+
2020/07/04 20:13:27 Config length 10

go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ go 1.14
55
require (
66
github.com/jroimartin/gocui v0.4.0
77
github.com/mattn/go-runewidth v0.0.9 // indirect
8+
github.com/mitchellh/go-ps v1.0.0
89
github.com/nsf/termbox-go v0.0.0-20200418040025-38ba6e5628f1 // indirect
10+
github.com/thoas/go-funk v0.7.0
911
)

go.sum

+10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
12
github.com/jroimartin/gocui v0.3.0 h1:l7wH8MKR2p+ozuZdtdhQiX7szILbv50vkMk1tg2+xow=
23
github.com/jroimartin/gocui v0.3.0/go.mod h1:2RtZznzYKt8RLRwvFiSkXjU0Ei8WwHdubgnlaYH47dw=
34
github.com/jroimartin/gocui v0.4.0 h1:52jnalstgmc25FmtGcWqa0tcbMEWS6RpFLsOIO+I+E8=
45
github.com/jroimartin/gocui v0.4.0/go.mod h1:7i7bbj99OgFHzo7kB2zPb8pXLqMBSQegY7azfqXMkyY=
56
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
67
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
8+
github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc=
9+
github.com/mitchellh/go-ps v1.0.0/go.mod h1:J4lOc8z8yJs6vUwklHw2XEIiT4z4C40KtWVN3nvg8Pg=
710
github.com/nsf/termbox-go v0.0.0-20200418040025-38ba6e5628f1 h1:lh3PyZvY+B9nFliSGTn5uFuqQQJGuNrD0MLCokv09ag=
811
github.com/nsf/termbox-go v0.0.0-20200418040025-38ba6e5628f1/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ=
12+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
13+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
14+
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
15+
github.com/thoas/go-funk v0.7.0 h1:GmirKrs6j6zJbhJIficOsz2aAI7700KsU/5YrdHRM1Y=
16+
github.com/thoas/go-funk v0.7.0/go.mod h1:+IWnUfUmFO1+WVYQWQtIJHeRRdaIyyYglZN7xzUPe4Q=
17+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
18+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

main.go

+43-119
Original file line numberDiff line numberDiff line change
@@ -1,146 +1,70 @@
1-
21
package main
32

43
import (
54
"fmt"
6-
"io"
7-
"io/ioutil"
5+
// "io/ioutil"
86
"log"
9-
"strings"
10-
// "github.com/nsf/termbox-go"
7+
"os"
8+
9+
// "github.com/nsf/termbox-go"
1110
"github.com/jroimartin/gocui"
12-
"github.com/windwp/go-at/pkg/app"
11+
"github.com/windwp/go-at/pkg/app"
12+
"github.com/windwp/go-at/pkg/gui"
13+
"github.com/windwp/go-at/pkg/model"
1314
)
1415

1516
var (
16-
config app.AppConfig
17+
config *model.AppConfig
1718
)
1819

1920

20-
func getLine(g *gocui.Gui, v *gocui.View) error {
21-
var l string
22-
var err error
23-
24-
_, cy := v.Cursor()
25-
if l, err = v.Line(cy); err != nil {
26-
l = ""
27-
}
28-
29-
maxX, maxY := g.Size()
30-
if v, err := g.SetView("msg", maxX/2-30, maxY/2-10, maxX/2+30, maxY/2+30); err != nil {
31-
if err != gocui.ErrUnknownView {
32-
return err
33-
}
34-
fmt.Fprintln(v, l+"lxla")
35-
if _, err := g.SetCurrentView("msg"); err != nil {
36-
return err
37-
}
38-
}
39-
return nil
40-
}
41-
42-
43-
44-
45-
46-
func saveMain(g *gocui.Gui, v *gocui.View) error {
47-
f, err := ioutil.TempFile("", "gocui_demo_")
48-
if err != nil {
49-
return err
50-
}
51-
defer f.Close()
21+
func layout(g *gocui.Gui) error {
22+
// maxX, maxY := g.Size()
23+
gui.SetUpSideGui(g, config)
24+
gui.SetUpMainGui(g,config)
25+
// if v, err := g.SetView("main", 30, -1, maxX, maxY); err != nil {
26+
// if err != gocui.ErrUnknownView {
27+
// return err
28+
// }
29+
30+
// b, err := ioutil.ReadFile("main.go")
31+
// if err != nil {
32+
// panic(err)
33+
// }
34+
35+
// fmt.Fprintf(v, "%s", b)
36+
// v.Editable = true
37+
// v.Wrap = true
38+
// if _, err := g.SetCurrentView("side"); err != nil {
39+
// return err
40+
// }
41+
// }
5242

53-
p := make([]byte, 5)
54-
v.Rewind()
55-
for {
56-
n, err := v.Read(p)
57-
if n > 0 {
58-
if _, err := f.Write(p[:n]); err != nil {
59-
return err
60-
}
61-
}
62-
if err == io.EOF {
63-
break
64-
}
65-
if err != nil {
66-
return err
67-
}
68-
}
6943
return nil
7044
}
7145

72-
func saveVisualMain(g *gocui.Gui, v *gocui.View) error {
73-
f, err := ioutil.TempFile("", "gocui_demo_")
46+
func main() {
47+
os.Remove("./at.log")
48+
f, err := os.OpenFile("./at.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
7449
if err != nil {
75-
return err
50+
fmt.Println("file log not exist")
7651
}
7752
defer f.Close()
78-
79-
vb := v.ViewBuffer()
80-
if _, err := io.Copy(f, strings.NewReader(vb)); err != nil {
81-
return err
82-
}
83-
return nil
84-
}
85-
86-
func updateView(g *gocui.Gui, v *gocui.View) error {
87-
v, err := g.View("side")
88-
if err != nil {
89-
return err
90-
}
91-
v.Clear()
92-
fmt.Fprintln(v, "lala")
93-
return nil
94-
}
95-
96-
func layout(g *gocui.Gui) error {
97-
maxX, maxY := g.Size()
98-
if v, err := g.SetView("side", -1, -1, 30, maxY); err != nil {
99-
if err != gocui.ErrUnknownView {
100-
return err
101-
}
102-
v.Highlight = true
103-
v.SelBgColor = gocui.ColorGreen
104-
v.SelFgColor = gocui.ColorBlack
105-
for _,c := range config.ListProcess {
106-
fmt.Fprintln(v,c.Name)
107-
}
108-
fmt.Fprint(v, "\rWill be")
109-
fmt.Fprint(v, "deleted\rItem 4\nItem 5")
110-
111-
}
112-
113-
114-
if v, err := g.SetView("main", 30, -1, maxX, maxY); err != nil {
115-
if err != gocui.ErrUnknownView {
116-
return err
117-
}
118-
119-
b, err := ioutil.ReadFile("main.go")
120-
if err != nil {
121-
panic(err)
122-
}
123-
124-
fmt.Fprintf(v, "%s", b)
125-
v.Editable = true
126-
v.Wrap = true
127-
if _, err := g.SetCurrentView("side"); err != nil {
128-
return err
129-
}
130-
}
131-
return nil
132-
}
133-
134-
func main() {
53+
log.SetOutput(f)
54+
log.Println("Start")
13555

13656
g, err := gocui.NewGui(gocui.OutputNormal)
137-
config=app.Setup()
57+
config = app.Setup()
58+
59+
g.Highlight = true
60+
g.SelFgColor = gocui.ColorRed
61+
g.BgColor = gocui.ColorBlack
62+
g.FgColor = gocui.ColorWhite
13863

13964
if err != nil {
140-
g.Close()
141-
log.Println("error my haha hihi")
65+
g.Close()
14266
log.Panicln(err)
143-
return
67+
return
14468
}
14569
defer g.Close()
14670
g.Cursor = true

pkg/app/app.go

+10-22
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,26 @@ package app
22

33
import(
44
"fmt"
5+
"github.com/windwp/go-at/pkg/model"
56
)
67
// Package main provides ...
7-
type Point struct {
8-
x, y int
9-
}
10-
type ProcessConfig struct {
11-
Pid int
12-
Name string
13-
Time int
14-
Text string
15-
Points []Point
16-
}
17-
18-
type AppConfig struct{
19-
ListProcess []ProcessConfig
20-
}
21-
22-
var config AppConfig
23-
func Setup() AppConfig {
8+
var config *model.AppConfig
9+
func Setup() *model.AppConfig {
2410
pNum:=10
25-
config=AppConfig{
26-
ListProcess : make([]ProcessConfig, 0, pNum),
11+
config=&model.AppConfig{
12+
ListProcess : make([]model.ProcessConfig, 0, pNum),
2713
}
14+
2815
for i := 0; i < pNum; i++ {
29-
iP:=ProcessConfig{
30-
Pid :0,
16+
iP:=model.ProcessConfig{
17+
Pid :i,
3118
Name:fmt.Sprintf("process %d",i),
3219
Time: 10,
3320
Text: "test",
34-
Points: make([]Point, 0),
21+
Points: make([]model.Point, 0),
3522
}
3623
config.ListProcess=append(config.ListProcess, iP)
3724
}
25+
config.SelectedProcess=&config.ListProcess[0]
3826
return config
3927
}

0 commit comments

Comments
 (0)