gizak / termui

Golang terminal dashboard
MIT License
13.14k stars 787 forks source link

New input element #129

Open sapessi opened 7 years ago

sapessi commented 7 years ago

Still missing lots of unit tests :( I'll keep working on them

meetmangukiya commented 7 years ago

@SAPessi does this work? Then I'll use your fork as the dep unless this is merged :D

sapessi commented 7 years ago

@meetmangukiya It does work, although I have tested all of the use-cases. Have a go and see if it works for you. If you find an issue let me know.

meetmangukiya commented 7 years ago

Ok, I'll have a go at it

sapessi commented 7 years ago

@meetmangukiya Did this work for you?

liushuchun commented 7 years ago

hi,body,I have tried this method.but when I input the Chinese words,it will be in the wrong sequence. image

sapessi commented 7 years ago

@liushuchun Do you expect it to be right to left or also vertical? This is definitely something that can be added.

pradeepto commented 7 years ago

@SAPessi Great stuff. Would love to see this merged. What is blocking it?

Griesbacher commented 7 years ago

@SAPessi Thanks for the PR. If found a little bug within your PR, this the code I've tested:

input := ui.NewInput("FOO BAR", false)
input.StartCapture()

On startup just press backspace when the courser is on the first position. Which results in such a panic:

panic: runtime error: index out of range

goroutine 1 [running]:
github.com/gizak/termui.(*Input).backspace(0xc4200fa000)
    /root/dev/go/src/github.com/gizak/termui/input.go:179 +0x2c7
github.com/gizak/termui.(*Input).StartCapture.func1(0x52f564, 0x8, 0xc4202e8bc4, 0xc, 0x52f2e8, 0x7, 0x0, 0x0, 0x50ca40, 0xc4202e8bd0, ...)
    /root/dev/go/src/github.com/gizak/termui/input.go:115 +0x5a1
github.com/gizak/termui.(*EvtStream).Loop.func1(0xc420046500, 0x52f564, 0x8, 0xc4202e8bc4, 0xc, 0x52f2e8, 0x7, 0x0, 0x0, 0x50ca40, ...)
    /root/dev/go/src/github.com/gizak/termui/events.go:251 +0xff
github.com/gizak/termui.(*EvtStream).Loop(0xc420046500)
    /root/dev/go/src/github.com/gizak/termui/events.go:253 +0x157
github.com/gizak/termui.Loop()
    /root/dev/go/src/github.com/gizak/termui/events.go:282 +0x2d
main.main()
...

If no string has been passed to the constructor everything works fine. I'm not sure if I did something wrong with the initialisation.

Edit: This happens also if an empty string has been passed and the first key pressed is a backspace.

Edit 2: If the arrow keys are pressed first also a out of bound error raises, in line 311 or 125 depending on the key pressed.

sapessi commented 7 years ago

@Griesbacher could be a bug, I'll look into it this weekend.

sapessi commented 7 years ago

@Griesbacher fixed those issues and added unit tests for them in the latest commit.

stephencheng commented 6 years ago

what's preventing this to be merged? can we get this one going into master?

sapessi commented 6 years ago

@gizak Should we close this pull request now that you've imported the input in a commit?

pjebs commented 6 years ago

@SAPessi which commit?

sapessi commented 6 years ago

Never mind, I confused the pull to another repo for this. @gizak, any idea whether this will be merged?

kellabyte commented 5 years ago

Any chances this could get merged? I think an input control would be really handy and I would love to use something already pre-existing. I don’t think it’s useful everyone implements a from scratch input control every time.

cjbassi commented 5 years ago

@kellabyte I'm currently finishing up rewriting termui but once I'm done with that I'll merge this and the other PRs too.

andre-l-mm commented 5 years ago

Hello @cjbassi and @gizak ,

I am wondering if the rewrite is included in version v3.0.0 released a week ago?

I am using termui and now need to implement some sort of input form. Is this pull request still planned to be included at some point?

I tried creating a local copy of input.go submitted in the pull request but it seems the code is not compatible anymore with version 3.

cjbassi commented 5 years ago

@andre-l-mm

The rewrite is included in v3.0.0.

So this PR is incompatible with the recent changes, so I've been working on rewriting it. You can check out the progress at the wip/input-widget branch. It's mostly functional, and it may work for you, but I still need to:

  1. add support for scrolling the view of the widget
  2. fix the text wrapping
  3. fix the cursor position on text wrap
  4. add support for line numbers

The widget is called TextBox, and it's going to supersede the Paragraph widget. I've added a few examples for it in the _examples/textbox.go file. All of the event handling is done client side vs library side since we don't have support for focusable widgets yet.

Feel free to create PR's against that branch if you end up using it.

andre-l-mm commented 5 years ago

Thanks @cjbassi, I will try the code on wip/input-widget branch today.

andre-l-mm commented 5 years ago

Hi @cjbassi , I started using the textbox widget and it looks cool. I was not able to find a method to retrieve back the text inputted and I am thinking of submitting a pull request adding a GetText() function. Does that make sense to you? For completion I am actually thinking of two functions:

cjbassi commented 5 years ago

@andre-l-mm Both of those sound good!

henri9813 commented 4 years ago

Hello,

Have you an idea when this will be released ? :D

Regards

thehaiwave commented 4 years ago

God has left us.