66
77#include <termios.h>
88
9+ static char termios__doc__ [] = "\
10+ This module provides an interface to the Posix calls for tty I/O control.\n\
11+ For a complete description of these calls, see the Posix or Unix manual\n\
12+ pages. It is only available for those Unix versions that support Posix\n\
13+ termios style tty I/O control (and then only if configured at installation\n\
14+ time).\n\
15+ \n\
16+ All functions in this module take a file descriptor fd as their first\n\
17+ argument. This must be an integer file descriptor, such as returned by\n\
18+ sys.stdin.fileno().\n\
19+ \n\
20+ This module should be used in conjunction with the TERMIOS module,\n\
21+ which defines the relevant symbolic constants." ;
22+
23+
924#define BAD "bad termios argument"
1025
1126static PyObject * TermiosError ;
@@ -16,6 +31,16 @@ static PyObject *TermiosError;
1631
1732 Return the attributes of the terminal device. */
1833
34+ static char termios_tcgetattr__doc__ [] = "\
35+ tcgetattr(fd) -> list_of_attrs\n\
36+ Get the tty attributes for file descriptor fd, as follows:\n\
37+ [iflag, oflag, cflag, lflag, ispeed, ospeed, cc] where cc is a list\n\
38+ of the tty special characters (each a string of length 1, except the items\n\
39+ with indices VMIN and VTIME, which are integers when these fields are\n\
40+ defined). The interpretation of the flags and the speeds as well as the\n\
41+ indexing in the cc array must be done using the symbolic constants defined\n\
42+ in the TERMIOS module." ;
43+
1944static PyObject *
2045termios_tcgetattr (self , args )
2146 PyObject * self ;
@@ -86,6 +111,16 @@ termios_tcgetattr(self, args)
86111/* tcsetattr(fd, when, termios)
87112 Set the attributes of the terminal device. */
88113
114+ static char termios_tcsetattr__doc__ [] = "\
115+ tcsetattr(fd, when, attributes) -> None\n\
116+ Set the tty attributes for file descriptor fd.\n\
117+ The attributes to be set are taken from the attributes argument, which\n\
118+ is a list like the one returned by tcgetattr(). The when argument\n\
119+ determines when the attributes are changed: TERMIOS.TCSANOW to\n\
120+ change immediately, TERMIOS.TCSADRAIN to change after transmitting all\n\
121+ queued output, or TERMIOS.TCSAFLUSH to change after transmitting all\n\
122+ queued output and discarding all queued input. " ;
123+
89124static PyObject *
90125termios_tcsetattr (self , args )
91126 PyObject * self ;
@@ -146,6 +181,12 @@ termios_tcsetattr(self, args)
146181/* tcsendbreak(fd, duration)
147182 Generate a break condition. */
148183
184+ static char termios_tcsendbreak__doc__ [] = "\
185+ tcsendbreak(fd, duration) -> None\n\
186+ Send a break on file descriptor fd.\n\
187+ A zero duration sends a break for 0.25-0.5 seconds; a nonzero duration \n\
188+ has a system dependent meaning. " ;
189+
149190static PyObject *
150191termios_tcsendbreak (self , args )
151192 PyObject * self ;
@@ -166,6 +207,10 @@ termios_tcsendbreak(self, args)
166207 Wait until all queued output to the terminal has been
167208 transmitted. */
168209
210+ static char termios_tcdrain__doc__ [] = "\
211+ tcdrain(fd) -> None\n\
212+ Wait until all output written to file descriptor fd has been transmitted. " ;
213+
169214static PyObject *
170215termios_tcdrain (self , args )
171216 PyObject * self ;
@@ -186,6 +231,13 @@ termios_tcdrain(self, args)
186231 Clear the input and/or output queues associated with
187232 the terminal. */
188233
234+ static char termios_tcflush__doc__ [] = "\
235+ tcflush(fd, queue) -> None\n\
236+ Discard queued data on file descriptor fd.\n\
237+ The queue selector specifies which queue: TERMIOS.TCIFLUSH for the input\n\
238+ queue, TERMIOS.TCOFLUSH for the output queue, or TERMIOS.TCIOFLUSH for\n\
239+ both queues. " ;
240+
189241static PyObject *
190242termios_tcflush (self , args )
191243 PyObject * self ;
@@ -206,6 +258,13 @@ termios_tcflush(self, args)
206258 Perform operations relating to XON/XOFF flow control on
207259 the terminal. */
208260
261+ static char termios_tcflow__doc__ [] = "\
262+ tcflow(fd, action) -> None\n\
263+ Suspend or resume input or output on file descriptor fd.\n\
264+ The action argument can be TERMIOS.TCOOFF to suspend output,\n\
265+ TERMIOS.TCOON to restart output, TERMIOS.TCIOFF to suspend input,\n\
266+ or TERMIOS.TCION to restart input. " ;
267+
209268static PyObject *
210269termios_tcflow (self , args )
211270 PyObject * self ;
@@ -224,12 +283,12 @@ termios_tcflow(self, args)
224283
225284static PyMethodDef termios_methods [] =
226285{
227- {"tcgetattr" , termios_tcgetattr },
228- {"tcsetattr" , termios_tcsetattr },
229- {"tcsendbreak" , termios_tcsendbreak },
230- {"tcdrain" , termios_tcdrain },
231- {"tcflush" , termios_tcflush },
232- {"tcflow" , termios_tcflow },
286+ {"tcgetattr" , termios_tcgetattr , 0 , termios_tcgetattr__doc__ },
287+ {"tcsetattr" , termios_tcsetattr , 0 , termios_tcsetattr__doc__ },
288+ {"tcsendbreak" , termios_tcsendbreak , 0 , termios_tcsendbreak__doc__ },
289+ {"tcdrain" , termios_tcdrain , 0 , termios_tcdrain__doc__ },
290+ {"tcflush" , termios_tcflush , 0 , termios_tcflush__doc__ },
291+ {"tcflow" , termios_tcflow , 0 , termios_tcflow__doc__ },
233292 {NULL , NULL }
234293};
235294
@@ -238,7 +297,8 @@ PyInit_termios()
238297{
239298 PyObject * m , * d ;
240299
241- m = Py_InitModule ("termios" , termios_methods );
300+ m = Py_InitModule4 ("termios" , termios_methods , termios__doc__ ,
301+ (PyObject * )NULL , PYTHON_API_VERSION );
242302
243303 d = PyModule_GetDict (m );
244304 TermiosError = PyErr_NewException ("termios.error" , NULL , NULL );
0 commit comments