Esempio n. 1
0
void wxTerminal::OnEnter(wxCommandEvent& event)
{
    event.Skip();
    if(m_interactive) {
        wxString lineText = m_textCtrl->GetRange(m_inferiorEnd, m_textCtrl->GetInsertionPoint());
        lineText.Trim().Trim(false);
        DoProcessCommand(lineText);
    }
}
Esempio n. 2
0
void wxTerminal::Execute(const wxString& command, bool exitWhenDone, const wxString& workingDir)
{
    if(m_process) return;

    m_textCtrl->Clear();

    // restore default style
    m_textCtrl->SetDefaultStyle(m_defaultStyle);
    m_textCtrl->SetFocus();

    m_exitWhenProcessDies = exitWhenDone;
    m_workingDir = workingDir;
    DoProcessCommand(command);
}
Esempio n. 3
0
void wxTerminal::Execute(const wxString& command, bool exitWhenDone)
{
	m_textCtrl->AppendText( command  + wxT("\n") ); //   write the prompt,
	// Cancel it, whether there's a valid one or not:  even an old selection interferes
	m_textCtrl->SetSelection( m_textCtrl->GetLastPosition(), m_textCtrl->GetLastPosition() );
	m_textCtrl->SetInsertionPointEnd();
	m_commandStart = m_textCtrl->GetInsertionPoint();

	// restore default style
	m_textCtrl->SetDefaultStyle( m_defaultStyle );
	m_textCtrl->SetFocus();
	m_exitWhenProcessDies = exitWhenDone;
	DoProcessCommand(command);
}
Esempio n. 4
0
void wxTerminal::OnKey(wxKeyEvent& event)
{
	if( m_textCtrl->IsEditable() == false) {
		return;
	}

	if(m_exitOnKey) {
		GetParent()->Close(true);
		return;
	}

	wxString cmd;
	switch ( event.GetKeyCode() ) {
	case 'U': {
		if( event.m_controlDown && m_process == NULL) {
			// clear the current line
			DoInsertLine(wxT(""));
		} else {
			DoFixSelection();
			event.Skip();
		}
		break;
	}
	case 'L': {
		if( event.m_controlDown  && m_process == NULL) {
			// clear the current line
			m_textCtrl->Clear();
			DoWritePrompt();
			m_textCtrl->DiscardEdits();
		} else {
			DoFixSelection();
			event.Skip();
		}
		break;
	}
	case 'C': {
		if( event.m_controlDown && m_process ) {
			// Send Ctrl-C
			DoCtrlC();
		} else {
			DoFixSelection();
			event.Skip();
		}
		break;
	}
	case WXK_HOME: {
		m_textCtrl->SetInsertionPoint( m_commandStart );
		break;
	}
	case WXK_UP: {
		cmd = m_history.ArrowUp();
		DoInsertLine(cmd);
		break;
	}
	case WXK_RETURN:
	case WXK_NUMPAD_ENTER: {
		m_textCtrl->AppendText(wxT("\n"));
		wxString cmd = DoGetLastLine();
		if ( !m_process ) {
			if (cmd.IsEmpty() == false ) {
				DoProcessCommand( cmd );
			} else {
				DoWritePrompt();
			}
		} else {
			// we got a process running, re-direct all input to it
			m_process->Write( cmd );
		}
		m_textCtrl->SetInsertionPointEnd();
		break;
	}
	case WXK_DOWN: {
		cmd = m_history.ArrowDown();
		DoInsertLine(cmd);
		break;
	}
	case WXK_DELETE:
	case WXK_BACK: {
		// Make sure we dont delete our prompt
		long from, to;
		m_textCtrl->GetSelection( &from,  &to );
		if ( to > from ) {
			// If there's a valid selection, delete it
			if ( to > m_commandStart ) {
				m_textCtrl->Remove( wxMax(from, m_commandStart), to );
			}
		} else {
			// Otherwise do a normal Del/Backspace
			if ( event.GetKeyCode() == WXK_BACK ) {
				long insertionPoint;
				insertionPoint = m_textCtrl->GetInsertionPoint();
				if (insertionPoint  > m_commandStart ) m_textCtrl->Remove( insertionPoint-1, insertionPoint );
			} else {
				long insertionPoint;
				insertionPoint = m_textCtrl->GetInsertionPoint();
				if ( insertionPoint >= m_commandStart && insertionPoint < m_textCtrl->GetLastPosition() ) m_textCtrl->Remove( wxMax(insertionPoint, m_commandStart), insertionPoint+1 );
			}
		}
		break;
	}
	default:{
		DoFixSelection();
		event.Skip();
		break;
	}
	}
	m_textCtrl->SetFocus();
}