From 95f5dd855d0cbd22af8e29ac12209a5f00d5513d Mon Sep 17 00:00:00 2001 From: Noboru Saito Date: Thu, 12 Sep 2024 14:29:34 +0900 Subject: [PATCH 1/2] Add a concverter specified shortcut Add a shortcut specified by RAW and Align Concverter. --- main.go | 5 ++++- oviewer/oviewer.go | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 0a6500c..fe8a9c5 100644 --- a/main.go +++ b/main.go @@ -358,8 +358,11 @@ func init() { rootCmd.PersistentFlags().StringVarP(&nonMatchFilter, "non-match-filter", "", "", "filter non match search pattern") rootCmd.PersistentFlags().BoolVarP(&oviewer.SkipExtract, "skip-extract", "", false, "skip extracting compressed files") + rootCmd.PersistentFlags().BoolVarP(&oviewer.AlignF, "align", "", false, "align column") + rootCmd.PersistentFlags().BoolVarP(&oviewer.RawF, "raw", "", false, "raw output of escape sequences") + // Config.General - rootCmd.PersistentFlags().StringP("converter", "", "es", "converter [es|raw]") + rootCmd.PersistentFlags().StringP("converter", "", "es", "converter [es|raw|align]") _ = viper.BindPFlag("general.Converter", rootCmd.PersistentFlags().Lookup("converter")) _ = rootCmd.RegisterFlagCompletionFunc("converter", func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) { return []string{"es\tEscape Sequence", "raw\tRaw output of escape sequences", "align\tAlign Column Widths"}, cobra.ShellCompDirectiveNoFileComp diff --git a/oviewer/oviewer.go b/oviewer/oviewer.go index f6f8a8e..25658ba 100644 --- a/oviewer/oviewer.go +++ b/oviewer/oviewer.go @@ -373,6 +373,12 @@ const ( var Shrink rune = '…' +// RawF is specifies converter shortcut for raw. +var RawF bool + +// AlignF is specifies converter shortcut for align. +var AlignF bool + var ( // ErrOutOfRange indicates that value is out of range. ErrOutOfRange = errors.New("out of range") @@ -700,6 +706,13 @@ func (root *Root) prepareRun(ctx context.Context) error { root.Screen.EnableMouse(MouseFlags) } + if RawF { + root.General.Converter = convRaw + } + if AlignF { + root.General.Converter = convAlign + } + if root.Config.ShrinkChar != "" { Shrink = []rune(root.Config.ShrinkChar)[0] } From 9d98adf6cc01b55061b9942de2a2c655905a2e20 Mon Sep 17 00:00:00 2001 From: Noboru Saito Date: Sat, 14 Sep 2024 12:55:01 +0900 Subject: [PATCH 2/2] Move shortcut options from oviewer to main Transferred shortcut handling for align and raw from oviewer/oviewer.go to main.go. --- main.go | 16 ++++++++++++++-- oviewer/oviewer.go | 13 ------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/main.go b/main.go index fe8a9c5..26961f5 100644 --- a/main.go +++ b/main.go @@ -45,6 +45,11 @@ var ( completion string // execCommand targets the output of executing the command. execCommand bool + + // alignF is align column. + alignF bool + // rawF is raw output of escape sequences. + rawF bool ) var ( @@ -99,6 +104,13 @@ It supports various compressed files(gzip, bzip2, zstd, lz4, and xz). config.General.SectionHeader = true } + // Set a converter by specifying flag. + if alignF { + config.General.Converter = "align" + } else if rawF { + config.General.Converter = "raw" + } + // Set a global variable to convert to a style before opening the file. oviewer.OverStrikeStyle = oviewer.ToTcellStyle(config.StyleOverStrike) oviewer.OverLineStyle = oviewer.ToTcellStyle(config.StyleOverLine) @@ -358,8 +370,8 @@ func init() { rootCmd.PersistentFlags().StringVarP(&nonMatchFilter, "non-match-filter", "", "", "filter non match search pattern") rootCmd.PersistentFlags().BoolVarP(&oviewer.SkipExtract, "skip-extract", "", false, "skip extracting compressed files") - rootCmd.PersistentFlags().BoolVarP(&oviewer.AlignF, "align", "", false, "align column") - rootCmd.PersistentFlags().BoolVarP(&oviewer.RawF, "raw", "", false, "raw output of escape sequences") + rootCmd.PersistentFlags().BoolVarP(&alignF, "align", "l", false, "align column") + rootCmd.PersistentFlags().BoolVarP(&rawF, "raw", "r", false, "raw output of escape sequences") // Config.General rootCmd.PersistentFlags().StringP("converter", "", "es", "converter [es|raw|align]") diff --git a/oviewer/oviewer.go b/oviewer/oviewer.go index 25658ba..f6f8a8e 100644 --- a/oviewer/oviewer.go +++ b/oviewer/oviewer.go @@ -373,12 +373,6 @@ const ( var Shrink rune = '…' -// RawF is specifies converter shortcut for raw. -var RawF bool - -// AlignF is specifies converter shortcut for align. -var AlignF bool - var ( // ErrOutOfRange indicates that value is out of range. ErrOutOfRange = errors.New("out of range") @@ -706,13 +700,6 @@ func (root *Root) prepareRun(ctx context.Context) error { root.Screen.EnableMouse(MouseFlags) } - if RawF { - root.General.Converter = convRaw - } - if AlignF { - root.General.Converter = convAlign - } - if root.Config.ShrinkChar != "" { Shrink = []rune(root.Config.ShrinkChar)[0] }