MCPcopy Create free account
hub / github.com/SpartanJ/eepp / configureTerminalShell

Method configureTerminalShell

src/tools/ecode/terminalmanager.cpp:171–245  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

169}
170
171void TerminalManager::configureTerminalShell() {
172 static const auto layout( R"xml(
173 <window layout_width="300dp" layout_height="150dp" window-flags="default|shadow" window-title='@string(shell_configuration, "Shell Configuration")'>
174 <vbox lw="mp" lh="mp" padding="4dp">
175 <vbox lw="mp" lh="0" lw8="1">
176 <TextView text='@string(configure_default_shell, "Configure default shell")' font-size="14dp" margin-bottom="8dp" />
177 <ComboBox id="shell_combo" layout_width="match_parent" layout_height="wrap_content" selectedIndex="0" popup-to-root="true" />
178 <TextInput id="shell_args" layout_width="match_parent" layout_height="wrap_content" margin-top="8dp" hint="@string(shell_arguments, Shell Command Line Arguments)" />
179 </vbox>
180 <hbox layout_gravity="right">
181 <PushButton id="ok" text="@string(msg_box_ok, Ok)" icon="ok" />
182 <PushButton id="cancel" text="@string(msg_box_cancel, Cancel)" margin-left="8dp" icon="cancel" />
183 </hbox>
184 </vbox>
185 </window>
186 )xml" );
187 UIWindow* window = mApp->getUISceneNode()->loadLayoutFromString( layout )->asType<UIWindow>();
188 UIComboBox* shellCombo = window->find<UIComboBox>( "shell_combo" );
189 UITextInput* shellArgs = window->find<UITextInput>( "shell_args" );
190 UIPushButton* ok = window->find<UIPushButton>( "ok" );
191 UIPushButton* cancel = window->find<UIPushButton>( "cancel" );
192 const std::vector<std::string> list{
193 "bash", "sh", "zsh", "fish", "nu", "csh", "tcsh", "ksh", "dash", "cmd", "powershell",
194 };
195 std::vector<String> found;
196 for ( const auto& i : list ) {
197 std::string f( Sys::which( i ) );
198 if ( !f.empty() )
199 found.emplace_back( std::move( f ) );
200 }
201 shellCombo->getListBox()->addListBoxItems( found );
202 shellArgs->setText( mApp->termConfig().shellArgs );
203 const char* shellEnv = std::getenv( "SHELL" );
204 if ( !mApp->termConfig().shell.empty() ) {
205 shellCombo->getListBox()->setSelected( mApp->termConfig().shell );
206 shellCombo->setText( mApp->termConfig().shell );
207 } else if ( shellEnv ) {
208 std::string shellEnvStr( FileSystem::fileExists( shellEnv ) ? shellEnv
209 : Sys::which( shellEnv ) );
210 if ( !shellEnvStr.empty() )
211 shellCombo->getListBox()->setSelected( shellEnvStr );
212 } else if ( Sys::getPlatformType() == Sys::PlatformType::Windows ) {
213 std::string shellEnvStr( Sys::which( "powershell" ) );
214 if ( !shellEnvStr.empty() )
215 shellCombo->getListBox()->setSelected( shellEnvStr );
216 }
217 const auto setShellFn = []( App* app, UIWindow* window, UIComboBox* shellCombo,
218 UITextInput* shellArgs ) {
219 std::string shell( shellCombo->getText().toUtf8() );
220 if ( !Sys::which( shell ).empty() || FileSystem::fileExists( shell ) ) {
221 app->getConfig().term.shell = shell;
222 app->getConfig().term.shellArgs = shellArgs->getText().toUtf8();
223 window->closeWindow();
224 } else {
225 app->errorMsgBox( app->i18n(
226 "shell_not_found", "The shell selected was not found in the file system.\nMake "
227 "sure that the shell is visible in your PATH" ) );
228 }

Callers 1

Calls 15

loadLayoutFromStringMethod · 0.80
addListBoxItemsMethod · 0.80
toUtf8Method · 0.80
getConfigMethod · 0.80
closeWindowMethod · 0.80
errorMsgBoxMethod · 0.80
getMaxNumVisibleItemsMethod · 0.80
getDropDownListMethod · 0.80
asKeyEventMethod · 0.80
centerMethod · 0.80
getUISceneNodeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected