Code Monkey home page Code Monkey logo

Comments (4)

hanslub42 avatar hanslub42 commented on August 24, 2024

There has been some discussion on bug-readline, about doing this for readine itself, where the conclusion was that this is not so simple. rlwraps hotkey is very similar, however: CTRL+R could be bound to rlwrap-hotkey, where the hotkey handler could do something along the lines of your example.

Problem: in bash, the hotkey handler is a shell function that can "see" everything because it runs in the same process as the shell itself. A filter is a separate, lonely process that can not look into rlwrap nor the rlwrapped command. cloak_and_dagger() can pry some information from the latter, but rlwrap itself is a black box.

A possible solution would be to send as much information as possible in a HOTKEY message: not only the current input line, but e.g. also the current history. The handler would have to be something like this

$filter -> hotkey_handler(sub {
   my($key, $input_line, $cursor_position, $history, $history_position, ....) = @_
   if ($key == control('R')) {
         my ($new_line, $new_cursorpos) = use_peco_to_get_a_line($history);
         return("", $new_line, $new_cursorpos, $history, $history_position,....);
   }
}

This would subsume the current rlwrap-edit-history function as well, and thus get rid of some code (at the expense of a slightly more complex hotkey handler)

If sending the complete history for every hotkey keystroke is a bit too much, I could also implement a rlwrap-hotkey-without-history function, for those hotkeys that don't need the complete history

from rlwrap.

hanslub42 avatar hanslub42 commented on August 24, 2024

I worked this out in branch hash_history, and this looks quite promising. History edit is now done in a few lines of perl (or python), and the existing --multi-line support could also easily be subsumed under rlwrap-hotkey. I cannot easily try peco on my linux machine, but I don't see why this wouldn't be straightforward as well.

One little twist should/will be added to the hotkey handler: if the returned input line ends with a newline, immediately accept the result, otherwise keep editing. So, if (and only if) we e.g. put two empty lines before a history line (or e.g. end a multi-line edit with a '!') accept the result

from rlwrap.

hokuda avatar hokuda commented on August 24, 2024

Thanks a lot for the great work! That is what I really want! I added peco handler to the handle_hotkeys script and it works fine! Please review my pull request which has a peco handler and a minor bug fix.

from rlwrap.

hanslub42 avatar hanslub42 commented on August 24, 2024

All merged and done. Closing.

from rlwrap.

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.