25 #include "YNCursesUI.h"
32 #include <yui/YEvent.h>
33 #include <yui/YDialog.h>
34 #include <yui/YCommandLine.h>
35 #include <yui/YButtonBox.h>
36 #include <yui/YMacro.h>
38 #define YUILogComponent "ncurses"
39 #include <yui/YUILog.h>
42 #include "NCWidgetFactory.h"
43 #include "NCOptionalWidgetFactory.h"
44 #include "NCPackageSelectorPluginStub.h"
46 extern std::string language2encoding( std::string lang );
51 YUI * createUI(
bool withThreads )
63 yuiMilestone() <<
"Start YNCursesUI" << std::endl;
66 if ( getenv(
"LANG" ) != NULL )
68 setlocale ( LC_CTYPE,
"" );
69 std::string language = getenv(
"LANG" );
70 std::string encoding = nl_langinfo( CODESET );
71 yuiMilestone() <<
"getenv LANG: " << language <<
" encoding: " << encoding << std::endl;
75 std::string locale = setlocale( LC_CTYPE, NULL );
76 setenv(
"LC_CTYPE", locale.c_str(), 1 );
77 yuiMilestone() <<
"setenv LC_CTYPE: " << locale <<
" encoding: " << encoding << std::endl;
81 NCstring::setTerminalEncoding( encoding );
82 app()->setLanguage( language, encoding );
85 YButtonBoxMargins buttonBoxMargins;
86 buttonBoxMargins.left = 1;
87 buttonBoxMargins.right = 1;
88 buttonBoxMargins.top = 1;
89 buttonBoxMargins.bottom = 0;
90 buttonBoxMargins.spacing = 1;
91 buttonBoxMargins.helpButtonExtraSpacing = 3;
92 YButtonBox::setDefaultMargins( buttonBoxMargins );
100 yuiMilestone() << err << std::endl;
105 topmostConstructorHasFinished();
112 YDialog::deleteAllDialogs();
113 yuiMilestone() <<
"Stop YNCursesUI" << std::endl;
121 YUI_CHECK_NEW( factory );
127 YOptionalWidgetFactory *
131 YUI_CHECK_NEW( factory );
138 YNCursesUI::createApplication()
141 YUI_CHECK_NEW( app );
163 FD_SET( fd_ycp, &fdset );
165 retval = select( fd_ycp + 1, &fdset, 0, 0, &tv );
169 if ( errno != EINTR )
170 yuiError() <<
"idleLoop error in select() (" << errno <<
')' << std::endl;
172 else if ( retval != 0 )
176 YDialog *currentDialog = YDialog::currentDialog(
false );
186 if ( NCBusyIndicatorObject )
187 NCBusyIndicatorObject->
handler( 0 );
194 while ( !FD_ISSET( fd_ycp, &fdset ) );
223 YDialog *dialog = YDialog::currentDialog();
228 yuiError() <<
"ERROR package selection: No dialog rexisting." << std::endl;
234 yuiError() <<
"ERROR package selection: No package selector existing." << std::endl;
239 dialog->dumpDialogWidgetTree();
250 void YNCursesUI::init_title()
253 YCommandLine cmdline;
259 std::string progName = YUILog::basename( cmdline[0] );
261 if ( progName ==
"y2base" )
271 if ( cmdline.size() > 1 )
272 progName +=
" - " + cmdline[1];
275 if ( progName.find(
"lt-" ) == 0 )
278 progName = progName.substr(
sizeof(
"lt-" ) - 1 );
286 std::string hostName;
288 char hostNameBuffer[ 256 ];
290 if ( gethostname( hostNameBuffer,
sizeof( hostNameBuffer ) - 1 ) != -1 )
296 hostNameBuffer[
sizeof( hostNameBuffer ) -1 ] =
'\0';
297 hostName = hostNameBuffer;
300 if ( hostName ==
"(none)" )
307 std::string windowTitle = progName;
309 if ( ! hostName.empty() )
310 windowTitle +=
" @ " + hostName;
312 NCurses::SetTitle( windowTitle );
316 bool YNCursesUI::want_colors()
318 if ( getenv(
"Y2NCURSES_BW" ) != NULL )
320 yuiMilestone() <<
"Y2NCURSES_BW is std::set - won't use colors" << std::endl;
338 const std::string & font,
339 const std::string & screen_map,
340 const std::string & unicode_map,
341 const std::string & lang )
343 std::string cmd(
"setfont" );
344 cmd +=
" -C " + myTerm;
347 if ( !screen_map.empty() )
348 cmd +=
" -m " + screen_map;
350 if ( !unicode_map.empty() )
351 cmd +=
" -u " + unicode_map;
353 yuiMilestone() << cmd << std::endl;
355 int ret = system(( cmd +
" >/dev/null 2>&1" ).c_str() );
360 yuiError() << cmd.c_str() <<
" returned " << ret << std::endl;
366 cmd =
"(echo -en \"\\033";
368 if ( console_magic.length() )
369 cmd += console_magic;
373 cmd +=
"\" >" + myTerm +
")";
375 yuiMilestone() << cmd << std::endl;
377 ret = system(( cmd +
" >/dev/null 2>&1" ).c_str() );
381 yuiError() << cmd.c_str() <<
" returned " << ret << std::endl;
390 if ( NCstring::terminalEncoding() !=
"UTF-8" )
392 std::string language = lang;
393 std::string::size_type pos = language.find(
'.' );
395 if ( pos != std::string::npos )
397 language.erase( pos );
400 pos = language.find(
'_' );
402 if ( pos != std::string::npos )
404 language.erase( pos );
407 std::string code = language2encoding( language );
409 yuiMilestone() <<
"setConsoleFont( ENCODING: " << code <<
" )" << std::endl;
411 if ( NCstring::setTerminalEncoding( code ) )
virtual YWidgetFactory * createWidgetFactory()
virtual void setConsoleFont(const std::string &console_magic, const std::string &font, const std::string &screen_map, const std::string &unicode_map, const std::string &lang)
virtual YOptionalWidgetFactory * createOptionalWidgetFactory()
void handler(int sig_num)
virtual void idleLoop(int fd_ycp)
virtual YEvent * runPkgSelection(YDialog *currentDialog, YWidget *packageSelector)
NCPackageSelectorPluginStub * packageSelectorPlugin()
virtual YEvent * runPkgSelection(YWidget *packageSelector)
YNCursesUI(bool withThreads)