Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a converter specified shortcut #625

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -358,8 +370,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(&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]")
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
Expand Down