Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to serialize form content and status to/from JSON ? #929

Open
X-Ryl669 opened this issue Dec 20, 2023 · 3 comments
Open

Add a way to serialize form content and status to/from JSON ? #929

X-Ryl669 opened this issue Dec 20, 2023 · 3 comments

Comments

@X-Ryl669
Copy link

If would be very useful if it was possible to serialize a form to/from JSON (so one could build a form from a simple JSON stream) at runtime.
Also, when the form is "submitted" it would be great if it was possible to serialize the content of each FormItem's value to a JSON stream too.

The underlying idea would be to use tview in conjunction with lua (for example in a plugin) to build a form to ask something to the user and be able to react when it's changed.

@digitallyserviced
Copy link
Contributor

@X-Ryl669 I think you're looking to integrate something that is best suited by other libraries.

tview is a TUI, widget, interface, view, framework. It does that well, and should continue to do just that, well...

It is like trying to reinventing the wheel. What if it is decided to put carbon fiber wheels on the tview car because some people like carbon fiber? Maybe you hate carbon fiber, because it killed your dog.

Also what if the carbon fiber wheels, are not properly installed, or they get holes from big ass bugs in them? And now because tview mechanic's would rather prioritize their precious time on UI/UX/widget features/bugs, your hole doesn't get fixed.

I hope this doesn't sound rude, but it's facts. Especially when you're asking for features to be built for you, when what you're asking for is rather simple, and json encoding is a first-party feature built into go's stdlib. You can even json:"fieldName" public fields in your struct to then json.Marshal it, or json:"-" to ignore that field from being encoded.

This is what development is about, using libraries, integrating code.

  • Good developers write good code.
  • Great developers copy good code.
  • Elite developers delete good code.

In all honesty it sounds like you are looking for a framework, or library that does more of what you're asking for specifically, rather than asking other people to make it do what you want.

Here's a library/framework specifically for asking questions in a terminal.

https://github.com/charmbracelet/huh

image

@X-Ryl669
Copy link
Author

Thanks for the link to huh.

TBH, I was looking at some widget collection derived from tcell to integrate in micro's editor. My idea was to be able to trigger a dialog in Lua (micro implements a Lua based plugin system). Building the interface in Lua is too low level (and it doesn't solve the event loop issue). So the logical solution would be to have a Go-based dynamic form creation (to be implemented in micro's Go level) and that the form description and value would be serialized to/from Lua.

I guess it's not too specific a feature, since building forms by hand is painful for everyone, every change implies rebuilding (which is slow). A dynamic form sounds like a must-have for ease of development, IMHO.

I understand it might not be the goal of this project, it's a feature request (hence the question mark at the end of the issue's title).

BTW, I'm not a Go developer, so yes it may sounds like a "do this for me" request, simple because I can't do it by myself efficiently.

@digitallyserviced
Copy link
Contributor

@X-Ryl669

On the note of micro's editor. I am not sure if you are aware of the stripped down version of the micro editor that can be utilized within tview, that pgavlin ripped out of micro.

I have a fork as well which added back a gutter, and some other integrations with how it handles colors.

This is a previous issue I had linked to it in... HOpefully it will help, or provide some insight/inspriation/guidance/scratch of the itch

There is a widget from pgavlin that I have forked and updated the color handling and re-added some features back that were stripped out.

The editor is an old version of the micro editor's main text view for code editing with syntax highlighting enabled, albeit in a rather simplistic form. It is fairly simple to use, both repo's linked below have example usages.

image

digitallyserviced/femto and pgavlin/femto

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants