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