Git Product home page Git Product logo

Comments (10)

J-C-3 avatar J-C-3 commented on June 13, 2024 1

Thanks lmorg!

The vim keybindings are great, it's just that my brain doesn't switch from when I'm on a server vs local so adding some of that traditional shell shortcut goodness is very appreciated.

Thanks again for the awesome shell. I look forward to playing with it.

from murex.

xyproto avatar xyproto commented on June 13, 2024 1

ctrl-l is such a handy hotkey to quickly clear the screen. I don't believe the ViM mode provides this.

from murex.

lmorg avatar lmorg commented on June 13, 2024 1

I think what I'll do for this release is have the hotkeys in their own functions so they can be redefined with onKeyPress but keep them hardcoded in readline.go as a default as well.

Conversations about whether they can be undefined, read command, etc can still happen but the above piece of work is worthwhile from a code cleanliness point of view regardless of any further decisions that might happen.

from murex.

lmorg avatar lmorg commented on June 13, 2024 1

read uses the same readline code as the REPL. The problem is events are registered with the readline instance:


// Add a key to the event list
func (evt *keyPressEvents) Add(name, keySeq string, block []rune, fileRef *ref.File) error {
	if shell.Prompt == nil {
		return errors.New("unable to register event with readline API")
	}

	shell.Prompt.AddEvent(keySeq, evt.callback)
	evt.events = append(evt.events, keyPressEvent{
		name:    name,
		keySeq:  keySeq,
		block:   block,
		fileRef: fileRef,
	})
	return nil
}

https://github.com/lmorg/murex/blob/master/builtins/events/onKeyPress/keypress.go#L55

That all said, all that is registered is a callback function and the function parameters are stored in a slice in onKeyPress package. So it's possible I could push those events to other instantiations of readline too. I could even add a property to onKeyPress (or better yet(?), another event like onReplKeyPress) for events that people don't want defined globally for readline.

The other problem this throws up is whether there should be an expectation that any shell scripts honour these events too. By default, user profiles are not loaded if a script is executed (basically the same as interactive vs non-interactive usage of Bash et al). Which would mean if we want any readline defaults persistent then they might have to live in their own config file.

Put aside all of what I'm going on about right now. If I have some time I'll cut a PR for this after 4.2's out if you're open to the idea.

I'm very open to contributions. Regardless of how big or small. Even just correcting typos in documents. But if anyone is open to contributing code as well, well then I'd be honoured to accept your time and code :)

from murex.

lmorg avatar lmorg commented on June 13, 2024

Ctrl+U exists (albeit it clears the whole line but that's easy to change)

It would be trivial to add the others so I'll get them added in the next release.

For now, there are vim keybinding. Press ESC and you'll drop into VIM mode.

from murex.

distek avatar distek commented on June 13, 2024

Heyo! Not to throw a wrench in the PRocess, but will these be configurable? I'm thinking in the form of something like how inputrc currently works:

    "\C-A": beginning-of-line
    "\C-B": backward-char
    "\C-E": end-of-line
    "\C-F": forward-char
    "\C-K": kill-line
    "\C-L": clear-screen

Basically having predefined (and user defined? might be a bit much, though) functions that a user could then configure to be triggered by a key comb, with some sane defaults.

Edit to clarify what I mean:
Taking this bit here:

			print(seqSetCursorPosTopLeft + seqClearScreen)
			rl.echo()
			rl.renderHelpers()

And breaking that out to a function that could be called by something like onKeyPress or a another event if the user wants to get fancy.

from murex.

J-C-3 avatar J-C-3 commented on June 13, 2024

Heyo! Not to throw a wrench in the PRocess, but will these be configurable? I'm thinking in the form of something like how inputrc currently works:

    "\C-A": beginning-of-line
    "\C-B": backward-char
    "\C-E": end-of-line
    "\C-F": forward-char
    "\C-K": kill-line
    "\C-L": clear-screen

Basically having predefined (and user defined? might be a bit much, though) functions that a user could then configure to be triggered by a key comb, with some sane defaults.

I think that the event handler onKeyPress should be able to do this conceptually. But, I had issues with interacting with my shell directly so I get the impression it’s a forked process and isn’t apart of my shell instance since I can send commands like touch: foo and the file is created but if I do out: “bar” I don’t get any output on stdout.

I didn’t open an issue for it yet as I hadn’t really looked into it further and I might be holding it all wrong.

https://murex.rocks/docs/commands/event.html

from murex.

lmorg avatar lmorg commented on June 13, 2024

@distek I could certainly do this, though it would mean those keys wouldn't be available for any other invocations of readline (eg via read builtin). The onKeyPress event was originally intended to be for the REPL shell and overrode any hotkeys in readline.

That's not to say that this behaviour couldn't be changed. It's just something for us to consider first

@J-C-3 onKeyPress expects stdout to be an object (eg JSON map). None of this is documented anywhere though, so I can't blame you getting stuck on this. I don't think there's even support for writing to the terminal. I could probably do with rewriting the whole API as it's pretty horrible. Maybe pipe stdout to the terminal like people would expect but have special functions available via a named pipe?

from murex.

distek avatar distek commented on June 13, 2024

Could there be a section of the config specially for the readline library? That way read could also take advantage of the key mappings (assuming read's readline is just using the same code, I can't seem to find it at the moment). Then it could be implemented kinda like:

func (rl *Instance) Readline() (_ string, err error) {
...
		if f, ok := ctrlCharMap[b[0]]; ok {
			f(rl)
		} else {
			switch b[0] {
			case charTab:
				if rl.modeTabCompletion {
					rl.moveTabCompletionHighlight(1, 0)
				} else {
					rl.getTabCompletion()
				}
...

Where the ctrlCharMap is set in the config, keeping defaults if not assigned by the user

Edit: Updated to match what you just pushed

from murex.

distek avatar distek commented on June 13, 2024

Put aside all of what I'm going on about right now. If I have some time I'll cut a PR for this after 4.2's out if you're open to the idea.

from murex.

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.