From a6e115ba6d6323289b5774191efd1fcb0e7af5ef Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Tue, 16 Aug 2016 17:18:20 -0400 Subject: [PATCH 01/15] Updated readme --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index e867e199..05c26106 100644 --- a/readme.md +++ b/readme.md @@ -4,7 +4,7 @@ Auxiliary packages for Go. ### Platform support -Currently we support Linux and Mac OS X. Some packages have stubs for Windows (for autocomplete). +Currently we support Linux and Mac OS X. Some packages have stubs for Windows (_for autocomplete_). ### Installation @@ -57,7 +57,7 @@ go get -u pkg.re/essentialkaos/ek.v3 ### Projects with EK -* [ssllabs-client](https://github.com/essentialkaos/ssllabs_client) - Pretty awesome command-line client for public SSLLabs API +* [sslcli](https://github.com/essentialkaos/sslcli) - Pretty awesome command-line client for public SSLLabs API * [redis-cli-monitor](https://github.com/essentialkaos/redis-cli-monitor) - Tiny redis client for renamed MONITOR commands * [shdoc](https://github.com/essentialkaos/shdoc) - Tool for viewing and exporting docs for shell scripts * [rbinstall](https://github.com/essentialkaos/rbinstall) - Utility for installing prebuilt ruby to RBEnv From 5a939c2f64ac5c68b9eb318e2586589b989eb56c Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Tue, 16 Aug 2016 17:41:04 -0400 Subject: [PATCH 02/15] Added examples for tmp package --- tmp/examples_test.go | 75 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 tmp/examples_test.go diff --git a/tmp/examples_test.go b/tmp/examples_test.go new file mode 100644 index 00000000..eaa4b172 --- /dev/null +++ b/tmp/examples_test.go @@ -0,0 +1,75 @@ +package tmp + +// ////////////////////////////////////////////////////////////////////////////////// // +// // +// Copyright (c) 2009-2016 Essential Kaos // +// Essential Kaos Open Source License // +// // +// ////////////////////////////////////////////////////////////////////////////////// // + +import ( + "fmt" +) + +// ////////////////////////////////////////////////////////////////////////////////// // + +func ExampleNewTemp() { + tmp, err := tmp.NewTemp() + + if err != nil { + log.Fatalln(err.Error()) + } + + fmt.Println(tmp, err) + + // Output: &{/tmp []} +} + +func Example_mkDir() { + tmp, err := tmp.NewTemp() + + if err != nil { + log.Fatalln(err.Error()) + } + + fmt.Println(tmp.MkDir()) + fmt.Println(tmp.MkDir("test123")) + + tmp.Clean() + + // Output: + // /tmp/_tmp_4xrgpNxaH6Gl + // /tmp/_oDUNbUndLe2w_test123 +} + +func Example_mkFile() { + tmp, err := tmp.NewTemp() + + if err != nil { + log.Fatalln(err.Error()) + } + + fmt.Println(tmp.MkDir()) + fmt.Println(tmp.MkDir("test123")) + + tmp.Clean() + + // Output: + // &{0xc8200a0d40} /tmp/_tmp_pfR9Qf6I5TZk + // &{0xc8200a0e00} /tmp/_l9yKFblzvv4e_test123 +} + +func Example_mkName() { + tmp, err := tmp.NewTemp() + + if err != nil { + log.Fatalln(err.Error()) + } + + fmt.Println(tmp.MkDir()) + fmt.Println(tmp.MkDir("test123")) + + // Output: + // /tmp/_tmp_4xrgpNxaH6Gl + // /tmp/_oDUNbUndLe2w_test123 +} From 0a56ab6c65ef8bfbc41a0eba7386eb669ce4014c Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Tue, 16 Aug 2016 17:42:23 -0400 Subject: [PATCH 03/15] Fixed tmp examples --- tmp/examples_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tmp/examples_test.go b/tmp/examples_test.go index eaa4b172..61bb0b49 100644 --- a/tmp/examples_test.go +++ b/tmp/examples_test.go @@ -25,7 +25,7 @@ func ExampleNewTemp() { // Output: &{/tmp []} } -func Example_mkDir() { +func ExampleTemp_mkDir() { tmp, err := tmp.NewTemp() if err != nil { @@ -42,7 +42,7 @@ func Example_mkDir() { // /tmp/_oDUNbUndLe2w_test123 } -func Example_mkFile() { +func ExampleTemp_mkFile() { tmp, err := tmp.NewTemp() if err != nil { @@ -59,7 +59,7 @@ func Example_mkFile() { // &{0xc8200a0e00} /tmp/_l9yKFblzvv4e_test123 } -func Example_mkName() { +func ExampleTemp_mkName() { tmp, err := tmp.NewTemp() if err != nil { From d11e50dda7dc5ecfa9e7bfea4642d9c854dddaf6 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Tue, 16 Aug 2016 17:44:05 -0400 Subject: [PATCH 04/15] Fixed tmp examples --- tmp/examples_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tmp/examples_test.go b/tmp/examples_test.go index 61bb0b49..4144cb64 100644 --- a/tmp/examples_test.go +++ b/tmp/examples_test.go @@ -25,7 +25,7 @@ func ExampleNewTemp() { // Output: &{/tmp []} } -func ExampleTemp_mkDir() { +func ExampleTemp_MkDir() { tmp, err := tmp.NewTemp() if err != nil { @@ -42,7 +42,7 @@ func ExampleTemp_mkDir() { // /tmp/_oDUNbUndLe2w_test123 } -func ExampleTemp_mkFile() { +func ExampleTemp_MkFile() { tmp, err := tmp.NewTemp() if err != nil { @@ -59,7 +59,7 @@ func ExampleTemp_mkFile() { // &{0xc8200a0e00} /tmp/_l9yKFblzvv4e_test123 } -func ExampleTemp_mkName() { +func ExampleTemp_MkName() { tmp, err := tmp.NewTemp() if err != nil { From a7e69edfb2f9a815b82b5252e95bc249c4ec88c3 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Tue, 16 Aug 2016 17:44:51 -0400 Subject: [PATCH 05/15] Fixed tmp examples --- tmp/examples_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tmp/examples_test.go b/tmp/examples_test.go index 4144cb64..878e04f6 100644 --- a/tmp/examples_test.go +++ b/tmp/examples_test.go @@ -49,8 +49,8 @@ func ExampleTemp_MkFile() { log.Fatalln(err.Error()) } - fmt.Println(tmp.MkDir()) - fmt.Println(tmp.MkDir("test123")) + fmt.Println(tmp.MkFile()) + fmt.Println(tmp.MkFile("test123")) tmp.Clean() From cf3eb8afd246525e44c67e1373460cdab2183198 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Tue, 16 Aug 2016 17:46:47 -0400 Subject: [PATCH 06/15] Fixed tmp examples --- tmp/examples_test.go | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/tmp/examples_test.go b/tmp/examples_test.go index 878e04f6..201150a7 100644 --- a/tmp/examples_test.go +++ b/tmp/examples_test.go @@ -59,17 +59,32 @@ func ExampleTemp_MkFile() { // &{0xc8200a0e00} /tmp/_l9yKFblzvv4e_test123 } -func ExampleTemp_MkName() { +func ExampleTemp_MkFile() { tmp, err := tmp.NewTemp() if err != nil { log.Fatalln(err.Error()) } - fmt.Println(tmp.MkDir()) - fmt.Println(tmp.MkDir("test123")) + fmt.Println(tmp.MkFile()) + fmt.Println(tmp.MkFile("test123")) + + tmp.Clean() // Output: - // /tmp/_tmp_4xrgpNxaH6Gl - // /tmp/_oDUNbUndLe2w_test123 + // &{0xc8200a0d40} /tmp/_tmp_pfR9Qf6I5TZk + // &{0xc8200a0e00} /tmp/_l9yKFblzvv4e_test123 +} + +func ExampleTemp_Clean() { + tmp, err := tmp.NewTemp() + + if err != nil { + log.Fatalln(err.Error()) + } + + tmp.MkDir() + + // All temporary data will be removed + tmp.Clean() } From 948c4c56341d138b9ea17aaa63cf9c13d64817ce Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Tue, 16 Aug 2016 17:47:48 -0400 Subject: [PATCH 07/15] Fixed tmp examples --- tmp/examples_test.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tmp/examples_test.go b/tmp/examples_test.go index 201150a7..da08d59c 100644 --- a/tmp/examples_test.go +++ b/tmp/examples_test.go @@ -59,21 +59,19 @@ func ExampleTemp_MkFile() { // &{0xc8200a0e00} /tmp/_l9yKFblzvv4e_test123 } -func ExampleTemp_MkFile() { +func ExampleTemp_MkName() { tmp, err := tmp.NewTemp() if err != nil { log.Fatalln(err.Error()) } - fmt.Println(tmp.MkFile()) - fmt.Println(tmp.MkFile("test123")) - - tmp.Clean() + fmt.Println(tmp.MkDir()) + fmt.Println(tmp.MkDir("test123")) // Output: - // &{0xc8200a0d40} /tmp/_tmp_pfR9Qf6I5TZk - // &{0xc8200a0e00} /tmp/_l9yKFblzvv4e_test123 + // /tmp/_tmp_4xrgpNxaH6Gl + // /tmp/_oDUNbUndLe2w_test123 } func ExampleTemp_Clean() { From 7efc8e669a0851e235cbc4034b3ad0405698949e Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Tue, 16 Aug 2016 17:58:39 -0400 Subject: [PATCH 08/15] Added examples for color package --- color/examples_test.go | 60 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 color/examples_test.go diff --git a/color/examples_test.go b/color/examples_test.go new file mode 100644 index 00000000..e416d2c1 --- /dev/null +++ b/color/examples_test.go @@ -0,0 +1,60 @@ +package color + +// ////////////////////////////////////////////////////////////////////////////////// // +// // +// Copyright (c) 2009-2016 Essential Kaos // +// Essential Kaos Open Source License // +// // +// ////////////////////////////////////////////////////////////////////////////////// // + +import ( + "fmt" +) + +// ////////////////////////////////////////////////////////////////////////////////// // + +func ExampleRGB2Hex() { + fmt.Printf("%x\n", color.RGB2Hex(127, 25, 75)) + // Output: 7f194b +} + +func ExampleHex2RGB() { + r, g, b := color.Hex2RGB(0x7f194b) + + fmt.Printf("r:%d g:%d b:%d\n", r, g, b) + + // Output: r:127 g:25 b:75 +} + +func ExampleRGBA2Hex() { + r, g, b, a := color.Hex2RGBA(0x7f194bcc) + + fmt.Printf("r:%d g:%d b:%d a:%d\n", r, g, b, a) + + // Output: r:127 g:25 b:75 a:204 +} + +func ExampleRGB2HSB() { + h, s, v := color.RGB2HSB(127, 25, 75) + + fmt.Printf("h:%d s:%d v:%d\n", h, s, v) + + // Output: h:331 s:81 v:50 +} + +func ExampleHSB2RGB() { + r, g, b := color.HSB2RGB(331, 81, 50) + + fmt.Printf("r:%d g:%d b:%d\n", r, g, b) + + // Output: r:128 g:24 b:74 +} + +func ExampleIsRGBA() { + fmt.Println(color.IsRGBA(0xAABBCC)) + fmt.Println(color.IsRGBA(0xAABBCCDD)) + + // Output: + // false + // true +} From ce6fdc690a3c7abc7992626696bc01ef2aac9de3 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Tue, 16 Aug 2016 18:00:05 -0400 Subject: [PATCH 09/15] Fixed color examples --- color/examples_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/color/examples_test.go b/color/examples_test.go index e416d2c1..17afa257 100644 --- a/color/examples_test.go +++ b/color/examples_test.go @@ -26,7 +26,7 @@ func ExampleHex2RGB() { // Output: r:127 g:25 b:75 } -func ExampleRGBA2Hex() { +func ExampleHex2RGBA() { r, g, b, a := color.Hex2RGBA(0x7f194bcc) fmt.Printf("r:%d g:%d b:%d a:%d\n", r, g, b, a) From dd5c34179b507c6d790c1be83c1781824ed7c33a Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Wed, 17 Aug 2016 19:31:01 -0400 Subject: [PATCH 10/15] Added package system/process for getting information about active processes --- changelog.md | 4 + readme.md | 1 + system/process/processes_linux.go | 262 ++++++++++++++++++++++++++++ system/process/processes_windows.go | 32 ++++ 4 files changed, 299 insertions(+) create mode 100644 system/process/processes_linux.go create mode 100644 system/process/processes_windows.go diff --git a/changelog.md b/changelog.md index 9bc3a62a..7c8a93d0 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ ## Changelog +#### v3.3.0 + +* `[system/process]` Added new package for working with getting information about active processes + #### v3.2.3 * `[terminal]` Fixed bug with title formating in `ReadUI` function diff --git a/readme.md b/readme.md index 05c26106..381ae358 100644 --- a/readme.md +++ b/readme.md @@ -49,6 +49,7 @@ go get -u pkg.re/essentialkaos/ek.v3 * [`spellcheck`](https://godoc.org/pkg.re/essentialkaos/ek.v3/spellcheck) - Package provides spellcheck based on Damerau–Levenshtein distance algorithm * [`strutil`](https://godoc.org/pkg.re/essentialkaos/ek.v3/strutil) - Package provides utils for working with strings * [`system`](https://godoc.org/pkg.re/essentialkaos/ek.v3/system) - Package provides methods for working with system data (metrics/users) +* [`system/process`](https://godoc.org/pkg.re/essentialkaos/ek.v3/system/process) - Package provides methods for getting information about active processes * [`terminal`](https://godoc.org/pkg.re/essentialkaos/ek.v3/terminal) - Package provides methods for working with user input * [`timeutil`](https://godoc.org/pkg.re/essentialkaos/ek.v3/timeutil) - Package with time utils * [`tmp`](https://godoc.org/pkg.re/essentialkaos/ek.v3/tmp) - Package provides methods for working with temporary data diff --git a/system/process/processes_linux.go b/system/process/processes_linux.go new file mode 100644 index 00000000..b7b633ee --- /dev/null +++ b/system/process/processes_linux.go @@ -0,0 +1,262 @@ +// +build linux + +// Package process provides methods for getting information about active processes +package process + +// ////////////////////////////////////////////////////////////////////////////////// // +// // +// Copyright (c) 2009-2016 Essential Kaos // +// Essential Kaos Open Source License // +// // +// ////////////////////////////////////////////////////////////////////////////////// // + +import ( + "errors" + "io/ioutil" + "strconv" + "strings" + + "pkg.re/essentialkaos/ek.v3/fsutil" + "pkg.re/essentialkaos/ek.v3/system" +) + +// ////////////////////////////////////////////////////////////////////////////////// // + +// ProcessInfo contains basic info about process +type ProcessInfo struct { + Command string // Full command + User string // Username + PID int // PID + IsThread bool // True if process is thread + Parent int // Parent process PID + Childs []*ProcessInfo // Slice with child processes +} + +// ////////////////////////////////////////////////////////////////////////////////// // + +// GetTree return root process with all subprocesses on system +func GetTree() (*ProcessInfo, error) { + list, err := findInfo("/proc", make(map[int]string)) + + if err != nil { + return nil, err + } + + if len(list) == 0 { + return nil, errors.New("Can't find any processes") + } + + processMap := processListToMap(list) + + for _, process := range processMap { + if process.Parent < 0 { + continue + } + + parentProcess := processMap[process.Parent] + + if parentProcess == nil { + continue + } + + parentProcess.Childs = append(parentProcess.Childs, process) + } + + return processMap[1], nil +} + +// GetList return slice with all active processes on system +func GetList() ([]*ProcessInfo, error) { + return findInfo("/proc", make(map[int]string)) +} + +// ////////////////////////////////////////////////////////////////////////////////// // + +func findInfo(dir string, userMap map[int]string) ([]*ProcessInfo, error) { + var result []*ProcessInfo + + dirs := fsutil.List(dir, true, &fsutil.ListingFilter{Perms: "DRX"}) + + for _, pidDir := range dirs { + if !isPID(pidDir) { + continue + } + + taskDir := dir + "/" + pidDir + "/task" + + if fsutil.IsExist(taskDir) { + threads, err := findInfo(taskDir, userMap) + + if err != nil { + return nil, err + } + + if len(threads) == 0 { + continue + } + + processThreads(threads) + + result = append(result, threads...) + + continue + } + + info, err := readProcessInfo(dir+"/"+pidDir, pidDir, userMap) + + if err != nil { + return nil, err + } + + if info == nil { + continue + } + + result = append(result, info) + } + + return result, nil +} + +func readProcessInfo(dir, pid string, userMap map[int]string) (*ProcessInfo, error) { + cmd, err := ioutil.ReadFile(dir + "/cmdline") + + if len(cmd) == 0 { + return nil, nil + } + + if err != nil { + return nil, err + } + + uid, _, err := fsutil.GetOwner(dir) + + if err != nil { + return nil, err + } + + username, err := getProcessUser(uid, userMap) + + if err != nil { + return nil, err + } + + pidInt, err := strconv.Atoi(pid) + + if err != nil { + return nil, err + } + + return &ProcessInfo{ + Command: formatCommand(string(cmd)), + User: username, + PID: pidInt, + Parent: getProcessParent(dir, pidInt), + }, nil +} + +func getProcessUser(uid int, userMap map[int]string) (string, error) { + if uid == 0 { + return "root", nil + } + + if userMap[uid] != "" { + return userMap[uid], nil + } + + user, err := system.LookupUser(strconv.Itoa(uid)) + + if err != nil { + return "", err + } + + userMap[uid] = user.Name + + return user.Name, nil +} + +func processThreads(threads []*ProcessInfo) { + for _, info := range threads { + info.IsThread = true + } +} + +func getProcessParent(pidDir string, pid int) int { + tgid, ppid := getParentPIDs(pidDir) + + if tgid != pid { + return tgid + } + + return ppid +} + +func getParentPIDs(pidDir string) (int, int) { + data, err := ioutil.ReadFile(pidDir + "/status") + + if err != nil { + return -1, -1 + } + + var ( + ppid string + tgid string + ) + + for _, line := range strings.Split(string(data), "\n") { + if strings.HasPrefix(line, "Tgid:") { + tgid = strings.TrimSpace(line[5:]) + } + + if strings.HasPrefix(line, "PPid:") { + ppid = strings.TrimSpace(line[5:]) + } + + if ppid != "" && tgid != "" { + break + } + } + + if tgid == "" || ppid == "" { + return -1, -1 + } + + tgidInt, _ := strconv.Atoi(tgid) + ppidInt, _ := strconv.Atoi(ppid) + + return tgidInt, ppidInt +} + +func formatCommand(cmd string) string { + // Normalize delemiters + command := strings.Replace(cmd, "\000", " ", -1) + + // Remove space on the end of command + command = strings.TrimSpace(command) + + return command +} + +func processListToMap(processes []*ProcessInfo) map[int]*ProcessInfo { + var result = make(map[int]*ProcessInfo) + + for _, info := range processes { + result[info.PID] = info + } + + return result +} + +func isPID(pid string) bool { + if pid == "" { + return false + } + + // Pid must start from number + switch pid[0] { + case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': + return true + } + + return false +} diff --git a/system/process/processes_windows.go b/system/process/processes_windows.go new file mode 100644 index 00000000..5729049f --- /dev/null +++ b/system/process/processes_windows.go @@ -0,0 +1,32 @@ +// +build windows + +package process + +// ////////////////////////////////////////////////////////////////////////////////// // +// // +// Copyright (c) 2009-2016 Essential Kaos // +// Essential Kaos Open Source License // +// // +// ////////////////////////////////////////////////////////////////////////////////// // + +// ProcessInfo contains basic info about process +type ProcessInfo struct { + Command string // Full command + User string // Username + PID int // PID + IsThread bool // True if process is thread + Parent int // Parent process PID + Childs []*ProcessInfo // Slice with child processes +} + +// ////////////////////////////////////////////////////////////////////////////////// // + +// GetTree return root process with all subprocesses on system +func GetTree() (*ProcessInfo, error) { + return nil, nil +} + +// GetList return slice with all active processes on system +func GetList() ([]*ProcessInfo, error) { + return nil, nil +} From 5364bf3c0b444aa83fdc590267eab75a82b033ab Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Wed, 17 Aug 2016 19:36:34 -0400 Subject: [PATCH 11/15] Fixed tmp package examples --- tmp/examples_test.go | 46 +++++++------------------------------------- 1 file changed, 7 insertions(+), 39 deletions(-) diff --git a/tmp/examples_test.go b/tmp/examples_test.go index da08d59c..6603829d 100644 --- a/tmp/examples_test.go +++ b/tmp/examples_test.go @@ -14,72 +14,40 @@ import ( // ////////////////////////////////////////////////////////////////////////////////// // func ExampleNewTemp() { - tmp, err := tmp.NewTemp() + tmp, _ := NewTemp() - if err != nil { - log.Fatalln(err.Error()) - } + fmt.Println(tmp) - fmt.Println(tmp, err) - - // Output: &{/tmp []} + // Output: &{/tmp []} } func ExampleTemp_MkDir() { - tmp, err := tmp.NewTemp() - - if err != nil { - log.Fatalln(err.Error()) - } + tmp, _ := NewTemp() fmt.Println(tmp.MkDir()) fmt.Println(tmp.MkDir("test123")) tmp.Clean() - - // Output: - // /tmp/_tmp_4xrgpNxaH6Gl - // /tmp/_oDUNbUndLe2w_test123 } func ExampleTemp_MkFile() { - tmp, err := tmp.NewTemp() - - if err != nil { - log.Fatalln(err.Error()) - } + tmp, _ := NewTemp() fmt.Println(tmp.MkFile()) fmt.Println(tmp.MkFile("test123")) tmp.Clean() - - // Output: - // &{0xc8200a0d40} /tmp/_tmp_pfR9Qf6I5TZk - // &{0xc8200a0e00} /tmp/_l9yKFblzvv4e_test123 } func ExampleTemp_MkName() { - tmp, err := tmp.NewTemp() - - if err != nil { - log.Fatalln(err.Error()) - } + tmp, _ := NewTemp() fmt.Println(tmp.MkDir()) fmt.Println(tmp.MkDir("test123")) - - // Output: - // /tmp/_tmp_4xrgpNxaH6Gl - // /tmp/_oDUNbUndLe2w_test123 } func ExampleTemp_Clean() { - tmp, err := tmp.NewTemp() - - if err != nil { - log.Fatalln(err.Error()) - } + tmp, _ := NewTemp() tmp.MkDir() From 8b89600afd89d4cb06981bf24ba9864337b8be0d Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Wed, 17 Aug 2016 19:37:12 -0400 Subject: [PATCH 12/15] Fixed color package examples --- color/examples_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/color/examples_test.go b/color/examples_test.go index 17afa257..90e650d6 100644 --- a/color/examples_test.go +++ b/color/examples_test.go @@ -14,12 +14,12 @@ import ( // ////////////////////////////////////////////////////////////////////////////////// // func ExampleRGB2Hex() { - fmt.Printf("%x\n", color.RGB2Hex(127, 25, 75)) + fmt.Printf("%x\n", RGB2Hex(127, 25, 75)) // Output: 7f194b } func ExampleHex2RGB() { - r, g, b := color.Hex2RGB(0x7f194b) + r, g, b := Hex2RGB(0x7f194b) fmt.Printf("r:%d g:%d b:%d\n", r, g, b) @@ -27,7 +27,7 @@ func ExampleHex2RGB() { } func ExampleHex2RGBA() { - r, g, b, a := color.Hex2RGBA(0x7f194bcc) + r, g, b, a := Hex2RGBA(0x7f194bcc) fmt.Printf("r:%d g:%d b:%d a:%d\n", r, g, b, a) @@ -35,7 +35,7 @@ func ExampleHex2RGBA() { } func ExampleRGB2HSB() { - h, s, v := color.RGB2HSB(127, 25, 75) + h, s, v := RGB2HSB(127, 25, 75) fmt.Printf("h:%d s:%d v:%d\n", h, s, v) @@ -43,7 +43,7 @@ func ExampleRGB2HSB() { } func ExampleHSB2RGB() { - r, g, b := color.HSB2RGB(331, 81, 50) + r, g, b := HSB2RGB(331, 81, 50) fmt.Printf("r:%d g:%d b:%d\n", r, g, b) @@ -51,8 +51,8 @@ func ExampleHSB2RGB() { } func ExampleIsRGBA() { - fmt.Println(color.IsRGBA(0xAABBCC)) - fmt.Println(color.IsRGBA(0xAABBCCDD)) + fmt.Println(IsRGBA(0xAABBCC)) + fmt.Println(IsRGBA(0xAABBCCDD)) // Output: // false From ec5af3d045090e94670b48fe28a74e1a1f62ef06 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Thu, 18 Aug 2016 05:49:23 -0400 Subject: [PATCH 13/15] Updated cheangelog --- changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 7c8a93d0..9e68f33a 100644 --- a/changelog.md +++ b/changelog.md @@ -2,7 +2,7 @@ #### v3.3.0 -* `[system/process]` Added new package for working with getting information about active processes +* `[system/process]` Added new package for getting information about active system processes #### v3.2.3 From abd11b0bebc8273291110b5093e505ebf245e7a5 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Fri, 19 Aug 2016 08:38:07 -0400 Subject: [PATCH 14/15] Fixed bug with title formating in terminal.ReadAnswer --- changelog.md | 1 + terminal/terminal.go | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index 9e68f33a..7f61e36a 100644 --- a/changelog.md +++ b/changelog.md @@ -3,6 +3,7 @@ #### v3.3.0 * `[system/process]` Added new package for getting information about active system processes +* `[terminal]` Fixed bug with title formating in `ReadAnswer` function #### v3.2.3 diff --git a/terminal/terminal.go b/terminal/terminal.go index ce9ece3a..732a3147 100644 --- a/terminal/terminal.go +++ b/terminal/terminal.go @@ -131,11 +131,11 @@ func getAnswerTitle(title, defaultAnswer string) string { switch strings.ToUpper(defaultAnswer) { case "Y": - return fmt.Sprintf("{c}%s (Y/n){!}", title) + return fmt.Sprintf("%s (Y/n)", title) case "N": - return fmt.Sprintf("{c}%s (y/N){!}", title) + return fmt.Sprintf("%s (y/N)", title) default: - return fmt.Sprintf("{c}%s (y/n){!}", title) + return fmt.Sprintf("%s (y/n)", title) } } From 0a1b854bfc40fbc0e00e5ae1f0d9ffff910509cd Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Fri, 19 Aug 2016 08:45:50 -0400 Subject: [PATCH 15/15] Added examples for system/process package --- system/process/examples_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 system/process/examples_test.go diff --git a/system/process/examples_test.go b/system/process/examples_test.go new file mode 100644 index 00000000..d5232656 --- /dev/null +++ b/system/process/examples_test.go @@ -0,0 +1,28 @@ +package process + +// ////////////////////////////////////////////////////////////////////////////////// // +// // +// Copyright (c) 2009-2016 Essential Kaos // +// Essential Kaos Open Source License // +// // +// ////////////////////////////////////////////////////////////////////////////////// // + +func Example_getTree() { + process, err := GetTree() + + if err != nil { + return + } + + // process is top process in tree +} + +func Example_getList() { + processes, err := GetList() + + if err != nil { + return + } + + // processes is slice with info about all active processes +}