Coder Social home page Coder Social logo

Comments (7)

jroimartin avatar jroimartin commented on August 25, 2024

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.

jroimartin avatar jroimartin commented on August 25, 2024

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.

thekeymaker avatar thekeymaker commented on August 25, 2024

I can defiantly try this out and get back to you later today. Thanks for the changes.

from gocui.

thekeymaker avatar thekeymaker commented on August 25, 2024

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.

jroimartin avatar jroimartin commented on August 25, 2024

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.

jroimartin avatar jroimartin commented on August 25, 2024

PR #67 is also related.

from gocui.

thekeymaker avatar thekeymaker commented on August 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.