String Search In Scrollback

I'm writing some functinoality into xterm to be able to do substring searches in the scrollback. I did it like this:

You echo to the tty:

esc]5;string^G

and it'll scroll you back to the first place where string occurs.

If you leave out the string in that esc seq, it'll start at last search location and it'll use last search string. This all works, except there is a race condition. When you echo, or run a shell script that echos, it will spit out the esc seq, which causes xterm to scroll back, and then the script/echo exits and it prints a new prompt from your shell. That printing causes the xterm to scroll back down to the bottom due to tty output occuring. This option can be turned off.. but most people, including me, like it on.

I found a better solution for the 'search next' case. I can create an xterm action, and then you can bind a key to the action. The action does 'search next' and so you can just hit key, and no script/echo needs to be run, thus no printing of prompt, thus no scorlling back, thus you stay where the search string was found.

That only works with search-next tho, since I already have the string to search for in mem (thats why i can do it as a static action). I dont know of a way to get that original string into xterm's mem tho.

I first thought about using selection. So you select something, then search back on that, however, that sucks since yer overloading the purpose of selection, and no X person is going to go for that. Then I moved to esc seq method.

I was thinking about this: 4 esc sequences: 'load buffer', 'reset pos', 'search forward', 'search backward', then using the interpert action, you can bind keys to all of the esc sequences. all but the first actually, since you still don't have a way to get the search string into xterm.

Load buffer could be done by a shell script, and it wouldn't actually search anything, it'd just move the scroll back.

Then you use the keys to scroll. The nice thing about this method is you can actually then just bind a new key to run a shell script which will grab x selection (using xprop or xcb), and search on that.

The annoying thing about this is that you first have to run a shell script then hit the search keys. At least the shell script could reset the position for you.

Time passed...

So I implemented the last thing I discussed.. 4 different esc seqs:

esc]5;0string^G - Load String
esc]5;1^G - Reset Position
esc]5;2^G - Find Up
esc]5;3^G - Find Down

This works well, but its annoying since you need to have a shell script to spit out the first two sequences.

Any suggestions to solving this problem would be great.

I think the best solution is to pop up a little window that takes input, and that is yer search string. It can be a transient window and with FVWM 2.3.2, you can automaticly focus transients, making this much easier to use.

The patch.

Back.