Comments (5)
You're right. The problem is happening because the input is evaluating its size before theming. I tried to fix it by evaluating the width after theming and it solved the panic, but I found more existing bugs lol
I noticed that WithWidth
has no effect when called with Input because form and group override its value by the current terminal width (even in standalone inputs because Input.Run()
is just a wrapper for a form with a single group). This also happens to other fields than Input.
I have a solution in mind and can work on the fix if the authors (cc @maaslalani @meowgorithm) haven't yet.
If you need a temporary solution in this version, you can create a form and set the width on it.
huh.NewForm(
huh.NewGroup(
huh.NewInput().
Title("Enter Slack workspace name").
Value(&workspace).
Description("Blah"),
),
).WithWidth(40).Run()
from huh.
Ah interesting, thanks for the detailed bug report @rusq!
@vitor-mariano if I understand your comment correctly this happens only with the single input Run
shorthand due to a bug with how form widths / input widths are handled? In that case, we'd be more than delighted to accept a PR for the fix but also happy to fix it ourselves as it seems it's an issue with how the theme/width is being applied.
from huh.
Not really. Let me detail it more.
- The problems happen regardless of the standalone use. I just emphasized that a standalone input works similarly to a grouped input.
- I checked the problems with
WithWidth
happen to other field types. - The panic is only one bug related to
WithWidth
.
Fixing the panic issue, I noticed a second bug. The lib ignores the width of the fields. This happens in two scenarios:
- When you also set
WithWidth
inform
, it overrides the width of all its children.The resulting size will be 60 becausehuh.NewForm( huh.NewGroup( huh.NewInput(). Title("Enter Slack workspace name"). Value(&workspace). Description("Blah"). WithWidth(40), ), ).WithWidth(60).Run()
form
propagatesWithWidth
to all its children. - When you don't set
WithWidth
inform
it propagates the window size to all its children, similarly to when you setWithWidth
explicitly:
https://github.com/charmbracelet/huh/blob/main/form.go#L325-L331case tea.WindowSizeMsg: if f.width > 0 { break } for _, group := range f.groups { group.WithWidth(msg.Width) }
I haven't tested groups yet, but I'm pretty sure the same bug applies.
from huh.
I think the solution is to have two properties in all field types:
maxWidth
that holds the desired field width.- the existing
width
will be the current rendered width.
To handle these properties, we could have the following functions:
- A new function
Resize(width int)
will set the current width without changing themaxWidth
. - The existing
WithWidth(width int)
function will set themaxWidth
and resize.
This way, the form and groups can control the current width of its fields respecting the maximum width set by the developer.
from huh.
This is fixed by #92
from huh.
Related Issues (20)
- Black and white color Spinner HOT 1
- Releaase 0.3.1 for File Picker HOT 1
- Theme.FieldSeparator no longer supported in 0.4.x? HOT 1
- MultiSelect's filterable set to "false" will have no effect.
- Add Filterable for Select HOT 2
- Empty confirmation considered invalid in accessible mode HOT 1
- Add "Select All" and "Invert" Shortcuts to Multiselect
- Add `WithInput` to specify input stream
- Overriding KeyMaps and KeyBinds
- Fullscreen / AltScreen does not take the full screen - there seems to be a maximum height
- Multiple forms can interfere with each other
- Keypresses are ignored upon reaching 2nd form (examples/gh) HOT 3
- Windows: Tab/Enter keys not handled correctly HOT 4
- bug: note.render should escape everything in code block HOT 2
- Hiding implicit focus indicators HOT 2
- Get input as an integer or other type HOT 4
- Group Title and Description don't work
- NewNote() will lose color and return to monochrome HOT 1
- Adding a test package to simplify testing interactive commands HOT 1
- Dynamic fields don't update when form is active HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from huh.