]> git.sesse.net Git - vlc/blob - plugins/text/intf_ncurses.c
e243e833088b7e19262158cbc1fe96d1d7957109
[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 /*****************************************************************************
24  * Preamble
25  *****************************************************************************/
26 #include "defs.h"
27
28 #include <errno.h>                                                 /* ENOMEM */
29 #include <stdlib.h>                                                /* free() */
30 #include <string.h>                                            /* strerror() */
31 #include <stdio.h>
32
33 #include <curses.h>
34
35 #include "config.h"
36 #include "common.h"
37 #include "threads.h"
38 #include "mtime.h"
39 #include "tests.h"
40 #include "modules.h"
41
42 #include "stream_control.h"
43 #include "input_ext-intf.h"
44
45 #include "intf_msg.h"
46 #include "interface.h"
47
48 #include "main.h"
49
50 /*****************************************************************************
51  * intf_sys_t: description and status of ncurses interface
52  *****************************************************************************/
53 typedef struct intf_sys_s
54 {
55     /* special actions */
56     vlc_mutex_t         change_lock;                      /* the change lock */
57
58 } intf_sys_t;
59
60 /*****************************************************************************
61  * Local prototypes.
62  *****************************************************************************/
63 static int  intf_Probe     ( probedata_t *p_data );
64 static int  intf_Open      ( intf_thread_t *p_intf );
65 static void intf_Close     ( intf_thread_t *p_intf );
66 static void intf_Run       ( intf_thread_t *p_intf );
67
68 /*****************************************************************************
69  * Functions exported as capabilities. They are declared as static so that
70  * we don't pollute the namespace too much.
71  *****************************************************************************/
72 void intf_getfunctions( function_list_t * p_function_list )
73 {
74     p_function_list->pf_probe = intf_Probe;
75     p_function_list->functions.intf.pf_open  = intf_Open;
76     p_function_list->functions.intf.pf_close = intf_Close;
77     p_function_list->functions.intf.pf_run   = intf_Run;
78 }
79
80 /*****************************************************************************
81  * intf_Probe: probe the interface and return a score
82  *****************************************************************************
83  * This function tries to initialize ncurses and returns a score to the
84  * plugin manager so that it can select the best plugin.
85  *****************************************************************************/
86 static int intf_Probe( probedata_t *p_data )
87 {
88     if( TestMethod( INTF_METHOD_VAR, "ncurses" ) )
89     {
90         return( 999 );
91     }
92
93     return( 40 );
94 }
95
96 /*****************************************************************************
97  * intf_Open: initialize and create window
98  *****************************************************************************/
99 static int intf_Open( intf_thread_t *p_intf )
100 {
101     /* Allocate instance and initialize some members */
102     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
103     if( p_intf->p_sys == NULL )
104     {
105         intf_ErrMsg("error: %s", strerror(ENOMEM));
106         return( 1 );
107     }
108
109     /* Initialize the curses library */
110     initscr();
111
112     /* Don't do NL -> CR/NL */
113     nonl();
114
115     /* Take input chars one at a time */
116     cbreak();
117
118     /* Don't echo */
119     noecho();
120
121     return( 0 );
122 }
123
124 /*****************************************************************************
125  * intf_Close: destroy interface window
126  *****************************************************************************/
127 static void intf_Close( intf_thread_t *p_intf )
128 {
129     /* Close the ncurses interface */
130     endwin();
131
132     /* Destroy structure */
133     free( p_intf->p_sys );
134 }
135
136 /*****************************************************************************
137  * intf_Run: ncurses thread
138  *****************************************************************************/
139 static void intf_Run( intf_thread_t *p_intf )
140 {
141     while( !p_intf->b_die )
142     {
143         p_intf->pf_manage( p_intf );
144
145         msleep( INTF_IDLE_SLEEP );
146     }
147 }
148
149 /* following functions are local */
150