]> git.sesse.net Git - vlc/blob - plugins/text/ncurses.c
* ALL: internationalized all configuration strings.
[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.14 2002/04/19 13:56:11 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_Open         ( intf_thread_t *p_intf );
46 static void intf_Close        ( intf_thread_t *p_intf );
47 static void intf_Run          ( intf_thread_t *p_intf );
48
49 /*****************************************************************************
50  * Building configuration tree
51  *****************************************************************************/
52 MODULE_CONFIG_START
53 MODULE_CONFIG_STOP
54
55 MODULE_INIT_START
56     SET_DESCRIPTION( _("ncurses interface module") )
57     ADD_CAPABILITY( INTF, 10 )
58     ADD_SHORTCUT( "curses" )
59     ADD_SHORTCUT( "ncurses" )
60 MODULE_INIT_STOP
61
62 MODULE_ACTIVATE_START
63     intf_getfunctions( &p_module->p_functions->intf );
64 MODULE_ACTIVATE_STOP
65
66 MODULE_DEACTIVATE_START
67 MODULE_DEACTIVATE_STOP
68
69 /*****************************************************************************
70  * intf_sys_t: description and status of ncurses interface
71  *****************************************************************************/
72 typedef struct intf_sys_s
73 {
74     /* special actions */
75     vlc_mutex_t         change_lock;                      /* the change lock */
76
77 } intf_sys_t;
78
79 /*****************************************************************************
80  * Functions exported as capabilities. They are declared as static so that
81  * we don't pollute the namespace too much.
82  *****************************************************************************/
83 static void intf_getfunctions( function_list_t * p_function_list )
84 {
85     p_function_list->functions.intf.pf_open  = intf_Open;
86     p_function_list->functions.intf.pf_close = intf_Close;
87     p_function_list->functions.intf.pf_run   = intf_Run;
88 }
89
90 /*****************************************************************************
91  * intf_Open: initialize and create window
92  *****************************************************************************/
93 static int intf_Open( intf_thread_t *p_intf )
94 {
95     /* Allocate instance and initialize some members */
96     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
97     if( p_intf->p_sys == NULL )
98     {
99         intf_ErrMsg( "intf error: %s", strerror(ENOMEM) );
100         return( 1 );
101     }
102
103     /* Initialize the curses library */
104     initscr();
105     /* Don't do NL -> CR/NL */
106     nonl();
107     /* Take input chars one at a time */
108     cbreak();
109     /* Don't echo */
110     noecho();
111
112     curs_set(0);
113     timeout(0);
114
115     return( 0 );
116 }
117
118 /*****************************************************************************
119  * intf_Close: destroy interface window
120  *****************************************************************************/
121 static void intf_Close( intf_thread_t *p_intf )
122 {
123     /* Close the ncurses interface */
124     endwin();
125
126     /* Destroy structure */
127     free( p_intf->p_sys );
128 }
129
130 /*****************************************************************************
131  * intf_Run: ncurses thread
132  *****************************************************************************/
133 static void intf_Run( intf_thread_t *p_intf )
134 {
135     signed char i_key;
136
137     while( !p_intf->b_die )
138     {
139         p_intf->pf_manage( p_intf );
140
141         msleep( INTF_IDLE_SLEEP );
142
143         mvaddstr( 1, 2, VOUT_TITLE " (ncurses interface)" );
144         mvaddstr( 3, 2, "keys:" );
145         mvaddstr( 4, 2, "Q,q.......quit" );
146         //mvaddstr( 5, 2, "No other keys are active yet." );
147
148         while( (i_key = getch()) != -1 )
149         {
150             switch( i_key )
151             {
152                 case 'q':
153                 case 'Q':
154                     p_intf->b_die = 1;
155                     break;
156
157                 default:
158                     break;
159             }
160         }
161     }
162 }
163
164 /* following functions are local */
165