From 90913b6d866ac5f7ffc97f77a341a0bde74eaa3c Mon Sep 17 00:00:00 2001 From: shipengqi Date: Thu, 7 Mar 2024 10:27:03 +0800 Subject: [PATCH] feat(select): implementing a responsive select --- internal/config/config.go | 10 +++++++++- internal/config/default.go | 4 ++-- internal/render/template.go | 12 ++++++++++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index d8fd43b..49825e0 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -98,7 +98,15 @@ func (c *Config) createTemplatesSelect(label string) *ui.SelectModel { for _, v := range all { choices = append(choices, ui.Choice(v.Name)) } - m := ui.NewSelect(label, choices) + height := 8 + if len(all) > 5 { + height = 12 + } else if len(all) > 3 { + height = 10 + } else if len(all) > 2 { + height = 9 + } + m := ui.NewSelect(label, choices).WithHeight(height) return m } diff --git a/internal/config/default.go b/internal/config/default.go index 7680de5..e8b0de5 100644 --- a/internal/config/default.go +++ b/internal/config/default.go @@ -19,9 +19,9 @@ items: - name: WIP desc: "Work in progress" - name: chore - desc: "Changes to the build process or auxiliary tools\n and libraries such as documentation generation" + desc: "Changes to the build process or auxiliary tools and\n libraries such as documentation generation" - name: style - desc: "Changes that do not affect the meaning of the code\n (white-space, formatting, missing semi-colons, etc)" + desc: "Changes that do not affect the meaning of the code\n (white-space, formatting, missing semi-colons, etc)" - name: refactor desc: "A code change that neither fixes a bug nor adds a feature" - name: perf diff --git a/internal/render/template.go b/internal/render/template.go index 2909487..f03bab0 100644 --- a/internal/render/template.go +++ b/internal/render/template.go @@ -18,7 +18,7 @@ type Option struct { func (o *Option) String() string { var b strings.Builder ml := len(o.Name) - pl := 10 - ml - 2 + pl := 12 - ml - 2 padding := strings.Repeat(" ", pl) b.WriteString(o.Name) b.WriteString(": ") @@ -143,7 +143,15 @@ func (t *Template) createSelectItem(label string, options []Option) *ui.SelectMo for _, v := range options { choices = append(choices, ui.Choice(v.String())) } - m := ui.NewSelect(label, choices) + height := 8 + if len(options) > 5 { + height = 12 + } else if len(options) > 3 { + height = 10 + } else if len(options) > 2 { + height = 9 + } + m := ui.NewSelect(label, choices).WithHeight(height) return m }