Comments (7)
Other people requested this behaviour before (#54 (comment)) and after some tests I think it's good change. So, PR #66 should fix it, can you check?
Thanks! :)
from gocui.
BTW take into account that after this change if any keybinding matches the event, its handler is executed and the edition step is skipped. It means that, in your example, if you want to type i
after making the view Editable, you will need to delete the keybinding.
if err := g.DeleteKeybinding("main", 'i', gocui.ModNone); err != nil {
return err
}
Maybe this behaviour could be configurable if there is a rationale for that.
from gocui.
I can defiantly try this out and get back to you later today. Thanks for the changes.
from gocui.
That looks good for me. Your right, with this new commit I would have to assign the key again if I ever wanted that functionality back. Here is my previous code modified to do just that and works with your new commit:
package main
import (
"log"
"github.com/jroimartin/gocui"
)
func edit(g *gocui.Gui, v *gocui.View) error {
v.Editable = true
if err := g.DeleteKeybinding("main", 'i', gocui.ModNone); err != nil { return err }
return nil
}
func escape_edit(g *gocui.Gui, v *gocui.View) error {
v.Editable = false
if err := g.SetKeybinding("main", 'i', gocui.ModNone, edit); err != nil {return err}
return nil
}
func quit(g *gocui.Gui, v *gocui.View) error {
return gocui.ErrQuit
}
func keybindings(g *gocui.Gui) error {
if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {return err}
if err := g.SetKeybinding("main", 'i', gocui.ModNone, edit); err != nil {return err}
if err := g.SetKeybinding("main", gocui.KeyEsc, gocui.ModNone, escape_edit); err != nil {return err}
return nil
}
func layout(g *gocui.Gui) error {
maxX, maxY := g.Size()
if v, err := g.SetView("main", 30, -1, maxX, maxY); err != nil {
if err != gocui.ErrUnknownView {
return err
}
v.Editable = false
v.Wrap = true
if _, err := g.SetCurrentView("main"); err != nil {return err}
}
return nil
}
func main() {
g, _ := gocui.NewGui()
defer g.Close()
g.SetManagerFunc(layout)
keybindings(g);
g.Cursor = true
g.InputEsc = true
if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {log.Panicln(err)}
}
I think this is an improvement because it always mean the key handler will capture that key unless the handler doesn't exist. Although, I do agree with your last comment that it may be nice to have the ability to change this functionality based on the situation.
Maybe another argument to the SetKeybinding() function to either capture or pass through the key press???
Don't know but like I said, I think this is an improvement. Thanks!
from gocui.
Let's keep it simple for now. At some point, if needed, we can add a Passthrough field to View.
BTW for your specific case, you can use the Editor interface to implement a custom edition mode. For instance, the following snippet shows how to create a simple vim editor:
https://gist.github.com/jroimartin/1ac98d3da7278fa18866c9cae0af6007
from gocui.
PR #67 is also related.
from gocui.
Cool! I will have to take a look at that. Thanks for the help. It looks like you merge this change into master so you can close this issue if it isn't still in progress.
Cheers!
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.