Skip to content

Commit

Permalink
Add support vertical header and header column
Browse files Browse the repository at this point in the history
Add command line options for vertical header and vertical header column.
The specified vertical header will be displayed fixedly.
Only one of vertical header or vertical header column can be applied.
  • Loading branch information
noborus committed Jan 22, 2025
1 parent 4f4e9e5 commit efb5431
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 7 deletions.
11 changes: 11 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,17 @@ func init() {
return []string{"1"}, cobra.ShellCompDirectiveNoFileComp
})

rootCmd.PersistentFlags().IntP("vertical-header", "y", 0, "number of characters to display as a vertical header")
_ = viper.BindPFlag("general.VerticalHeader", rootCmd.PersistentFlags().Lookup("vertical-header"))
_ = rootCmd.RegisterFlagCompletionFunc("vertical-header", func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
return []string{"1"}, cobra.ShellCompDirectiveNoFileComp
})
rootCmd.PersistentFlags().IntP("header-column", "Y", 0, "number of columns to display as a vertical header")
_ = viper.BindPFlag("general.VerticalHeaderColumn", rootCmd.PersistentFlags().Lookup("header-column"))
_ = rootCmd.RegisterFlagCompletionFunc("header-column", func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
return []string{"1"}, cobra.ShellCompDirectiveNoFileComp
})

rootCmd.PersistentFlags().IntP("skip-lines", "", 0, "skip the number of lines")
_ = viper.BindPFlag("general.SkipLines", rootCmd.PersistentFlags().Lookup("skip-lines"))
_ = rootCmd.RegisterFlagCompletionFunc("skip-lines", func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
Expand Down
11 changes: 7 additions & 4 deletions oviewer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ type Config struct {
StyleMarkLine OVStyle
// StyleSectionLine is a style that section delimiter line.
StyleSectionLine OVStyle
// StyleVerticalHeader is a style that applies to the vertical header.
StyleVerticalHeader OVStyle
// StyleJumpTargetLine is the line that displays the search results.
StyleJumpTargetLine OVStyle
// StyleAlternate is a style that applies line by line.
Expand Down Expand Up @@ -108,12 +110,10 @@ func NewConfig() Config {
Background: "gray",
},
StyleOverStrike: OVStyle{
Bold: true,
UnderlineStyle: "3",
Bold: true,
},
StyleOverLine: OVStyle{
Underline: true,
UnderlineStyle: "2",
Underline: true,
},
StyleLineNumber: OVStyle{
Bold: true,
Expand All @@ -130,6 +130,9 @@ func NewConfig() Config {
StyleSectionLine: OVStyle{
Background: "slateblue",
},
StyleVerticalHeader: OVStyle{
Reverse: true,
},
StyleMultiColorHighlight: []OVStyle{
{Foreground: "red"},
{Foreground: "aqua"},
Expand Down
32 changes: 29 additions & 3 deletions oviewer/draw.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (root *Root) drawWrapLine(y int, lX int, lN int, lineC LineC) (int, int) {
log.Printf("Illegal lX:%d", lX)
return 0, 0
}

currentLX := lX
screen := root.Screen
for n := 0; ; n++ {
x := root.scr.startX + n
Expand All @@ -185,7 +185,9 @@ func (root *Root) drawWrapLine(y int, lX int, lN int, lineC LineC) (int, int) {
}
screen.SetContent(x, y, c.mainc, c.combc, c.style)
}

if currentLX == 0 {
root.drawVerticalHeader(y, lineC)
}
return lX, lN
}

Expand All @@ -209,10 +211,34 @@ func (root *Root) drawNoWrapLine(y int, lX int, lN int, lineC LineC) (int, int)
screen.SetContent(x, y, c.mainc, c.combc, c.style)
}
lN++

root.drawVerticalHeader(y, lineC)
return lX, lN
}

func (root *Root) drawVerticalHeader(y int, lineC LineC) int {
vheader := 0
if root.General.VerticalHeaderColumn > 0 && len(lineC.columnRanges) > root.General.VerticalHeaderColumn {
vheader = lineC.columnRanges[root.General.VerticalHeaderColumn-1].end + 1
}
if root.General.VerticalHeader > 0 {
vheader = root.General.VerticalHeader
}
if vheader == 0 {
return 0
}
screen := root.Screen
for n := 0; n < vheader; n++ {
x := root.scr.startX + n
c := DefaultContent
if n < len(lineC.lc) {
c = lineC.lc[n]
}
style := applyStyle(c.style, root.StyleVerticalHeader)
screen.SetContent(x, y, c.mainc, c.combc, style)
}
return vheader
}

// blankLineNumber should be blank for the line number.
func (root *Root) blankLineNumber(y int) {
if !root.Doc.LineNumMode {
Expand Down
4 changes: 4 additions & 0 deletions oviewer/oviewer.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ type general struct {
TabWidth int
// Header is number of header lines to be fixed.
Header int
// VerticalHeader is the number of vertical header lines.
VerticalHeader int
// VerticalHeaderColumn is the number of vertical header columns.
VerticalHeaderColumn int
// SkipLines is the rows to skip.
SkipLines int
// WatchInterval is the watch interval (seconds).
Expand Down

0 comments on commit efb5431

Please sign in to comment.