From 8e33cadcaa863fee869966fc8280b790064e90ef Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Mon, 20 Jan 2025 19:28:19 +0100 Subject: [PATCH 01/10] add -y --- cfg/config.go | 2 ++ cmd/root.go | 2 ++ go.mod | 1 + go.sum | 2 ++ lib/helpers.go | 8 ++++++++ lib/printer.go | 27 +++++++++++++++++++++++++++ 6 files changed, 42 insertions(+) diff --git a/cfg/config.go b/cfg/config.go index 3d4840a..e2c34ec 100644 --- a/cfg/config.go +++ b/cfg/config.go @@ -59,6 +59,8 @@ type Config struct { NoHeaders bool Columns string UseColumns []int + YankColumns string + UseYankColumns []int Separator string OutputMode int InvertMatch bool diff --git a/cmd/root.go b/cmd/root.go index afbf0df..c4ff4fe 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -147,6 +147,8 @@ func Execute() { "Custom field separator") rootCmd.PersistentFlags().StringVarP(&conf.Columns, "columns", "c", "", "Only show the speficied columns (separated by ,)") + rootCmd.PersistentFlags().StringVarP(&conf.YankColumns, "yank-columns", "y", "", + "Yank the speficied columns (separated by ,) to the clipboard") rootCmd.PersistentFlags().StringVarP(&conf.TransposeColumns, "transpose-columns", "T", "", "Transpose the speficied columns (separated by ,)") diff --git a/go.mod b/go.mod index 7c203d7..7ae1eeb 100644 --- a/go.mod +++ b/go.mod @@ -18,6 +18,7 @@ require ( github.com/agext/levenshtein v1.2.3 // indirect github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect + github.com/atotto/clipboard v0.1.4 // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/mattn/go-runewidth v0.0.16 // indirect diff --git a/go.sum b/go.sum index 5491a3d..3a96455 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,8 @@ github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4= github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de h1:FxWPpzIjnTlhPwqqXc4/vE0f7GvRjuAsbW+HOIe8KnA= github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de/go.mod h1:DCaWoUhZrYW9p1lxo/cm8EmUOOzAPSEZNGF2DK1dJgw= +github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4= +github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= diff --git a/lib/helpers.go b/lib/helpers.go index 32b6705..28dc321 100644 --- a/lib/helpers.go +++ b/lib/helpers.go @@ -77,6 +77,14 @@ func PrepareColumns(conf *cfg.Config, data *Tabdata) error { conf.UseColumns = usecolumns + // -y columns + useyankcolumns, err := PrepareColumnVars(conf.YankColumns, data) + if err != nil { + return err + } + + conf.UseYankColumns = useyankcolumns + return nil } diff --git a/lib/printer.go b/lib/printer.go index 3189060..c863b7f 100644 --- a/lib/printer.go +++ b/lib/printer.go @@ -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) + } +} From 2d5799e2f2624e5deaf2e0a19d3b97d1f7a31e86 Mon Sep 17 00:00:00 2001 From: "T.v.Dein" Date: Mon, 20 Jan 2025 21:27:26 +0100 Subject: [PATCH 02/10] Use primary clipboard on unix --- lib/printer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/printer.go b/lib/printer.go index c863b7f..4d6a37f 100644 --- a/lib/printer.go +++ b/lib/printer.go @@ -285,7 +285,7 @@ func yankColumns(conf cfg.Config, data *Tabdata) { } if yank != "" { - // FIXME: does not use the primary clipboard, grnz... + clipboard.Primary = true // unix clipboard.WriteAll(yank) } } From 82f54c120da5e2598f9399ee1ff33320a4ee76e1 Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Tue, 21 Jan 2025 18:42:04 +0100 Subject: [PATCH 03/10] catch err --- lib/printer.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/printer.go b/lib/printer.go index 4d6a37f..cc95238 100644 --- a/lib/printer.go +++ b/lib/printer.go @@ -286,6 +286,8 @@ func yankColumns(conf cfg.Config, data *Tabdata) { if yank != "" { clipboard.Primary = true // unix - clipboard.WriteAll(yank) + if err := clipboard.WriteAll(yank); err != nil { + log.Fatalln("error writing string to clipboard:", err) + } } } From e8f4fef41c019714f88a81cae9cb674e94ba878a Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Wed, 22 Jan 2025 23:12:42 +0100 Subject: [PATCH 04/10] fix #37: make yank portable --- lib/printer.go | 2 +- lib/ya_darwin.go | 8 ++++++++ lib/ya_unix.go | 9 +++++++++ lib/ya_windows.go | 8 ++++++++ tablizer.1 | 4 ++-- 5 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 lib/ya_darwin.go create mode 100644 lib/ya_unix.go create mode 100644 lib/ya_windows.go diff --git a/lib/printer.go b/lib/printer.go index cc95238..43ee535 100644 --- a/lib/printer.go +++ b/lib/printer.go @@ -285,7 +285,7 @@ func yankColumns(conf cfg.Config, data *Tabdata) { } if yank != "" { - clipboard.Primary = true // unix + setprimary() if err := clipboard.WriteAll(yank); err != nil { log.Fatalln("error writing string to clipboard:", err) } diff --git a/lib/ya_darwin.go b/lib/ya_darwin.go new file mode 100644 index 0000000..2e7f149 --- /dev/null +++ b/lib/ya_darwin.go @@ -0,0 +1,8 @@ +// +build darwin + +package lib + +import "github.com/atotto/clipboard" + +func setprimary() { +} diff --git a/lib/ya_unix.go b/lib/ya_unix.go new file mode 100644 index 0000000..6f05680 --- /dev/null +++ b/lib/ya_unix.go @@ -0,0 +1,9 @@ +// +build freebsd linux netbsd openbsd solaris dragonfly + +package lib + +import "github.com/atotto/clipboard" + +func setprimary() { + clipboard.Primary = true +} diff --git a/lib/ya_windows.go b/lib/ya_windows.go new file mode 100644 index 0000000..4caae39 --- /dev/null +++ b/lib/ya_windows.go @@ -0,0 +1,8 @@ +// +build windows + +package lib + +import "github.com/atotto/clipboard" + +func setprimary() { +} diff --git a/tablizer.1 b/tablizer.1 index 73dd6b4..e3f1aad 100644 --- a/tablizer.1 +++ b/tablizer.1 @@ -1,4 +1,4 @@ -.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) +.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== @@ -133,7 +133,7 @@ .\" ======================================================================== .\" .IX Title "TABLIZER 1" -.TH TABLIZER 1 "2025-01-15" "1" "User Commands" +.TH TABLIZER 1 "2025-01-22" "1" "User Commands" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l From dc718392b602ac211656b725f50d0a63768d3ca5 Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Wed, 22 Jan 2025 23:15:12 +0100 Subject: [PATCH 05/10] fix-import --- lib/ya_darwin.go | 1 - lib/ya_windows.go | 1 - 2 files changed, 2 deletions(-) diff --git a/lib/ya_darwin.go b/lib/ya_darwin.go index 2e7f149..39e974e 100644 --- a/lib/ya_darwin.go +++ b/lib/ya_darwin.go @@ -2,7 +2,6 @@ package lib -import "github.com/atotto/clipboard" func setprimary() { } diff --git a/lib/ya_windows.go b/lib/ya_windows.go index 4caae39..75cecfe 100644 --- a/lib/ya_windows.go +++ b/lib/ya_windows.go @@ -2,7 +2,6 @@ package lib -import "github.com/atotto/clipboard" func setprimary() { } From 768a19b4d6e9a476d5b7c4da1d788baaf5780c1a Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Thu, 23 Jan 2025 13:59:02 +0100 Subject: [PATCH 06/10] fine tuning, added test, which hangs, but yanking works anyway --- Makefile | 2 +- README.md | 2 ++ cmd/tablizer.go | 16 +++++++++++ go.mod | 2 +- lib/printer.go | 28 +------------------ lib/yank.go | 51 +++++++++++++++++++++++++++++++++++ lib/yank_test.go | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ tablizer.1 | 20 ++++++++++++-- tablizer.pod | 15 +++++++++++ 9 files changed, 175 insertions(+), 31 deletions(-) create mode 100644 lib/yank.go create mode 100644 lib/yank_test.go diff --git a/Makefile b/Makefile index 2870e99..e4e5175 100644 --- a/Makefile +++ b/Makefile @@ -69,7 +69,7 @@ test: singletest: @echo "Call like this: 'make singletest TEST=TestPrepareColumns MOD=lib'" - go test -run $(TEST) github.com/tlinden/tablizer/$(MOD) + go test -run $(TEST) github.com/tlinden/tablizer/$(MOD) $(OPTS) cover-report: go test ./... -cover -coverprofile=coverage.out diff --git a/README.md b/README.md index a66a97d..054ba6d 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,8 @@ Output Flags (mutually exclusive): -C, --csv Enable CSV output -A, --ascii Default output mode, ascii tabular -L, --hightlight-lines Use alternating background colors for tables + -y, --yank-columns Yank specified columns (separated by ,) to clipboard, + space separated Sort Mode Flags (mutually exclusive): -a, --sort-age sort according to age (duration) string diff --git a/cmd/tablizer.go b/cmd/tablizer.go index 71f5b21..e6fb84f 100644 --- a/cmd/tablizer.go +++ b/cmd/tablizer.go @@ -30,6 +30,8 @@ SYNOPSIS -C, --csv Enable CSV output -A, --ascii Default output mode, ascii tabular -L, --hightlight-lines Use alternating background colors for tables + -y, --yank-columns Yank specified columns (separated by ,) to clipboard, + space separated Sort Mode Flags (mutually exclusive): -a, --sort-age sort according to age (duration) string @@ -267,6 +269,18 @@ DESCRIPTION markdown which prints a Markdown table, yaml, which prints yaml encoding and CSV mode, which prints a comma separated value file. + PUT FIELDS TO CLIPBOARD + You can let tablizer put fields to the clipboard using the option "-y". + This best fits the use-case when the result of your filtering yields + just one row. For example: + + cloudctl cluster ls | tablizer -yid matchbox + + If "matchbox" matches one cluster, you can immediately use the id of + that cluster somewhere else and paste it. Of course, if there are + multiple matches, then all id's will be put into the clipboard separated + by one space. + ENVIRONMENT VARIABLES tablizer supports certain environment variables which use can use to influence program behavior. Commandline flags have always precedence @@ -416,6 +430,8 @@ Output Flags (mutually exclusive): -C, --csv Enable CSV output -A, --ascii Default output mode, ascii tabular -L, --hightlight-lines Use alternating background colors for tables + -y, --yank-columns Yank specified columns (separated by ,) to clipboard, + space separated Sort Mode Flags (mutually exclusive): -a, --sort-age sort according to age (duration) string diff --git a/go.mod b/go.mod index 7ae1eeb..568616a 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.22 require ( github.com/alecthomas/repr v0.4.0 github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de + github.com/atotto/clipboard v0.1.4 github.com/gookit/color v1.5.4 github.com/hashicorp/hcl/v2 v2.23.0 github.com/lithammer/fuzzysearch v1.1.8 @@ -18,7 +19,6 @@ require ( github.com/agext/levenshtein v1.2.3 // indirect github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect - github.com/atotto/clipboard v0.1.4 // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/mattn/go-runewidth v0.0.16 // indirect diff --git a/lib/printer.go b/lib/printer.go index 43ee535..0041f85 100644 --- a/lib/printer.go +++ b/lib/printer.go @@ -1,5 +1,5 @@ /* -Copyright © 2022 Thomas von Dein +Copyright © 2022-2025 Thomas von Dein This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -26,7 +26,6 @@ import ( "strconv" "strings" - "github.com/atotto/clipboard" "github.com/gookit/color" "github.com/olekukonko/tablewriter" "github.com/tlinden/tablizer/cfg" @@ -266,28 +265,3 @@ 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 != "" { - setprimary() - if err := clipboard.WriteAll(yank); err != nil { - log.Fatalln("error writing string to clipboard:", err) - } - } -} diff --git a/lib/yank.go b/lib/yank.go new file mode 100644 index 0000000..7f4d755 --- /dev/null +++ b/lib/yank.go @@ -0,0 +1,51 @@ +/* +Copyright © 2022-2025 Thomas von Dein + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +package lib + +import ( + "log" + "strings" + + "github.com/atotto/clipboard" + "github.com/tlinden/tablizer/cfg" +) + +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 = append(yank, field) + } + } + } + } + + if len(yank) > 0 { + setprimary() + if err := clipboard.WriteAll(strings.Join(yank, " ")); err != nil { + log.Fatalln("error writing string to clipboard:", err) + } + } +} diff --git a/lib/yank_test.go b/lib/yank_test.go new file mode 100644 index 0000000..b1c057a --- /dev/null +++ b/lib/yank_test.go @@ -0,0 +1,70 @@ +/* +Copyright © 2025 Thomas von Dein + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +package lib + +import ( + "bytes" + "fmt" + "testing" + + "github.com/atotto/clipboard" + "github.com/tlinden/tablizer/cfg" +) + +var yanktests = []struct { + name string + yank []int // -y$colum,$column... after processing + filter string + expect string +}{ + { + name: "one", + yank: []int{1}, + filter: "beta", + }, +} + +func DISABLED_TestYankColumns(t *testing.T) { + for _, testdata := range yanktests { + testname := fmt.Sprintf("yank-%s-filter-%s", + testdata.name, testdata.filter) + t.Run(testname, func(t *testing.T) { + conf := cfg.Config{ + OutputMode: cfg.ASCII, + UseYankColumns: testdata.yank, + NoColor: true, + } + + conf.ApplyDefaults() + data := newData() // defined in printer_test.go, reused here + + var writer bytes.Buffer + printData(&writer, conf, &data) + + got, err := clipboard.ReadAll() // hangs indefinetly + if err != nil { + t.Errorf("failed to fetch yanked text from clipboard") + } + + if got != testdata.expect { + t.Errorf("not yanked correctly:\n+++ got:\n%s\n+++ want:\n%s", + got, testdata.expect) + } + }) + } +} diff --git a/tablizer.1 b/tablizer.1 index e3f1aad..01e55d1 100644 --- a/tablizer.1 +++ b/tablizer.1 @@ -1,4 +1,4 @@ -.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) +.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== @@ -133,7 +133,7 @@ .\" ======================================================================== .\" .IX Title "TABLIZER 1" -.TH TABLIZER 1 "2025-01-22" "1" "User Commands" +.TH TABLIZER 1 "2025-01-23" "1" "User Commands" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -168,6 +168,8 @@ tablizer \- Manipulate tabular output of other programs \& \-C, \-\-csv Enable CSV output \& \-A, \-\-ascii Default output mode, ascii tabular \& \-L, \-\-hightlight\-lines Use alternating background colors for tables +\& \-y, \-\-yank\-columns Yank specified columns (separated by ,) to clipboard, +\& space separated \& \& Sort Mode Flags (mutually exclusive): \& \-a, \-\-sort\-age sort according to age (duration) string @@ -442,6 +444,20 @@ more output modes available: \fBorgtbl\fR which prints an Emacs org-mode table and \fBmarkdown\fR which prints a Markdown table, \fByaml\fR, which prints yaml encoding and \s-1CSV\s0 mode, which prints a comma separated value file. +.SS "\s-1PUT FIELDS TO CLIPBOARD\s0" +.IX Subsection "PUT FIELDS TO CLIPBOARD" +You can let tablizer put fields to the clipboard using the option +\&\f(CW\*(C`\-y\*(C'\fR. This best fits the use-case when the result of your filtering +yields just one row. For example: +.PP +.Vb 1 +\& cloudctl cluster ls | tablizer \-yid matchbox +.Ve +.PP +If \*(L"matchbox\*(R" matches one cluster, you can immediately use the id of +that cluster somewhere else and paste it. Of course, if there are +multiple matches, then all id's will be put into the clipboard +separated by one space. .SS "\s-1ENVIRONMENT VARIABLES\s0" .IX Subsection "ENVIRONMENT VARIABLES" \&\fBtablizer\fR supports certain environment variables which use can use diff --git a/tablizer.pod b/tablizer.pod index 8f170ae..e05a288 100644 --- a/tablizer.pod +++ b/tablizer.pod @@ -29,6 +29,8 @@ tablizer - Manipulate tabular output of other programs -C, --csv Enable CSV output -A, --ascii Default output mode, ascii tabular -L, --hightlight-lines Use alternating background colors for tables + -y, --yank-columns Yank specified columns (separated by ,) to clipboard, + space separated Sort Mode Flags (mutually exclusive): -a, --sort-age sort according to age (duration) string @@ -290,6 +292,19 @@ table and B which prints a Markdown table, B, which prints yaml encoding and CSV mode, which prints a comma separated value file. +=head2 PUT FIELDS TO CLIPBOARD + +You can let tablizer put fields to the clipboard using the option +C<-y>. This best fits the use-case when the result of your filtering +yields just one row. For example: + + cloudctl cluster ls | tablizer -yid matchbox + +If "matchbox" matches one cluster, you can immediately use the id of +that cluster somewhere else and paste it. Of course, if there are +multiple matches, then all id's will be put into the clipboard +separated by one space. + =head2 ENVIRONMENT VARIABLES B supports certain environment variables which use can use From 200f1f32f837aaa353a872a27ae807aab50996a3 Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Tue, 28 Jan 2025 14:40:17 +0100 Subject: [PATCH 07/10] using patched tiagomeol/go-clipboard/clipboard, fixes #37 --- go.mod | 2 ++ go.sum | 6 ++++++ lib/ya_darwin.go | 7 ------- lib/ya_unix.go | 9 --------- lib/ya_windows.go | 7 ------- lib/yank.go | 6 +++--- lib/yank_test.go | 6 ++++-- 7 files changed, 15 insertions(+), 28 deletions(-) delete mode 100644 lib/ya_darwin.go delete mode 100644 lib/ya_unix.go delete mode 100644 lib/ya_windows.go diff --git a/go.mod b/go.mod index 568616a..5e7053f 100644 --- a/go.mod +++ b/go.mod @@ -23,8 +23,10 @@ require ( github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/mattn/go-runewidth v0.0.16 // indirect github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect + github.com/pkg/errors v0.9.1 // indirect github.com/rivo/uniseg v0.2.0 // indirect github.com/spf13/pflag v1.0.5 // indirect + github.com/tiagomelo/go-clipboard v0.1.2-0.20250126153310-fcc1f95408cf // indirect github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect github.com/zclconf/go-cty v1.13.3 // indirect golang.org/x/mod v0.18.0 // indirect diff --git a/go.sum b/go.sum index 3a96455..3eed471 100644 --- a/go.sum +++ b/go.sum @@ -34,6 +34,8 @@ github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzC github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= @@ -51,6 +53,10 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/tiagomelo/go-clipboard v0.1.1 h1:nddQ5DsEnKW0KdzTILhbLpSq3e9y2dkJXEOtsMs6H7A= +github.com/tiagomelo/go-clipboard v0.1.1/go.mod h1:kXtjJBIMimZaGbxmcKZ8+JqK+acSNf5tAJiChlZBOr8= +github.com/tiagomelo/go-clipboard v0.1.2-0.20250126153310-fcc1f95408cf h1:csb/+rmJBAtOP6OP+9soTnwJVuhlUpedjb5dPlNZasY= +github.com/tiagomelo/go-clipboard v0.1.2-0.20250126153310-fcc1f95408cf/go.mod h1:kXtjJBIMimZaGbxmcKZ8+JqK+acSNf5tAJiChlZBOr8= github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= diff --git a/lib/ya_darwin.go b/lib/ya_darwin.go deleted file mode 100644 index 39e974e..0000000 --- a/lib/ya_darwin.go +++ /dev/null @@ -1,7 +0,0 @@ -// +build darwin - -package lib - - -func setprimary() { -} diff --git a/lib/ya_unix.go b/lib/ya_unix.go deleted file mode 100644 index 6f05680..0000000 --- a/lib/ya_unix.go +++ /dev/null @@ -1,9 +0,0 @@ -// +build freebsd linux netbsd openbsd solaris dragonfly - -package lib - -import "github.com/atotto/clipboard" - -func setprimary() { - clipboard.Primary = true -} diff --git a/lib/ya_windows.go b/lib/ya_windows.go deleted file mode 100644 index 75cecfe..0000000 --- a/lib/ya_windows.go +++ /dev/null @@ -1,7 +0,0 @@ -// +build windows - -package lib - - -func setprimary() { -} diff --git a/lib/yank.go b/lib/yank.go index 7f4d755..39265d3 100644 --- a/lib/yank.go +++ b/lib/yank.go @@ -21,7 +21,7 @@ import ( "log" "strings" - "github.com/atotto/clipboard" + "github.com/tiagomelo/go-clipboard/clipboard" "github.com/tlinden/tablizer/cfg" ) @@ -43,8 +43,8 @@ func yankColumns(conf cfg.Config, data *Tabdata) { } if len(yank) > 0 { - setprimary() - if err := clipboard.WriteAll(strings.Join(yank, " ")); err != nil { + cb := clipboard.New(clipboard.ClipboardOptions{Primary: true}) + if err := cb.CopyText(strings.Join(yank, " ")); err != nil { log.Fatalln("error writing string to clipboard:", err) } } diff --git a/lib/yank_test.go b/lib/yank_test.go index b1c057a..748104b 100644 --- a/lib/yank_test.go +++ b/lib/yank_test.go @@ -22,7 +22,7 @@ import ( "fmt" "testing" - "github.com/atotto/clipboard" + "github.com/tiagomelo/go-clipboard/clipboard" "github.com/tlinden/tablizer/cfg" ) @@ -40,6 +40,8 @@ var yanktests = []struct { } func DISABLED_TestYankColumns(t *testing.T) { + cb := clipboard.New() + for _, testdata := range yanktests { testname := fmt.Sprintf("yank-%s-filter-%s", testdata.name, testdata.filter) @@ -56,7 +58,7 @@ func DISABLED_TestYankColumns(t *testing.T) { var writer bytes.Buffer printData(&writer, conf, &data) - got, err := clipboard.ReadAll() // hangs indefinetly + got, err := cb.PasteText() if err != nil { t.Errorf("failed to fetch yanked text from clipboard") } From 150fdddd2ab9a5bcee2b662920de0c1bc2140b93 Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Sun, 23 Feb 2025 18:00:29 +0100 Subject: [PATCH 08/10] use latest go-clipboard --- go.mod | 3 +-- go.sum | 4 ++-- tablizer.1 | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 5e7053f..3cf9830 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,6 @@ go 1.22 require ( github.com/alecthomas/repr v0.4.0 github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de - github.com/atotto/clipboard v0.1.4 github.com/gookit/color v1.5.4 github.com/hashicorp/hcl/v2 v2.23.0 github.com/lithammer/fuzzysearch v1.1.8 @@ -26,7 +25,7 @@ require ( github.com/pkg/errors v0.9.1 // indirect github.com/rivo/uniseg v0.2.0 // indirect github.com/spf13/pflag v1.0.5 // indirect - github.com/tiagomelo/go-clipboard v0.1.2-0.20250126153310-fcc1f95408cf // indirect + github.com/tiagomelo/go-clipboard v0.1.2 // indirect github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect github.com/zclconf/go-cty v1.13.3 // indirect golang.org/x/mod v0.18.0 // indirect diff --git a/go.sum b/go.sum index 3eed471..6736f35 100644 --- a/go.sum +++ b/go.sum @@ -8,8 +8,6 @@ github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4= github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de h1:FxWPpzIjnTlhPwqqXc4/vE0f7GvRjuAsbW+HOIe8KnA= github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de/go.mod h1:DCaWoUhZrYW9p1lxo/cm8EmUOOzAPSEZNGF2DK1dJgw= -github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4= -github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -57,6 +55,8 @@ github.com/tiagomelo/go-clipboard v0.1.1 h1:nddQ5DsEnKW0KdzTILhbLpSq3e9y2dkJXEOt github.com/tiagomelo/go-clipboard v0.1.1/go.mod h1:kXtjJBIMimZaGbxmcKZ8+JqK+acSNf5tAJiChlZBOr8= github.com/tiagomelo/go-clipboard v0.1.2-0.20250126153310-fcc1f95408cf h1:csb/+rmJBAtOP6OP+9soTnwJVuhlUpedjb5dPlNZasY= github.com/tiagomelo/go-clipboard v0.1.2-0.20250126153310-fcc1f95408cf/go.mod h1:kXtjJBIMimZaGbxmcKZ8+JqK+acSNf5tAJiChlZBOr8= +github.com/tiagomelo/go-clipboard v0.1.2 h1:Ph2icR0vZRIj3v5ExvsGweBwsbbDUTlS6HoF40MkQD8= +github.com/tiagomelo/go-clipboard v0.1.2/go.mod h1:kXtjJBIMimZaGbxmcKZ8+JqK+acSNf5tAJiChlZBOr8= github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= diff --git a/tablizer.1 b/tablizer.1 index 01e55d1..b2a650a 100644 --- a/tablizer.1 +++ b/tablizer.1 @@ -133,7 +133,7 @@ .\" ======================================================================== .\" .IX Title "TABLIZER 1" -.TH TABLIZER 1 "2025-01-23" "1" "User Commands" +.TH TABLIZER 1 "2025-02-23" "1" "User Commands" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l From c1cfc08c23bea4e7a17d94661d3f8f3dd43f12a8 Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Sun, 23 Feb 2025 18:02:52 +0100 Subject: [PATCH 09/10] fix windows test, add clean to test target --- .github/workflows/ci.yaml | 2 +- Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1624835..a58792a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -7,7 +7,7 @@ jobs: version: ['1.22'] # windows-latest removed, see: # https://github.com/rogpeppe/go-internal/issues/284 - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest, macos-latest, windows-latest] name: Build runs-on: ${{ matrix.os }} steps: diff --git a/Makefile b/Makefile index e4e5175..c2d28a5 100644 --- a/Makefile +++ b/Makefile @@ -64,7 +64,7 @@ install: buildlocal clean: rm -rf $(tool) releases coverage.out -test: +test: clean go test ./... $(OPTS) singletest: From fda365bd8b3379cc805f5e80c22bae4eec9a30fb Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Sun, 23 Feb 2025 18:06:42 +0100 Subject: [PATCH 10/10] bump version --- cfg/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cfg/config.go b/cfg/config.go index e2c34ec..3d25227 100644 --- a/cfg/config.go +++ b/cfg/config.go @@ -28,7 +28,7 @@ import ( ) const DefaultSeparator string = `(\s\s+|\t)` -const Version string = "v1.3.1" +const Version string = "v1.3.3" const MAXPARTS = 2 var DefaultConfigfile = os.Getenv("HOME") + "/.config/tablizer/config"