]> git.sesse.net Git - vlc/blob - plugins/text/intf_ncurses.c
* Ported Glide and MGA plugins to the new module API. MGA never worked,
[vlc] / plugins / text / intf_ncurses.c
1 /*****************************************************************************
2  * intf_ncurses.c: ncurses interface
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  *
6  * Authors: Samuel Hocevar <sam@zoy.org>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  * 
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
21  *****************************************************************************/
22
23 #define MODULE_NAME ncurses
24 #include "modules_inner.h"
25
26 /*****************************************************************************
27  * Preamble
28  *****************************************************************************/
29 #include "defs.h"
30
31 #include <errno.h>                                                 /* ENOMEM */
32 #include <stdlib.h>                                                /* free() */
33 #include <string.h>                                            /* strerror() */
34 #include <stdio.h>
35
36 #include <curses.h>
37
38 #include "config.h"
39 #include "common.h"
40 #include "threads.h"
41 #include "mtime.h"
42 #include "tests.h"
43 #include "modules.h"
44
45 #include "stream_control.h"
46 #include "input_ext-intf.h"
47
48 #include "intf_msg.h"
49 #include "interface.h"
50
51 #include "main.h"
52
53 /*****************************************************************************
54  * intf_sys_t: description and status of ncurses interface
55  *****************************************************************************/
56 typedef struct intf_sys_s
57 {
58     /* special actions */
59     vlc_mutex_t         change_lock;                      /* the change lock */
60
61 } intf_sys_t;
62
63 /*****************************************************************************
64  * Local prototypes.
65  *****************************************************************************/
66 static int  intf_Probe     ( probedata_t *p_data );
67 static int  intf_Open      ( intf_thread_t *p_intf );
68 static void intf_Close     ( intf_thread_t *p_intf );
69 static void intf_Run       ( intf_thread_t *p_intf );
70
71 /*****************************************************************************
72  * Functions exported as capabilities. They are declared as static so that
73  * we don't pollute the namespace too much.
74  *****************************************************************************/
75 void _M( intf_getfunctions )( function_list_t * p_function_list )
76 {
77     p_function_list->pf_probe = intf_Probe;
78     p_function_list->functions.intf.pf_open  = intf_Open;
79     p_function_list->functions.intf.pf_close = intf_Close;
80     p_function_list->functions.intf.pf_run   = intf_Run;
81 }
82
83 /*****************************************************************************
84  * intf_Probe: probe the interface and return a score
85  *****************************************************************************
86  * This function tries to initialize ncurses and returns a score to the
87  * plugin manager so that it can select the best plugin.
88  *****************************************************************************/
89 static int intf_Probe( probedata_t *p_data )
90 {
91     if( TestMethod( INTF_METHOD_VAR, "ncurses" ) )
92     {
93         return( 999 );
94     }
95
96     return( 40 );
97 }
98
99 /*****************************************************************************
100  * intf_Open: initialize and create window
101  *****************************************************************************/
102 static int intf_Open( intf_thread_t *p_intf )
103 {
104     /* Allocate instance and initialize some members */
105     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
106     if( p_intf->p_sys == NULL )
107     {
108         intf_ErrMsg("error: %s", strerror(ENOMEM));
109         return( 1 );
110     }
111
112     /* Initialize the curses library */
113     initscr();
114
115     /* Don't do NL -> CR/NL */
116     nonl();
117
118     /* Take input chars one at a time */
119     cbreak();
120
121     /* Don't echo */
122     noecho();
123
124     return( 0 );
125 }
126
127 /*****************************************************************************
128  * intf_Close: destroy interface window
129  *****************************************************************************/
130 static void intf_Close( intf_thread_t *p_intf )
131 {
132     /* Close the ncurses interface */
133     endwin();
134
135     /* Destroy structure */
136     free( p_intf->p_sys );
137 }
138
139 /*****************************************************************************
140  * intf_Run: ncurses thread
141  *****************************************************************************/
142 static void intf_Run( intf_thread_t *p_intf )
143 {
144     while( !p_intf->b_die )
145     {
146         p_intf->pf_manage( p_intf );
147
148         msleep( INTF_IDLE_SLEEP );
149     }
150 }
151
152 /* following functions are local */
153