Add config options for showing and hiding the top menu and line index

This commit is contained in:
EnumDev 2025-06-12 21:16:33 +03:00
parent 444c355117
commit dd0cc2a293
5 changed files with 30 additions and 6 deletions

View File

@ -3,4 +3,6 @@ selected_style: "default" # Style for 256-color and true-color capable terminals
selected_style_fallback: "default-fallback" # Style for 8-color capable terminals (Like TTYs)
# Other
show_top_menu: true
show_line_index: true
tab_indentation: 4 # Length of tab characters

View File

@ -10,6 +10,8 @@ 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"`
}
@ -19,6 +21,8 @@ func readConfig() {
Config = TyperConfig{
SelectedStyle: "default",
FallbackStyle: "default-fallback",
ShowTopMenu: true,
ShowLineIndex: true,
TabIndentation: 4,
}

View File

@ -53,7 +53,7 @@ func drawDropdowns(window *Window) {
dropdownStyle := tcell.StyleDefault.Background(CurrentStyle.DropdownBg).Foreground(CurrentStyle.DropdownFg)
for _, d := range dropdowns {
drawBox(window.screen, d.PosX, d.PosY, d.PosX+d.Width+1, d.PosY+len(d.Options)+1, dropdownStyle)
line := d.PosY
line := 1
for i, option := range d.Options {
if d.Selected == i {
drawText(window.screen, d.PosX+1, d.PosY+line, d.PosX+d.Width+1, d.PosY+line, dropdownStyle.Background(CurrentStyle.DropdownSel), option)

View File

@ -22,7 +22,13 @@ func initTopMenu() {
Name: "File",
Action: func(window *Window) {
ClearDropdowns()
d := CreateDropdownMenu([]string{"New", "Save", "Open", "Close", "Quit"}, 0, 1, 0, func(i int) {
y := 0
if window.ShowTopMenu {
y++
}
d := CreateDropdownMenu([]string{"New", "Save", "Open", "Close", "Quit"}, 0, y, 0, func(i int) {
switch i {
case 0:
RunCommand(window, "new-buffer")
@ -45,7 +51,13 @@ func initTopMenu() {
Name: "Edit",
Action: func(window *Window) {
ClearDropdowns()
d := CreateDropdownMenu([]string{"Copy", "Paste"}, 0, 1, 0, func(i int) {
y := 0
if window.ShowTopMenu {
y++
}
d := CreateDropdownMenu([]string{"Copy", "Paste"}, 0, y, 0, func(i int) {
switch i {
case 0:
RunCommand(window, "copy")
@ -63,6 +75,12 @@ func initTopMenu() {
Name: "Buffers",
Action: func(window *Window) {
ClearDropdowns()
y := 0
if window.ShowTopMenu {
y++
}
buffersSlice := make([]string, 0)
for _, buffer := range Buffers {
if window.CurrentBuffer == buffer {
@ -74,7 +92,7 @@ func initTopMenu() {
slices.Sort(buffersSlice)
d := CreateDropdownMenu(buffersSlice, 0, 1, 0, func(i int) {
d := CreateDropdownMenu(buffersSlice, 0, y, 0, func(i int) {
start := strings.Index(buffersSlice[i], "[")
end := strings.Index(buffersSlice[i], "]")

View File

@ -39,8 +39,8 @@ var mouseHeld = false
func CreateWindow() (*Window, error) {
window := Window{
ShowTopMenu: true,
ShowLineIndex: true,
ShowTopMenu: Config.ShowTopMenu,
ShowLineIndex: Config.ShowLineIndex,
CursorMode: CursorModeBuffer,
CurrentBuffer: nil,