Comments (7)
Can you confirm if it only happens with lines that have been manually written in editable Views?
If so, it's closely related to #60 and should be fixed once that issue is closed. On the other hand, rewriting the edition mode is in progress and (hopefully) will be merged soon.
from gocui.
Confirmed -- this is only happening with view's that have editors attached.
FYI, my use case is creating a "field widget" to enter 1 line of short text, like a input field on a web page. It will have a label, a fieldName and a maxLength. This will create two views, 1 that will contain the field label and another 1 row view that will be used for the field entry text.
I wrappered the exiting editor to handle the complex part of editing, but my wrapper simple ignores up/down arrows and prevents text beyond maxLength for the field. This is also why the other enhancement request to allow a zero frame view. Let me know if I'm making this too complex and if there is a better way to do this.
from gocui.
What about doing it this way?
https://gist.github.com/jroimartin/3b2e943a3811d795e0718b4a95b89bec
from gocui.
Please, take into account that I did several simplifications, but should be enough to get an idea :)
from gocui.
Your example is pretty close, however it doesn't allow for arrow keys for editing text already typed into the field. My version used a wrapper around the DefaultEditor to do any special processing on keystrocks, then pass them onto the DefaultEditor as I didn't want to deal with the complexity of processing the arrow keys, insert, etc. Below was my func... a bit ugly with debug code in. Your solution was cleaner -- if it could handle the full editing of the field.
func (w *MyEditor) Edit(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) {
lineValue, _ := v.Line(0)
lineValue = strings.Replace(lineValue, "\x00", "", -1)
currentSize := len(lineValue)
atMax := false
if currentSize >= w.MaxFieldSize {
atMax = true
}
fmt.Printf("\n[%v], currentSize:%v atMax:%v ", lineValue, currentSize, atMax)
switch {
case key == gocui.KeyArrowRight:
x, _ := v.Cursor()
fmt.Printf("\nx:%v", x)
if x < currentSize {
w.baseEditor.Edit(v, key, ch, mod)
}
case key == gocui.KeyArrowLeft:
fallthrough
case key == gocui.KeyBackspace || key == gocui.KeyBackspace2:
fallthrough
case key == gocui.KeyDelete:
fallthrough
case key == gocui.KeyInsert:
w.baseEditor.Edit(v, key, ch, mod)
case key == gocui.KeyEnter:
// v.EditNewLine()
case key == gocui.KeyArrowDown:
// v.MoveCursor(0, 1, false)
case key == gocui.KeyArrowUp:
// v.MoveCursor(0, -1, false)
default:
if !atMax {
//fmt.Printf("key:[%v] ch:[%v]", key, ch )
w.baseEditor.Edit(v, key, ch, mod)
}
}
}
from gocui.
Yes, I tried to keep the snippet as simple as possible and focus on how to create widgets and so on. Definitely, the new edition mode should make easier to customize this kind of things.
from gocui.
Fixed via 2677ad0. Can you check? :)
from gocui.
Related Issues (20)
- Wrong layout when Title uses a different encoding HOT 1
- True color support ? HOT 2
- Keybindings not working on FreeBSD HOT 3
- Examples does not support east asian windows? HOT 1
- Can you support run jar packet? HOT 1
- force update HOT 6
- Add a project that using gocui HOT 1
- Update Screenshot Example HOT 1
- Start printing at cursor position
- Add lazygit to the list of projects HOT 1
- Better tags support HOT 2
- how to read input
- Support ANSI code for hyperlinks
- Add Omnivore to projects list.
- Lazydocker is not listed HOT 2
- Extended ANSI color codes are not supported
- Is the library still actively maintained?
- Chinese Support HOT 2
- KeyBinding For Mouse(Any of them) dosn't trigger HOT 2
- git-bug relies on gocui
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 gocui.