Skip to content

Commit

Permalink
Merge pull request #609 from noborus/converter
Browse files Browse the repository at this point in the history
Allowing converters other than escape sequences
  • Loading branch information
noborus authored Aug 19, 2024
2 parents 956f44f + fb6ceca commit c1f7690
Show file tree
Hide file tree
Showing 22 changed files with 663 additions and 502 deletions.
8 changes: 7 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func RunOviewer(args []string) error {
if ov.QuitSmall && (filter != "" || nonMatchFilter != "") {
ov.QuitSmallFilter = true
}

// Run oviewer.
if err := ov.Run(); err != nil {
return err
}
Expand Down Expand Up @@ -359,6 +359,12 @@ func init() {
rootCmd.PersistentFlags().BoolVarP(&oviewer.SkipExtract, "skip-extract", "", false, "skip extracting compressed files")

// Config.General
rootCmd.PersistentFlags().StringP("converter", "", "es", "converter [es|raw]")
_ = 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"}, cobra.ShellCompDirectiveNoFileComp
})

rootCmd.PersistentFlags().IntP("tab-width", "x", 8, "tab stop width")
_ = viper.BindPFlag("general.TabWidth", rootCmd.PersistentFlags().Lookup("tab-width"))
_ = rootCmd.RegisterFlagCompletionFunc("tab-width", func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
Expand Down
9 changes: 9 additions & 0 deletions oviewer/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ func (root *Root) setViewMode(ctx context.Context, modeName string) {
}

root.Doc.general = mergeGeneral(root.Doc.general, c)
root.Doc.conv = root.Doc.converterType(root.Doc.general.Converter)
root.Doc.regexpCompile()
root.Doc.ClearCache()
root.ViewSync(ctx)
Expand All @@ -428,6 +429,14 @@ func (root *Root) modeConfig(modeName string) (general, error) {
return c, nil
}

func (root *Root) setConverter(ctx context.Context, name string) {
m := root.Doc
m.general.Converter = name
m.conv = m.converterType(name)
root.Doc.ClearCache()
root.ViewSync(ctx)
}

// setDelimiter sets the delimiter string.
func (root *Root) setDelimiter(input string) {
root.Doc.setDelimiter(input)
Expand Down
2 changes: 1 addition & 1 deletion oviewer/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func Parse_Helper(b *testing.B, fileName string) {
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
parseString(string(f), 8)
StrToContents(string(f), 8)
}
}

Expand Down
Loading

0 comments on commit c1f7690

Please sign in to comment.