Stty raw mode


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Stty raw mode
# 1  
Old 04-12-2019
Stty raw mode

Hi,


I'm writing a BBS terminal program. And have hit a major roadblock. My terminal works fine for every BBS out there, except Mystic BBSes. I've narrowed down the problem to the usage of the stty() command. The problem is so: I cannot use the arrow keys to select certain things on Mystic BBSes. It doesn't seem to be sending the ^[[A, ^[[B, etc ANSI codes to the screen. Here's the strange part, If I press the arrow key multiple times, it will do what it's supposed to do, and traverse the menus. Now, back to stty(), I wrote another program, this time, in Python, and had this exact problem with it. I solved it by putting a
Code:
os.system("stty raw");

before the command to connect to the BBS. Now back to the problem, I have no idea where I should put this system() call. Trial and error hasn't helped much.


Any and all input is greatly appreciated. And a big THANK YOU to everyone who has helped me get this far. You know who you are.
# 2  
Old 04-12-2019
Using stty raw is only half of the problem. When the BBS software exits, you need to restore the stty settings to what they were before you went into raw mode before returning to your user.

If you ever get stuck because a program exited while in raw mode, you can get back to a semi-sane setting by using:
Code:
CTL-J CTL-J stty sane CTL-J
stty -a

where CTL-J means hold down the CTL or control key on your keyboard and while you are holding it down hit and release the J key (and then you can release the control key). After you have entered the first line of that, hopefully you will be back in a sane cooked state, but there is a good chance that the erase and kill characters that you are used to using have not been reset to the values you expect. The stty -a output will tell you what stty sane set up for you.

It would be a good idea to run stty -a and look at the stty man page on your system so you can understand what the output you see from stty -a means. The stty utility is covered by the standards, but the output format varies from operating system to operating system.

You haven't said what language you're using for this project. If you were writing standard shell code to invoke your Mystic BBS software and we make the wild assumption that you do so by invoking a utility named mystic, you would want something like:
Code:
settings=$(stty -g) # save current user's TTY settings
echo "Getting ready to invoke mystic..."
stty raw
mystic # be sure to include whatever options you need to pass to mystic
ec=$? # save exit code from mystic
stty $settings # restore original stty settings
echo "Back from mystic...  TTY settings have been restored."
exit $ec

Hope this helps.

Last edited by Don Cragun; 04-12-2019 at 11:05 PM.. Reason: Fix suggestion...
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 04-12-2019
Thank you for that, sir. I'm actually using C for this project.
# 4  
Old 04-12-2019
If you're using C instead of shell code, look at the man pages for the tcgetattr() and tcsetattr() functions on your system. Those functions (and others you will find in their SEE ALSO sections or on the same pages) are used by the stty utility to get its job done.
# 5  
Old 04-12-2019
Also, I may not have mentioned it. But this is actually a terminal program for connecting to other BBSes.. The solution I posted was a solution for the Python project. I still can't get things working with the C version. Sorry, I did not make myself clear enough on that.


Thanks.

--- Post updated at 02:25 AM ---

Quote:
Originally Posted by Don Cragun
If you're using C instead of shell code, look at the man pages for the tcgetattr() and tcsetattr() functions on your system. Those functions (and others you will find in their SEE ALSO sections or on the same pages) are used by the stty utility to get its job done.

Ok. Will do. Thank you much.
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. HP-UX

From a C++ application how to find if a hpux host is in standard mode or trusted mode

is there a way for my C++ application to find out which mode the hpux OS is running in? standard mode or trusted mode. (3 Replies)
Discussion started by: einsteinBrain
3 Replies

2. Solaris

DNS service is in maintenance mode. How to bring it back to online mode?

:confused: when i tried to look the status of DNS-client, it is in maintenance mode..... Please tell me how to bring it back to online mode...PLEASE TELL ME STEP BY STEP.... PLEASE... :wall: (2 Replies)
Discussion started by: vamshigvk475
2 Replies

3. Shell Programming and Scripting

How to use stty?

Hi , I have shell scripting in linux box. This script is mentioned that should be run under the one particular user. If you run that mentioned user location then it is working fine.... Suppose if you are trying run from some other user like as mentioned below sudo su - gxadm -c script.sh ... (1 Reply)
Discussion started by: Mani_apr08
1 Replies

4. UNIX for Advanced & Expert Users

What is the difference between single line mode and multiline mode in Regular expressions?

Hi All, Can please let me know what is the difference between the single line mode and multi line mode in regular expresions? Thanks, Chidhambaram B (3 Replies)
Discussion started by: chidhu.anu
3 Replies

5. OS X (Apple)

Using stty

Hello, I am trying to configure a serial port, for mac os x 10.6. I believe I can use the stty command to look at serial port configuration and or change the serial port settings. I read the man page, but I don't really know what I am doing. Any help? (0 Replies)
Discussion started by: jamesapp
0 Replies

6. SuSE

Convet Linux OS from text mode to graphic mode

Hi All, I used to have my suse linux(VM) server in graphic mode but not anymore since morning. I cant rolback since i loose somuch work. Any idea how to it back to normal. Thanks (6 Replies)
Discussion started by: s_linux
6 Replies

7. UNIX for Dummies Questions & Answers

stty

I am trying to set my backspace key as the erase key right now I have to type CONTROL-H to delete. Can you please tell me the command to set my backspace as the erase key...... (1 Reply)
Discussion started by: frank
1 Replies
Login or Register to Ask a Question