]> git.sesse.net Git - vlc/blob - plugins/text/ncurses.c
* ./BUGS: added a list of known bugs. Please add your findings!
[vlc] / plugins / text / ncurses.c
1 /*****************************************************************************
2  * ncurses.c : NCurses plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  * $Id: ncurses.c,v 1.10 2002/01/04 14:01:34 sam Exp $
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *      
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  * 
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28 #include <string.h>
29 #include <errno.h>                                                 /* ENOMEM */
30 #include <stdio.h>
31
32 #include <curses.h>
33
34 #include <videolan/vlc.h>
35
36 #include "stream_control.h"
37 #include "input_ext-intf.h"
38
39 #include "interface.h"
40
41 /*****************************************************************************
42  * Local prototypes.
43  *****************************************************************************/
44 static void intf_getfunctions ( function_list_t * p_function_list );
45 static int  intf_Probe        ( probedata_t *p_data );
46 static int  intf_Open         ( intf_thread_t *p_intf );
47 static void intf_Close        ( intf_thread_t *p_intf );
48 static void intf_Run          ( intf_thread_t *p_intf );
49
50 /*****************************************************************************
51  * Building configuration tree
52  *****************************************************************************/
53 MODULE_CONFIG_START
54 ADD_WINDOW( "Configuration for NCurses module" )
55     ADD_COMMENT( "For now, the NCurses module cannot be configured" )
56 MODULE_CONFIG_STOP
57
58 MODULE_INIT_START
59     p_module->i_capabilities = MODULE_CAPABILITY_NULL
60                                 | MODULE_CAPABILITY_INTF;
61     p_module->psz_longname = "ncurses interface module";
62     ADD_SHORTCUT( "ncurses" )
63 MODULE_INIT_STOP
64
65 MODULE_ACTIVATE_START
66     intf_getfunctions( &p_module->p_functions->intf );
67 MODULE_ACTIVATE_STOP
68
69 MODULE_DEACTIVATE_START
70 MODULE_DEACTIVATE_STOP
71
72 /*****************************************************************************
73  * intf_sys_t: description and status of ncurses interface
74  *****************************************************************************/
75 typedef struct intf_sys_s
76 {
77     /* special actions */
78     vlc_mutex_t         change_lock;                      /* the change lock */
79
80 } intf_sys_t;
81
82 /*****************************************************************************
83  * Functions exported as capabilities. They are declared as static so that
84  * we don't pollute the namespace too much.
85  *****************************************************************************/
86 static void intf_getfunctions( function_list_t * p_function_list )
87 {
88     p_function_list->pf_probe = intf_Probe;
89     p_function_list->functions.intf.pf_open  = intf_Open;
90     p_function_list->functions.intf.pf_close = intf_Close;
91     p_function_list->functions.intf.pf_run   = intf_Run;
92 }
93
94 /*****************************************************************************
95  * intf_Probe: probe the interface and return a score
96  *****************************************************************************
97  * This function tries to initialize ncurses and returns a score to the
98  * plugin manager so that it can select the best plugin.
99  *****************************************************************************/
100 static int intf_Probe( probedata_t *p_data )
101 {
102     return( 40 );
103 }
104
105 /*****************************************************************************
106  * intf_Open: initialize and create window
107  *****************************************************************************/
108 static int intf_Open( intf_thread_t *p_intf )
109 {
110     /* Allocate instance and initialize some members */
111     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
112     if( p_intf->p_sys == NULL )
113     {
114         intf_ErrMsg( "intf error: %s", strerror(ENOMEM) );
115         return( 1 );
116     }
117
118     /* Initialize the curses library */
119     initscr();
120     /* Don't do NL -> CR/NL */
121     nonl();
122     /* Take input chars one at a time */
123     cbreak();
124     /* Don't echo */
125     noecho();
126
127     curs_set(0);
128     timeout(0);
129
130     return( 0 );
131 }
132
133 /*****************************************************************************
134  * intf_Close: destroy interface window
135  *****************************************************************************/
136 static void intf_Close( intf_thread_t *p_intf )
137 {
138     /* Close the ncurses interface */
139     endwin();
140
141     /* Destroy structure */
142     free( p_intf->p_sys );
143 }
144
145 /*****************************************************************************
146  * intf_Run: ncurses thread
147  *****************************************************************************/
148 static void intf_Run( intf_thread_t *p_intf )
149 {
150     signed char i_key;
151
152     while( !p_intf->b_die )
153     {
154         p_intf->pf_manage( p_intf );
155
156         msleep( INTF_IDLE_SLEEP );
157
158         mvaddstr( 1, 2, VOUT_TITLE " (ncurses interface)" );
159         mvaddstr( 3, 2, "keys:" );
160         mvaddstr( 4, 2, "Q,q.......quit" );
161         //mvaddstr( 5, 2, "No other keys are active yet." );
162
163         while( (i_key = getch()) != -1 )
164         {
165             switch( i_key )
166             {
167                 case 'q':
168                 case 'Q':
169                     p_intf->b_die = 1;
170                     break;
171
172                 default:
173                     break;
174             }
175         }
176     }
177 }
178
179 /* following functions are local */
180