From 7af696cc20aa9013e84c64a194bb36b381e78110 Mon Sep 17 00:00:00 2001 From: EnumDev Date: Sat, 14 Jun 2025 17:15:53 +0300 Subject: [PATCH] Add 'extend_line_index' config option --- config/config.yml | 1 + src/config.go | 2 ++ src/line_index.go | 25 ++++++++++++++++--------- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/config/config.yml b/config/config.yml index 47c8a96..a5d0e11 100644 --- a/config/config.yml +++ b/config/config.yml @@ -5,5 +5,6 @@ selected_style_fallback: "default-fallback" # Style for 8-color capable terminal # Other show_top_menu: true show_line_index: true +extend_line_index: false # Extend line index to the bottom of the screen buffer_info_message: "File: %f Cursor: (%x, %y, %p) Chars: %c" tab_indentation: 4 # Length of tab characters \ No newline at end of file diff --git a/src/config.go b/src/config.go index 3f9b630..6923c92 100644 --- a/src/config.go +++ b/src/config.go @@ -12,6 +12,7 @@ type TyperConfig struct { FallbackStyle string `yaml:"fallback_style,omitempty"` ShowTopMenu bool `yaml:"show_top_menu,omitempty"` ShowLineIndex bool `yaml:"show_line_index,omitempty"` + ExtendLineIndex bool `yaml:"extend_line_index,omitempty"` BufferInfoMessage string `yaml:"buffer_info_message,omitempty"` TabIndentation int `yaml:"tab_indentation,omitempty"` } @@ -24,6 +25,7 @@ func readConfig() { FallbackStyle: "default-fallback", ShowTopMenu: true, ShowLineIndex: true, + ExtendLineIndex: false, BufferInfoMessage: "File: %f Cursor: (%x, %y, %p) Chars: %c", TabIndentation: 4, } diff --git a/src/line_index.go b/src/line_index.go index 97417bd..33ada80 100644 --- a/src/line_index.go +++ b/src/line_index.go @@ -12,16 +12,22 @@ func drawLineIndex(window *Window) { lineIndexStyle := tcell.StyleDefault.Background(CurrentStyle.LineIndexBg).Foreground(CurrentStyle.LineIndexFg) - _, sizeY := screen.Size() - - y := 0 - if window.ShowTopMenu { - y = 1 - } - lineIndexSize := getLineIndexSize(window) - for lineIndex := 1 + buffer.OffsetY; lineIndex <= strings.Count(buffer.Contents, "\n")+1 && lineIndex < sizeY+buffer.OffsetY; lineIndex++ { + _, bufferY1, _, bufferY2 := window.GetTextAreaDimensions() + + lineIndex := 1 + buffer.OffsetY + for y := bufferY1; y <= bufferY2; y++ { + if lineIndex > strings.Count(buffer.Contents, "\n")+1 { + if Config.ExtendLineIndex { + for x := 0; x < lineIndexSize; x++ { + screen.SetContent(x, y, ' ', nil, lineIndexStyle) + } + continue + } else { + break + } + } for x := 0; x < lineIndexSize; x++ { screen.SetContent(x, y, ' ', nil, lineIndexStyle) @@ -30,7 +36,8 @@ func drawLineIndex(window *Window) { text := strconv.Itoa(lineIndex) drawText(screen, lineIndexSize-len(text)-1, y, lineIndexSize, y, lineIndexStyle, text) - y++ + + lineIndex++ } }