You are not logged in.

#1 2017-08-23 11:46:05

olly
Member
From: South West England
Registered: 2017-08-22
Posts: 38

[SOLVED] readline (by read -e)

Hi arch people

I posted this in newbie, which I think was the wrong place, so I've move it here.


Maybe you can help with a problem I can't seem to solve. I use read -e to invoke readline to use both bind esc cursor control and fill buffer (-i). Do this at start of line and read and realine function as expected. Cursor to middle of screen, and read works fine. Use readline, enter backspace, no problem. But, middle of screen use readline, type 123, bacspace twice and it does what expected, bacspace on last character and the cursor goes to start of line, as in cursor return, not backspace. Only does this if characters are entered, if just backspace the cursor stays put. I know there are issues with ^H and so on, but I don't think that's it. Any advice gratefully received.

To test in script

echo -ne "\033[5;20H"
read -e text

Thanks

Last edited by olly (2018-06-26 18:57:23)


Bullies are only weak people trying to compensate for their own inadequacy. If they can't compete intellectually, they bully.

Offline

#2 2017-08-23 12:38:31

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 11,787
Website

Re: [SOLVED] readline (by read -e)

I posted this in newbie, which I think was the wrong place, so I've move it here.

In the future, please do not do this. Use the report button instead to contact the mod team and request a move. I'll close and bin the other topic.


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Online

#3 2017-08-23 13:28:06

olly
Member
From: South West England
Registered: 2017-08-22
Posts: 38

Re: [SOLVED] readline (by read -e)

Sorry. I'm new.

Is this duplicated by anyone, or is it perculiar to my system?


Anyone?

Last edited by olly (2017-08-26 10:51:59)


Bullies are only weak people trying to compensate for their own inadequacy. If they can't compete intellectually, they bully.

Offline

#4 2018-06-19 16:20:27

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,447
Website

Re: [SOLVED] readline (by read -e)

I can confirm the symptoms.  It's not just backspace, but any readline command to move to the start of the line moves to position 0 rather than position 20.  I suspect this is due to readline controlling the full line.  If you want text before the input, use a readline prompt.  To acheive the apparent intent of your sample code:

#!/bin/bash

echo -ne "\033[5;0H"
read -e -p "                    " text

EDIT: this seems to work too:

read -e -p "$(printf '\033[5;20H')" text

Last edited by Trilby (2018-06-19 16:38:20)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2018-06-26 18:28:12

olly
Member
From: South West England
Registered: 2017-08-22
Posts: 38

Re: [SOLVED] readline (by read -e)

Very interesting......

What I'm trying to do is edit text under column headings. So, I move the cursor to column 20, and do something like

 read -e -i "text-to-edit"  

which works fine unless you backspace on the first character. I think readline dates back to primitive console types. As well as a read command,  an edit command would be useful. While your suggestion allows input beyond a prompt without the problem, it does not edit.

UNLESS

If you combine both.....

 read -e -p " "  -i "text-to-edit"  text

It works !  It needs the space in the prompt to work, probably makes it interpret it as start of line, but hay ho!

Thanks for that.

Last edited by olly (2018-09-26 15:40:16)


Bullies are only weak people trying to compensate for their own inadequacy. If they can't compete intellectually, they bully.

Offline

Board footer

Powered by FluxBB