Skip to content

Commit

Permalink
Added support for giving search term as argument
Browse files Browse the repository at this point in the history
  • Loading branch information
heppu committed Apr 4, 2017
1 parent 30c907e commit 46a3be0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
11 changes: 8 additions & 3 deletions killer/killer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Killer struct {
err error
}

func NewKiller() (*Killer, error) {
func NewKiller(filter string) (*Killer, error) {
processes, err := ps.Processes()
if err != nil {
return nil, err
Expand All @@ -46,6 +46,7 @@ func NewKiller() (*Killer, error) {
processes: processes,
filtered: processes,
cursor: len(processes) / 2,
filter: filter,
}

color.Output = ansi.NewAnsiStdout()
Expand All @@ -60,6 +61,7 @@ func NewKiller() (*Killer, error) {
UniqueEditLine: true,
Stdout: color.Output,
})
rt.Operation.SetBuf(filter)
k.rt = rt
return k, nil
}
Expand Down Expand Up @@ -114,9 +116,12 @@ func (k *Killer) killProcess(sig syscall.Signal) {
k.err = p.Signal(sig)
}

func (k *Killer) OnChange(line []rune, pos int, key rune) (newLine []rune, newPos int, ok bool) {
func (k *Killer) OnChange(line []rune, pos int, _ rune) (newLine []rune, newPos int, ok bool) {
if !k.done {
k.filter = string(line)
// When we call Readlien() OnChenge is triggered with nil line
if line != nil {
k.filter = string(line)
}
k.filterProcesses()
}

Expand Down
9 changes: 8 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@ package main

import (
"fmt"
"os"
"strings"

"github.com/heppu/gkill/killer"
)

func main() {
k, err := killer.NewKiller()
var filter string
if len(os.Args) > 1 {
filter = strings.Join(os.Args[1:], " ")
}

k, err := killer.NewKiller(filter)
if err != nil {
fmt.Print(err)
}
Expand Down

0 comments on commit 46a3be0

Please sign in to comment.