Bug - Fixed Return/Enter doesn't separate CLI commands when typed quickly

nema

New member
Currently running r12101, but this has been going on for as long as I can remember.

Often I'll be typing commands in the CLI and mafia behaves as if it just can't keep up as I type in stuff manually.

If, for example, I issue tye following commands:
Code:
skill empathy
skill leash

mafia ends up giving errors because it doesn't separate the commands correctly, like this:
Code:
skill empathys
kill leash

This happens to me daily. I assure you I'm entering RETURN at the proper place. Also, I apologize if this thread exists elsewhere-- I did searches for return/enter, and a few others without hits, but it could be described very differently by someone else.

I should note: if I enter it on one line separated by a semi-colon, there's never an issue. Not that I want to input that way, but that hasn't ever had issues.
 

lostcalpolydude

Developer
Staff member
I assure you I'm entering RETURN at the proper place.
Short of filming yourself typing and then reviewing the recording, how can you really be sure?

You could use "skill empathy, leash" to both avoid needing Enter and to save some typing.

If there really is a bug here, I don't think I will be tracking it down.
 

nema

New member
Short of filming yourself typing and then reviewing the recording, how can you really be sure?

You could use "skill empathy, leash" to both avoid needing Enter and to save some typing.

If there really is a bug here, I don't think I will be tracking it down.

I'm sure because it's not a mistake I make in other shells ever. It's odd though. I can't recall it ever being off by more than one character despite running into this all the time. And of course, slowing down does solve it. I thought it might be easily duplicated using copy/paste, but alas, the ENTER isn't carried through.

The comma solution you mention might be good for me to get into the habit of. But it doesn't solve the case when the commands aren't similar. eg. 'skill foo \nuse bar'
 

nema

New member
Short of filming yourself typing and then reviewing the recording, how can you really be sure?

You got me thinking about this-- I want to be sure. I located some software that sends keystrokes to windows with the following:
Code:
"skill leash<ENTER>skill empathy<ENTER>"

Mafia returned this with predictable results:
Code:
> CURRENT: skill leash
> QUEUED 1: kill empathy

In this test, the 1st command worked, but the 2nd didn't because 'kill empathy' can't be invoked. I don't know where the extra 's' went. When it happens to me typing manually, it's always part of the 1st command somehow.
 
I can confirm this happening.

My theory is that the enter key triggers something asynchronous, such as "notify a later thread to feed the current content of the input box to the CLI", and then, fast typing on slow computers makes it so the next keystroke after the enter key gets added to the input box and thus to the "previous" command.
 

roippi

Developer
You got me thinking about this-- I want to be sure. I located some software that sends keystrokes to windows

Share with the class? I do not have access to a sufficiently slow computer to reproduce this manually, and I can type quite fast.

Anyway I see how this happens:

Code:
		this.entryField.addKeyListener( new CommandEntryListener() );

Code:
	private class CommandEntryListener
		extends ThreadedListener

Code:
public abstract class ThreadedListener
	implements ActionListener, ItemListener, KeyListener, MouseListener, PopupMenuListener, Runnable
{

...

	public void keyReleased( final KeyEvent e )
	{
		if ( e.isConsumed() )
		{
			return;
		}

		if ( !this.isValidKeyCode( e.getKeyCode() ) )
		{
			return;
		}

		this.keyEvent = e;
		RequestThread.runInParallel( this ); // race condition, wrong

		e.consume();
	}

We shouldn't spawn a parallel thread to collect the contents of the entryField and zero them out, it should be done on the EDT. Many things in mafia are long-running operations and as such decidedly need a parallel thread to do their thing, but this is one case where it's necessary for things to be done all on the same thread.
 

ckb

Minion
Staff member
As a workaround for those times when commas don't work, semicolons are your friend.

Code:
skill empathy
skill leash

is the same as

Code:
skill empathy, leash

is the same as

Code:
skill empathy; skill leash
 

nema

New member
I did a few cmdlines and didn't see the problem. I ran the sendkeys test and both commands were handled properly. So it appears fixed, thanks!
 
Top