Skip to content

Commit

Permalink
Fix for rad init UI issue on a small terminal (#8068)
Browse files Browse the repository at this point in the history
# Description

- Removed hard coded values for width and height for list model.
- Dynamically change the width or height of the list model depending on
the terminal dimensions.

## Type of change

<!--

Please select **one** of the following options that describes your
change and delete the others. Clearly identifying the type of change you
are making will help us review your PR faster, and is used in authoring
release notes.

If you are making a bug fix or functionality change to Radius and do not
have an associated issue link please create one now.

-->

- This pull request fixes a bug in Radius and has an approved issue
(issue link required).

<!--

Please update the following to link the associated issue. This is
required for some kinds of changes (see above).

-->

Fixes: #6492

## Contributor checklist
Please verify that the PR meets the following requirements, where
applicable:

- [ ] An overview of proposed schema changes is included in a linked
GitHub issue.
- [ ] A design document PR is created in the [design-notes
repository](https://github.com/radius-project/design-notes/), if new
APIs are being introduced.
- [ ] If applicable, design document has been reviewed and approved by
Radius maintainers/approvers.
- [ ] A PR for the [samples
repository](https://github.com/radius-project/samples) is created, if
existing samples are affected by the changes in this PR.
- [ ] A PR for the [documentation
repository](https://github.com/radius-project/docs) is created, if the
changes in this PR affect the documentation or any user facing updates
are made.
- [ ] A PR for the [recipes
repository](https://github.com/radius-project/recipes) is created, if
existing recipes are affected by the changes in this PR.

---------

Signed-off-by: Vishwanath Hiremath <[email protected]>
  • Loading branch information
vishwahiremat authored Nov 19, 2024
1 parent ec57f59 commit c1237c2
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pkg/cli/prompt/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ import (
"github.com/charmbracelet/x/ansi"
)

const listHeight = 14

const defaultWidth = 400

var (
titleStyle = lipgloss.NewStyle().PaddingLeft(2)
itemStyle = lipgloss.NewStyle().PaddingLeft(4)
Expand Down Expand Up @@ -92,7 +88,8 @@ func NewListModel(choices []string, promptMsg string) ListModel {
items[i] = item(choice)
}

l := list.New(items, itemHandler{}, defaultWidth, listHeight)
// setting width and height of list model to 0, that means its set to terminal width/height.
l := list.New(items, itemHandler{}, 0, 0)
l.Title = promptMsg
l.SetShowStatusBar(false)
l.SetFilteringEnabled(true)
Expand Down Expand Up @@ -134,6 +131,9 @@ func (m ListModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.WindowSizeMsg:
m.width = msg.Width
// setting the width and height of the list model as terminal dimensions changes.
// setting the height to 25% of the height of the terminal height.
m.List.SetSize(msg.Width, msg.Height-((3*msg.Height)/4))
case tea.KeyMsg:
switch keypress := msg.String(); keypress {
case "ctrl+c", "q":
Expand Down

0 comments on commit c1237c2

Please sign in to comment.