If the argument isn't an ID, use fzf to find an ID
Signed-off-by: Oliver Davies <oliver@oliverdavies.uk>
This commit is contained in:
parent
329d6d34e0
commit
3c7a1dc3c1
5 changed files with 118 additions and 20 deletions
|
@ -3,13 +3,10 @@ package lib
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var ansiRegex = regexp.MustCompile(`\x1b\[[0-9;]*m`)
|
||||
|
||||
type Item struct {
|
||||
ID int `json:"id"`
|
||||
Title string `json:"title"`
|
||||
|
@ -19,7 +16,7 @@ func AsJSON(zets []string) (string, error) {
|
|||
var items []Item
|
||||
|
||||
for _, entry := range zets {
|
||||
cleanEntry := stripANSI(entry)
|
||||
cleanEntry := StripANSI(entry)
|
||||
parts := strings.SplitN(cleanEntry, " ", 2)
|
||||
|
||||
id, _ := strconv.Atoi(parts[0])
|
||||
|
@ -42,7 +39,3 @@ func AsJSON(zets []string) (string, error) {
|
|||
|
||||
return string(jsonData), nil
|
||||
}
|
||||
|
||||
func stripANSI(s string) string {
|
||||
return ansiRegex.ReplaceAllString(s, "")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue