mirror of
https://codeberg.org/scip/tablizer.git
synced 2025-12-17 12:31:06 +01:00
add -y
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user