This commit is contained in:
2025-01-20 19:28:19 +01:00
parent 03f3225f24
commit 8e33cadcaa
6 changed files with 42 additions and 0 deletions

View File

@@ -26,6 +26,7 @@ import (
"strconv"
"strings"
"github.com/atotto/clipboard"
"github.com/gookit/color"
"github.com/olekukonko/tablewriter"
"github.com/tlinden/tablizer/cfg"
@@ -38,6 +39,9 @@ func printData(writer io.Writer, conf cfg.Config, data *Tabdata) {
// by, independently if it's being used for display or not.
sortTable(conf, data)
// put one or more columns into clipboard
yankColumns(conf, data)
// add numbers to headers and remove those we're not interested in
numberizeAndReduceHeaders(conf, data)
@@ -262,3 +266,26 @@ func printCSVData(writer io.Writer, data *Tabdata) {
log.Fatal(err)
}
}
func yankColumns(conf cfg.Config, data *Tabdata) {
var yank string
if len(data.entries) == 0 || len(conf.UseYankColumns) == 0 {
return
}
for _, row := range data.entries {
for i, field := range row {
for _, idx := range conf.UseYankColumns {
if i == idx-1 {
yank += field + " "
}
}
}
}
if yank != "" {
// FIXME: does not use the primary clipboard, grnz...
clipboard.WriteAll(yank)
}
}