[GH-ISSUE #93] customised command mode input field #72

Closed
opened 2026-03-04 01:01:39 +03:00 by kerem · 2 comments
Owner

Originally created by @stephencheng on GitHub (Mar 30, 2018).
Original GitHub issue: https://github.com/rivo/tview/issues/93

I have special need to implement a command mode input field.

Basically, I use this type of field to hook up with defined key for quick value change. For example:

  • use ctrlj/ctrlk to increase/decrease the value by 1 (not sure if j/k alone is possible), I tested with ctrlj/ctrlk anyway.
  • use ctrlh/ctrll to increase/decrease the value by 10
  • allow user to define a initial value

I hacked the code for the test, it worked perfect, shown as below:

`

	switch key := event.Key(); key {
	//case tcell.KeyRune: // Regular character.
	//	newText := i.text + string(event.Rune())
	//	if i.accept != nil {
	//		if !i.accept(newText, event.Rune()) {
	//			break
	//		}
	//	}
	//	i.text = newText

	case tcell.KeyCtrlJ:
		i.text = i.text + "+10"
	case tcell.KeyCtrlK:
		i.text = i.text + "-10"

`

I thought I should follow the guid of the primitive sample to make it my own inputfield, so I did a copy of the inputfield go file in order to just add my own logic to handle the key binding part. I could replace all different inner function with exported public method, like Getxx in order to remove compilation errors, but there is one left, which is the border(bool)

if i.border { x++ y++ rightLimit -= 2 }

so my questions:

  1. Is it worth doing my way or you could provide a way to extend the existing inputfield, if so, I will require a few things:
  • allow user to add more key binding
  • provide a way to disable: case tcell.KeyRune
  1. or could you provide a expose method for board method?

Thank you

Originally created by @stephencheng on GitHub (Mar 30, 2018). Original GitHub issue: https://github.com/rivo/tview/issues/93 I have special need to implement a command mode input field. Basically, I use this type of field to hook up with defined key for quick value change. For example: * use ctrlj/ctrlk to increase/decrease the value by 1 (not sure if j/k alone is possible), I tested with ctrlj/ctrlk anyway. * use ctrlh/ctrll to increase/decrease the value by 10 * allow user to define a initial value I hacked the code for the test, it worked perfect, shown as below: ` switch key := event.Key(); key { //case tcell.KeyRune: // Regular character. // newText := i.text + string(event.Rune()) // if i.accept != nil { // if !i.accept(newText, event.Rune()) { // break // } // } // i.text = newText case tcell.KeyCtrlJ: i.text = i.text + "+10" case tcell.KeyCtrlK: i.text = i.text + "-10" ` I thought I should follow the guid of the primitive sample to make it my own inputfield, so I did a copy of the inputfield go file in order to just add my own logic to handle the key binding part. I could replace all different inner function with exported public method, like Getxx in order to remove compilation errors, but there is one left, which is the border(bool) ` if i.border { x++ y++ rightLimit -= 2 } ` so my questions: 1. Is it worth doing my way or you could provide a way to extend the existing inputfield, if so, I will require a few things: * allow user to add more key binding * provide a way to disable: case tcell.KeyRune 2. or could you provide a expose method for board method? Thank you
kerem closed this issue 2026-03-04 01:01:39 +03:00
Author
Owner

@rivo commented on GitHub (Apr 1, 2018):

I think what you'll want is SetInputCapture(). There is an example in the Wiki. It's on the Application level but it works the same for primitives.

Let me know if this works for you.

<!-- gh-comment-id:377769226 --> @rivo commented on GitHub (Apr 1, 2018): I think what you'll want is [`SetInputCapture()`](https://godoc.org/github.com/rivo/tview#Box.SetInputCapture). There is an example in the [Wiki](https://github.com/rivo/tview/wiki/Primitives#hooking-into-key-events). It's on the `Application` level but it works the same for primitives. Let me know if this works for you.
Author
Owner

@stephencheng commented on GitHub (Apr 3, 2018):

Thanks. primitive level SetInputCapture is exactly what I needed.

It's great to have all these loving feature already there

<!-- gh-comment-id:378241674 --> @stephencheng commented on GitHub (Apr 3, 2018): Thanks. primitive level SetInputCapture is exactly what I needed. It's great to have all these loving feature already there
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#72
No description provided.