1. graphics.e on Linux

I have been experimenting with the position(line,column) procedure and get_position() function from the graphics.e include file for Linux running in a terminal window.

It appears from my tests that get_position() returns a line and column that is based on the line where the cursor was located when the program calling the function began. The position(line,column) procedure seems to locate the cursor at the beginning of the terminal window as I expected.

Is this the intended results of get_position()? If so, is there a way to determine the actual line within the terminal window based on the current position of the cursor?

I have seen other applications using position() and get_position that seem to work, but these seem to define an area of the screen for their use and don't depend on where the cursor is in the terminal window.

I'm probably just missing something simple again. The code for my simple (not very elegant) test case is below. Again this is run in a terminal window on Linux (Ubuntu 9.0.4)) which uses a Gnome desktop. I open a terminal window and run eui pos_test. Then (without closing and restarting the terminal window) I run eui pos_test again. Both times get_position reports the same line and column numbers, even though on the second call it appears the line number should not be the same. The text written after calling position() is written in the same place each time.

I would appreciate any help anyone can provide on this.

Thanks!

George

My code in a file pos_test is

-- test position and get_position 
 
include graphics.e 
 
sequence pos 
integer line, col 
 
puts(1,"\n\n\n\n****") 
pos = get_position() 
line = pos[1] 
col = pos[2] 
 
print(1,pos) 
 
position(line,col) 
 
puts(1,"**********\n\n\n\n") 
 
new topic     » topic index » view message » categorize

2. Re: graphics.e on Linux

-- don't you want to use a different print here. 
-- like printf(1,"%d",{pod}) 
print(1,pos)  
new topic     » goto parent     » topic index » view message » categorize

3. Re: graphics.e on Linux

georgeorr said...

I have been experimenting with the position(line,column) procedure and get_position() function from the graphics.e include file for Linux running in a terminal window.

It appears from my tests that get_position() returns a line and column that is based on the line where the cursor was located when the program calling the function began. The position(line,column) procedure seems to locate the cursor at the beginning of the terminal window as I expected.

Is this the intended results of get_position()? If so, is there a way to determine the actual line within the terminal window based on the current position of the cursor?

I have seen other applications using position() and get_position that seem to work, but these seem to define an area of the screen for their use and don't depend on where the cursor is in the terminal window.

I'm probably just missing something simple again. The code for my simple (not very elegant) test case is below. Again this is run in a terminal window on Linux (Ubuntu 9.0.4)) which uses a Gnome desktop. I open a terminal window and run eui pos_test. Then (without closing and restarting the terminal window) I run eui pos_test again. Both times get_position reports the same line and column numbers, even though on the second call it appears the line number should not be the same. The text written after calling position() is written in the same place each time.

I would appreciate any help anyone can provide on this.

Thanks!

George

My code in a file pos_test is

-- test position and get_position 
 
include graphics.e 
 
sequence pos 
integer line, col 
 
puts(1,"\n\n\n\n****") 
pos = get_position() 
line = pos[1] 
col = pos[2] 
 
print(1,pos) 
 
position(line,col) 
 
puts(1,"**********\n\n\n\n") 
 

Hi

If you ran

-- test position and get_position 
 
include graphics.e 
 
sequence pos 
integer line, col 
 
position(1,1) 
 
puts(1,"\n\n\n\n****") 
pos = get_position() 
line = pos[1] 
col = pos[2] 
 
print(1,pos) 
 
position(line,col) 
 
puts(1,"**********\n\n\n\n") 
 

What would happen? The point being, you shouldn't rely on the interpreter to always return the correct cursor position, until after you've initially set it.

Chris

new topic     » goto parent     » topic index » view message » categorize

4. Re: graphics.e on Linux

Chris -

What you suggest certainly makes the program repeat the same actions, but doesn't get at my problem. I was looking at trying to do some simple in-line editing of a line entered (at various lines in the terminal/command window) during execution of a command line program. This is pretty straight forward if I define a fixed input area relative to the top of the terminal/command window, using something like you suggest. But I don't know how to find out where the cursor is in the terminal/command window in order to do this more flexibly. The documentation for get_position() seems to say it will do this for me, but it doesn't work on Linux (at least the way I was using it). Looking at the code in graphics.e this position is returned by machine_func(M_GET_POSITION, 0), so it doesn't seem to depend on my defining the cursor position beforehand. I guess I was trying to ask if anyone knew how to get the current cursor position in the general case.

Thanks for the input!

George

ChrisB said...
georgeorr said...

I have been experimenting with the position(line,column) procedure and get_position() function from the graphics.e include file for Linux running in a terminal window.

It appears from my tests that get_position() returns a line and column that is based on the line where the cursor was located when the program calling the function began. The position(line,column) procedure seems to locate the cursor at the beginning of the terminal window as I expected.

Is this the intended results of get_position()? If so, is there a way to determine the actual line within the terminal window based on the current position of the cursor?

I have seen other applications using position() and get_position that seem to work, but these seem to define an area of the screen for their use and don't depend on where the cursor is in the terminal window.

I'm probably just missing something simple again. The code for my simple (not very elegant) test case is below. Again this is run in a terminal window on Linux (Ubuntu 9.0.4)) which uses a Gnome desktop. I open a terminal window and run eui pos_test. Then (without closing and restarting the terminal window) I run eui pos_test again. Both times get_position reports the same line and column numbers, even though on the second call it appears the line number should not be the same. The text written after calling position() is written in the same place each time.

I would appreciate any help anyone can provide on this.

Thanks!

George

My code in a file pos_test is

-- test position and get_position 
 
include graphics.e 
 
sequence pos 
integer line, col 
 
puts(1,"\n\n\n\n****") 
pos = get_position() 
line = pos[1] 
col = pos[2] 
 
print(1,pos) 
 
position(line,col) 
 
puts(1,"**********\n\n\n\n") 
 

Hi

If you ran

-- test position and get_position 
 
include graphics.e 
 
sequence pos 
integer line, col 
 
position(1,1) 
 
puts(1,"\n\n\n\n****") 
pos = get_position() 
line = pos[1] 
col = pos[2] 
 
print(1,pos) 
 
position(line,col) 
 
puts(1,"**********\n\n\n\n") 
 

What would happen? The point being, you shouldn't rely on the interpreter to always return the correct cursor position, until after you've initially set it.

Chris

new topic     » goto parent     » topic index » view message » categorize

5. Re: graphics.e on Linux

Hi

After a little experimentation, this would seem to be the case - you can't know the position of the cursor, until after you have called position(). As far as I can tell, this is because there's no way of getting the cursor position from bash, or passing it to an application.

include graphics.e  
  
sequence pos  
integer line, col  
 
pos = get_position()  --doesn't matter where you start, always returns 1,1 
line = pos[1]  
col = pos[2]  
printf(1,"%d,%d\n",{line, col}) 
 
position(15,15) 
puts(1,"***\n-------------------------------->") --returns the real cursor position 
pos = get_position() 
line = pos[1]  
col = pos[2]  
printf(1,"%d,%d\n",{line, col}) 
 

I tried with a (highly experimental and undeveloped) ncurses lib, but you have to open a new 'screen' with that, and kind of defeats the object. There are ways of returning to and from 'cooked' mode with curses, but again I'm not sure how to get the cursor position from the stdscr.

Why don't you just put a box in the middle of the screen, and edit in there?

Chris

new topic     » goto parent     » topic index » view message » categorize

6. Re: graphics.e on Linux

Chris -

I feel a little better that you found this difficult also! I have actually wrapped the GNU readline function for my application, but this seems like overkill. I can wrap the readline history routines also, so there is good in this. I was just hoping to be able to avoid platform specific routines and third party libraries. But if I can't,

Thanks for your insight. The helpfulness of others has always seemed a strength of this forum to me.

George

ChrisB said...

Hi

After a little experimentation, this would seem to be the case - you can't know the position of the cursor, until after you have called position(). As far as I can tell, this is because there's no way of getting the cursor position from bash, or passing it to an application.

include graphics.e  
  
sequence pos  
integer line, col  
 
pos = get_position()  --doesn't matter where you start, always returns 1,1 
line = pos[1]  
col = pos[2]  
printf(1,"%d,%d\n",{line, col}) 
 
position(15,15) 
puts(1,"***\n-------------------------------->") --returns the real cursor position 
pos = get_position() 
line = pos[1]  
col = pos[2]  
printf(1,"%d,%d\n",{line, col}) 
 

I tried with a (highly experimental and undeveloped) ncurses lib, but you have to open a new 'screen' with that, and kind of defeats the object. There are ways of returning to and from 'cooked' mode with curses, but again I'm not sure how to get the cursor position from the stdscr.

Why don't you just put a box in the middle of the screen, and edit in there?

Chris

new topic     » goto parent     » topic index » view message » categorize

7. Re: graphics.e on Linux

IMHO this is a bug in the Unix console code of Euphoria. It should be possible to do this, in fact there is a working example at http://unixwiz.net/techtips/wsize.c (which should be integrated into Euphoria).

georgeorr said...

I have been experimenting with the position(line,column) procedure and get_position() function from the graphics.e include file for Linux running in a terminal window.

It appears from my tests that get_position() returns a line and column that is based on the line where the cursor was located when the program calling the function began. The position(line,column) procedure seems to locate the cursor at the beginning of the terminal window as I expected.

Is this the intended results of get_position()? If so, is there a way to determine the actual line within the terminal window based on the current position of the cursor?

I have seen other applications using position() and get_position that seem to work, but these seem to define an area of the screen for their use and don't depend on where the cursor is in the terminal window.

I'm probably just missing something simple again. The code for my simple (not very elegant) test case is below. Again this is run in a terminal window on Linux (Ubuntu 9.0.4)) which uses a Gnome desktop. I open a terminal window and run eui pos_test. Then (without closing and restarting the terminal window) I run eui pos_test again. Both times get_position reports the same line and column numbers, even though on the second call it appears the line number should not be the same. The text written after calling position() is written in the same place each time.

I would appreciate any help anyone can provide on this.

Thanks!

George

My code in a file pos_test is

-- test position and get_position 
 
include graphics.e 
 
sequence pos 
integer line, col 
 
puts(1,"\n\n\n\n****") 
pos = get_position() 
line = pos[1] 
col = pos[2] 
 
print(1,pos) 
 
position(line,col) 
 
puts(1,"**********\n\n\n\n") 
 
new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu