Merge pull request #126 from omar-polo/master

Complete the refactor
This commit is contained in:
Caleb Bassi 2019-03-11 22:49:37 -07:00
commit d38fd3a575
2 changed files with 10 additions and 28 deletions

View File

@ -143,17 +143,17 @@ func (c Canvas) Get(x, y int) bool {
return (char & dot_index) != 0
}
// Get character at the given screen coordinates
// GetScreenCharacter gets character at the given screen coordinates
func (c Canvas) GetScreenCharacter(x, y int) rune {
return rune(c.chars[y][x] + braille_char_offset)
}
// Get character for the given pixel
// GetCharacter gets character for the given pixel
func (c Canvas) GetCharacter(x, y int) rune {
return c.GetScreenCharacter(x/4, y/4)
}
// Retrieve the rows from a given view
// Rows retrieves the rows from a given view
func (c Canvas) Rows(minX, minY, maxX, maxY int) []string {
minrow, maxrow := minY/4, (maxY)/4
mincol, maxcol := minX/2, (maxX)/2
@ -170,7 +170,7 @@ func (c Canvas) Rows(minX, minY, maxX, maxY int) []string {
return ret
}
// Retrieve a string representation of the frame at the given parameters
// Frame retrieves a string representation of the frame at the given parameters
func (c Canvas) Frame(minX, minY, maxX, maxY int) string {
var ret string
for _, row := range c.Rows(minX, minY, maxX, maxY) {

View File

@ -17,25 +17,7 @@ const (
fifty = ten + ten + ten + ten + ten
)
func (self *ProcWidget) update() {
procs, err := GetProcs()
if err != nil {
log.Printf("failed to retrieve processes: %v", err)
return
}
// have to iterate like this in order to actually change the value
for i := range procs {
procs[i].CPU /= self.cpuCount
}
self.ungroupedProcs = procs
self.groupedProcs = GroupProcs(procs)
self.SortProcesses()
}
func GetProcs() ([]Process, error) {
func getProcs() ([]Proc, error) {
keywords := fmt.Sprintf("pid=%s,comm=%s,pcpu=%s,pmem=%s,args", ten, fifty, five, five)
output, err := exec.Command("ps", "-caxo", keywords).Output()
if err != nil {
@ -60,11 +42,11 @@ func GetProcs() ([]Process, error) {
log.Printf("failed to convert fourth field to float: %v. split: %v", err, line)
}
proc := Proc{
PID: pid,
Command: strings.TrimSpace(line[11:61]),
CPU: cpu,
Mem: mem,
Args: line[74:],
Pid: pid,
CommandName: strings.TrimSpace(line[11:61]),
Cpu: cpu,
Mem: mem,
FullCommand: line[74:],
}
procs = append(procs, proc)
}