diff --git a/config/config.yml b/config/config.yml index e761a7d..47c8a96 100644 --- a/config/config.yml +++ b/config/config.yml @@ -5,4 +5,5 @@ selected_style_fallback: "default-fallback" # Style for 8-color capable terminal # Other show_top_menu: true show_line_index: true +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 ac8a5f2..3f9b630 100644 --- a/src/config.go +++ b/src/config.go @@ -8,22 +8,24 @@ import ( ) type TyperConfig struct { - SelectedStyle string `yaml:"selected_style,omitempty"` - FallbackStyle string `yaml:"fallback_style,omitempty"` - ShowTopMenu bool `yaml:"show_top_menu,omitempty"` - ShowLineIndex bool `yaml:"show_line_index,omitempty"` - TabIndentation int `yaml:"tab_indentation,omitempty"` + SelectedStyle string `yaml:"selected_style,omitempty"` + FallbackStyle string `yaml:"fallback_style,omitempty"` + ShowTopMenu bool `yaml:"show_top_menu,omitempty"` + ShowLineIndex bool `yaml:"show_line_index,omitempty"` + BufferInfoMessage string `yaml:"buffer_info_message,omitempty"` + TabIndentation int `yaml:"tab_indentation,omitempty"` } var Config TyperConfig func readConfig() { Config = TyperConfig{ - SelectedStyle: "default", - FallbackStyle: "default-fallback", - ShowTopMenu: true, - ShowLineIndex: true, - TabIndentation: 4, + SelectedStyle: "default", + FallbackStyle: "default-fallback", + ShowTopMenu: true, + ShowLineIndex: true, + BufferInfoMessage: "File: %f Cursor: (%x, %y, %p) Chars: %c", + TabIndentation: 4, } homeDir, err := os.UserHomeDir() diff --git a/src/top_menu.go b/src/top_menu.go index 5282ce4..842617b 100644 --- a/src/top_menu.go +++ b/src/top_menu.go @@ -133,11 +133,38 @@ func drawTopMenu(window *Window) { } // Draw buffer info + bufferInfoMsg := getBufferInfoMsg(window) + drawText(screen, sizeX-len(bufferInfoMsg)-1, 0, sizeX-1, 0, topMenuStyle, bufferInfoMsg) +} + +func getBufferInfoMsg(window *Window) string { + pathToFile := "Not set" filename := "Not set" + if window.CurrentBuffer.filename != "" { + pathToFile = window.CurrentBuffer.filename + } if filepath.Base(window.CurrentBuffer.filename) != "." { filename = filepath.Base(window.CurrentBuffer.filename) } + + cursorPos := window.CurrentBuffer.CursorPos cursorX, cursorY := window.GetCursorPos2D() - cursorInfo := fmt.Sprintf("File: %s Cursor: (%d,%d,%d) Words: %d", filename, cursorX+1, cursorY+1, window.CurrentBuffer.CursorPos+1, len(strings.Fields(window.CurrentBuffer.Contents))) - drawText(screen, sizeX-len(cursorInfo)-1, 0, sizeX-1, 0, topMenuStyle, cursorInfo) + cursorX++ + cursorY++ + + chars := len(window.CurrentBuffer.Contents) + words := len(strings.Fields(window.CurrentBuffer.Contents)) + + ret := Config.BufferInfoMessage + + ret = strings.ReplaceAll(ret, "\n", " ") + ret = strings.ReplaceAll(ret, "%F", pathToFile) + ret = strings.ReplaceAll(ret, "%f", filename) + ret = strings.ReplaceAll(ret, "%x", strconv.Itoa(cursorX)) + ret = strings.ReplaceAll(ret, "%y", strconv.Itoa(cursorY)) + ret = strings.ReplaceAll(ret, "%p", strconv.Itoa(cursorPos)) + ret = strings.ReplaceAll(ret, "%c", strconv.Itoa(chars)) + ret = strings.ReplaceAll(ret, "%w", strconv.Itoa(words)) + + return ret }