예제 #1
0
void RKConsole::tryNextInBatch (bool add_new_line) {
	RK_TRACE (APP);
	if (add_new_line) {
		if (RKSettingsModuleConsole::maxConsoleLines ()) {
			uint c = (uint) doc->numLines();
			setUpdatesEnabled (false);
			for (uint ui = c; ui > RKSettingsModuleConsole::maxConsoleLines (); --ui) {
				editInterface(doc)->removeText (0, 0,0, editInterface(doc)->textLine(0).length());
			}
			setUpdatesEnabled (true);
		}
		editInterface(doc)->insertText (doc->numLines ()-1, 0, prefix);		// somehow, it seems to be safer to do this after removing superfluous lines, than before
		cursorAtTheEnd ();
	}

	if (!commands_batch.isEmpty()) {
		// If we were not finished executing a batch of commands, we execute the next one.
		setCurrentCommand (currentCommand () + commands_batch.first ());
		commands_batch.pop_front ();
		if (!commands_batch.isEmpty ()){
			submitCommand ();
			return;
		}
		// We would put this here if we would want the last line to be executed. We generally don't want this, as there is an empty last item, if there is a newline at the end.
		//TODO: deal with this kind of situation better.
		//commands_batch.erase(commands_batch.begin());
	}

	current_command = 0;
	interrupt_command_action->setEnabled (isBusy ());
}
예제 #2
0
void pConsole::executeCommand( const QString& command, bool writeCommand, bool showPrompt )
{
	const QStringList clearCommands = QStringList( "clear" ) << "cls";
	
	if ( clearCommands.contains( command, Qt::CaseInsensitive ) )
	{
		clear();
		
		if ( showPrompt )
		{
			displayPrompt();
		}
		
		return;
	}
	
	// write command to execute
	if ( writeCommand )
	{
		if ( !currentCommand().isEmpty() )
		{
			displayPrompt();
		}
		
		insertPlainText( command );
	}
	
	// execute command
	int res;
	QString strRes = interpretCommand( command, &res );
	
	// write output in different colors if needed
	if ( res == 0 )
	{
		useColor( ctOutput );
	}
	else
	{
		useColor( ctError );
	}
	
	if ( !strRes.isEmpty() )
	{
		appendPlainText( strRes );
	}
	
	useColor( ctCommand );
	
	// display the prompt again if needed
	if ( showPrompt )
	{
		displayPrompt();
	}
}
예제 #3
0
bool RKConsole::provideContext (unsigned int line_rev, QString *context, int *cursor_position) {
	RK_TRACE (COMMANDEDITOR);

	if (line_rev > 1) return false;

	if (line_rev == 0) {
		*cursor_position = currentCursorPositionInCommand ();
		*context = currentCommand ();
	} else {
		*cursor_position = -1;
		*context = incomplete_command;
	}

	return true;
}
예제 #4
0
파일: ftp.cpp 프로젝트: jkinliu/Wave
/**
 * @brief   ftp命令回调函数
 */
void Ftp::ftp_command_finished(int id, bool error)
{
    int command = currentCommand();

    if (error)
    {
        abort();
        //qDebug() << "command id =" << id << "command" << command << "error =" << error;
    }

    switch (command)
    {
        case ConnectToHost:
        {
            break;
        }
        case Login:
        {
            emit connect_finished(error);
            break;
        }
        case Cd:
        {
            lists.clear();
            list();
            break;
        }
        case List:
        {
            emit file_lists(lists);
            break;
        }
        case Get:
        {
            file_download->close();
            break;
        }
        case Put:
        {
            file_upload->close();
            cd(".");
            break;
        }
        default:
            break;
    }
}
예제 #5
0
void SerialCommand::onCmdlineComplete(char * marker, char* current) {
#ifdef SERIALCOMMAND_DEBUG
		Serial.println("*******");
		Serial.println("Executing command.");
#endif

	if (currentCommand) {
		currentCommand();
	} else {
#ifdef SERIALCOMMAND_DEBUG
		Serial.println("Executing Default command.");
#endif
		defaultHandler(buffer);
	}
	currentCommand = 0;
	nparam = 0;
}
예제 #6
0
void RKConsole::pipeCommandThroughConsoleLocal (RCommand *command) {
	RK_TRACE (APP);

	emit (raiseWindow ());
	if (isBusy () || (!currentCommand ().isEmpty ())) {
		int res = KMessageBox::questionYesNo (this, i18n ("You have configured RKWrad to run script commands through the console. However, the console is currently busy (either a command is running, or you have started to enter text in the console). Do you want to bypass the console this one time, or do you want to try again later?"), i18n ("Console is busy"), KGuiItem (i18n ("Bypass console")), KGuiItem (i18n ("Cancel")));
		if (res == KMessageBox::Yes) {
			RKGlobals::rInterface ()->issueCommand (command);
		}
	} else {
		QString text = command->command ();
		text.replace ("\n", QString ("\n") + iprefix);
		doc->insertText (doc->numLines () - 1, QString (nprefix).length (), text + '\n');
		command->addReceiver (this);
		command->addTypeFlag (RCommand::Console);
		current_command = command;
		RKGlobals::rInterface ()->issueCommand (command);
	}
}
예제 #7
0
void RKConsole::doTabCompletion () {
	RK_TRACE (APP);

	QString current_line = currentCommand ();
	int word_start;
	int word_end;
	int cursor_pos = currentCursorPositionInCommand ();
	RKCommonFunctions::getCurrentSymbolOffset (current_line, cursor_pos, false, &word_start, &word_end);

	QString current_symbol = current_line.mid (word_start, word_end - word_start);
	if (!current_symbol.isEmpty ()) {
		RObject::RObjectMap map;
		RObject::RObjectMap::const_iterator it;
		RObjectList::getObjectList ()->findObjectsMatching (current_symbol, &map);
		int count = map.count ();

		if (count == 1) {
			int current_line_num = doc->numLines () - 1;
			int offset = prefix.length ();
			it = map.constBegin ();
			doc->removeText (current_line_num, offset + word_start, current_line_num, offset + word_end);
			doc->insertText (current_line_num, offset + word_start, it.key ());
		} else if (count == 0) {
			KApplication::kApplication ()->beep ();
		} else if (tab_key_pressed_before) {
			int i=0;
			for (it = map.constBegin (); it != map.constEnd (); ++it) {
				if (i % 3) {
					doc->insertText (doc->numLines () - 1, 0, it.key ().leftJustify (35));
				} else {
					doc->insertText (doc->numLines (), 0, it.key ());
				}
				++i;
			}
			doc->insertText (doc->numLines (),  0, prefix + current_line);
			cursorAtTheEnd ();
		} else {
			tab_key_pressed_before = true;
			return;
		}
	}
	tab_key_pressed_before = false;
}
예제 #8
0
void RKConsole::submitCommand () {
	RK_TRACE (APP);

	QString current_line = currentCommand ();
	QString command = current_line;
	addCommandToHistory (current_line);
	
	if (command_incomplete) {
		command.prepend (incomplete_command + '\n');
	}

	doc->insertText (doc->numLines () - 1, editInterface (doc)->lineLength (doc->numLines () -1), "\n");
	if (!current_line.isEmpty ()) {
		current_command = new RCommand (command, RCommand::User | RCommand::Console, QString::null, this);
		RKGlobals::rInterface ()->issueCommand (current_command);
		interrupt_command_action->setEnabled (true);
	} else {
		tryNextInBatch ();
	}
}
예제 #9
0
void FtpDownloader::processCommand(int id, bool err)
{
    if (!url_.isValid() || url_.isEmpty() || !dev_) {
        abort();
        return;
    }

    if (err) {
        if (ftpLoginId_ == id) {
            if (!anonymousLoginChecked_) {
                anonymousLoginChecked_ = true;
                ftpAuthenticator(url_)->setUser(QString());
                ftpAuthenticator(url_)->setPassword(QString());
                ftpLoginId_ = login();
                return;
            }
            emit ftpAuthenticationRequierd(url_, ftpAuthenticator(url_));
            ftpLoginId_ = login(ftpAuthenticator(url_)->user(), ftpAuthenticator(url_)->password());
            return;
        }
        abort();
        return;
    }

    switch (currentCommand()) {
    case QFtp::ConnectToHost:
        if (!anonymousLoginChecked_) {
            anonymousLoginChecked_ = ftpAuthenticator(url_)->user().isEmpty()
                                     && ftpAuthenticator(url_)->password().isEmpty();
        }
        ftpLoginId_ = login(ftpAuthenticator(url_)->user(), ftpAuthenticator(url_)->password());
        break;

    case QFtp::Login:
        get(url_.path(), dev_);
        break;
    default:
        ;
    }
}
예제 #10
0
void RKConsole::showContextHelp () {
	RK_TRACE (APP);
	RKGlobals::helpDialog ()->getContextHelp (currentCommand (), currentCursorPositionInCommand ());
}
예제 #11
0
void RKConsole::commandsListUp () {
	RK_TRACE (APP);
	if (commands_history.constBegin () == commands_history_position) return;	// already at topmost item
	if (commands_history.constEnd () == commands_history_position) history_editing_line = currentCommand ();
	--commands_history_position;

	setCurrentCommand (*commands_history_position);
}