@@ -10,7 +10,7 @@ import (
10
10
11
11
const Version = "v0.1.3"
12
12
13
- func Watch (pid int ) {
13
+ func Watch (pid int , seconds ... int ) {
14
14
lines := make ([]io.Writer , 0 )
15
15
l0 := uilive .New ()
16
16
l0 .RefreshInterval = time .Hour * 24 * 30
@@ -25,23 +25,35 @@ func Watch(pid int) {
25
25
pad := 26
26
26
s := NewSpinnerAnim ()
27
27
28
+ timer := time .NewTimer (time .Hour * 24 )
29
+ if len (seconds ) > 0 && seconds [0 ] >= 1 {
30
+ timer = time .NewTimer (time .Second * time .Duration (seconds [0 ]))
31
+ }
32
+
28
33
if PidgrepActive (pid ) {
34
+ Watch:
29
35
for {
30
- fmt .Fprint (lines [0 ], Logo ()+ "\n " )
31
- fmt .Fprintf (lines [0 ], "%s watching pid: %v %s \n " , s .Next (), pid , Pidgrepstatus (pid ))
32
- fmt .Fprintf (lines [0 ], "┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n " )
33
- fmt .Fprintf (lines [0 ], "┃ TCP conns ┃ %s ┃\n " , Red (LPad (pad , FGroup (Conngrep (pid )))))
34
- fmt .Fprintf (lines [0 ], "┣━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n " )
35
- fmt .Fprintf (lines [0 ], "┃ Open files ┃ %s ┃\n " , Yellow (LPad (pad , FGroup (Filegrep (pid )))))
36
- fmt .Fprintf (lines [0 ], "┣━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n " )
37
- fmt .Fprintf (lines [0 ], "┃ Threads ┃ %s ┃\n " , Blue (LPad (pad , FGroup (Threadgrep (pid )))))
38
- fmt .Fprintf (lines [0 ], "┣━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n " )
39
- fmt .Fprintf (lines [0 ], "┃ RSS bytes ┃ %s ┃\n " , Gray (8 , LPad (pad , FGroup (Memgrep (pid )))))
40
- fmt .Fprintf (lines [0 ], "┣━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n " )
41
- fmt .Fprintf (lines [0 ], "┃ CPU percent ┃ %s ┃\n " , Magenta (LPad (pad , Cpugrep (pid ))))
42
- fmt .Fprintf (lines [0 ], "┗━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n " )
43
- l0 .Flush ()
44
- time .Sleep (time .Millisecond * 500 )
36
+ select {
37
+ case <- timer .C :
38
+ break Watch
39
+ default :
40
+
41
+ fmt .Fprint (lines [0 ], Logo ()+ "\n " )
42
+ fmt .Fprintf (lines [0 ], "%s watching pid: %v %s \n " , s .Next (), pid , Pidgrepstatus (pid ))
43
+ fmt .Fprintf (lines [0 ], "┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n " )
44
+ fmt .Fprintf (lines [0 ], "┃ TCP conns ┃ %s ┃\n " , Red (LPad (pad , FGroup (Conngrep (pid )))))
45
+ fmt .Fprintf (lines [0 ], "┣━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n " )
46
+ fmt .Fprintf (lines [0 ], "┃ Open files ┃ %s ┃\n " , Yellow (LPad (pad , FGroup (Filegrep (pid )))))
47
+ fmt .Fprintf (lines [0 ], "┣━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n " )
48
+ fmt .Fprintf (lines [0 ], "┃ Threads ┃ %s ┃\n " , Blue (LPad (pad , FGroup (Threadgrep (pid )))))
49
+ fmt .Fprintf (lines [0 ], "┣━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n " )
50
+ fmt .Fprintf (lines [0 ], "┃ RSS bytes ┃ %s ┃\n " , Gray (8 , LPad (pad , FGroup (Memgrep (pid )))))
51
+ fmt .Fprintf (lines [0 ], "┣━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n " )
52
+ fmt .Fprintf (lines [0 ], "┃ CPU percent ┃ %s ┃\n " , Magenta (LPad (pad , Cpugrep (pid ))))
53
+ fmt .Fprintf (lines [0 ], "┗━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n " )
54
+ l0 .Flush ()
55
+ time .Sleep (time .Millisecond * 500 )
56
+ }
45
57
}
46
58
} else {
47
59
fmt .Printf (Logo ())
0 commit comments