Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Possible with a plugin?

May
12,998
174
Charles, Rex, anyone, do you think this is possible with a keystroke handler plugin?

... put a timestamp at the end of a command line ... on the same line ... maybe, upon <Enter>, put the timestamp on the command line after the current position, without altering the current position, and leaving the <Enter> (or NUL) in place. That could get messy with multi-line commands.

Do you think it could be done with PRE_EXEC? I tried
Code:
alias pre_exec `echos %_time`
but it gets it's own line.
 
Wouldn't be difficult with a keystroke handler. I don't think you'd want to hook Enter, though -- there wouldn't be very many commands you would want to add a timestamp to!
 
Wouldn't be difficult with a keystroke handler. I don't think you'd want to hook Enter, though -- there wouldn't be very many commands you would want to add a timestamp to!
Yes, it was quite easy.
Code:
  if ( lpki->nKey == 13 )
   {
     WCHAR szCmd[64] = L"ECHO ^e[35;1m(%_TIME)^e[0m";
     Command(szCmd, 0);
     return 0;
   }
upload_2014-10-16_23-24-10.png

<snip>
It seems a bit kludgy. Any suggestions? (probably should be ECHOS).
 
This makes it versatile and user-friendly, and works as shown above after
Code:
set postprompt=`^e[35;1m(%_TIME)^e[0m`
Code:
  if ( lpki->nKey == 13 )
   {
     WCHAR szCmd[64] = L"ECHO ^s";
     if ( GetEnvironmentVariable(L"POSTPROMPT", szCmd + 7, 57) )
       Command(szCmd, 0);
     return 0;
   }
 
But that only works well if the cursor is at the end of the command line when <Enter> is pressed. Hmmm! Now I have to figure out where the end of the command line is in the console (not tonight).
 
Well, I completely misunderstood what you're trying to do.

The structure passed to keystroke plugins includes the starting row/column of the command line, as well as a copy of the command line itself. Add the length of pszLine to the start column, and then I guess do some modulo arithmetic to handle lines longer than the console width?
 
Well, I completely misunderstood what you're trying to do.

The structure passed to keystroke plugins includes the starting row/column of the command line, as well as a copy of the command line itself. Add the length of pszLine to the start column, and then I guess do some modulo arithmetic to handle lines longer than the console width?
Thanks! I knew all that but got off on the wrong foot ... trying to start at the current cursor position. I also suppressed the action for empty and continued command lines and changed the name of the variable (though I'm not crazy about the new name).
Code:
  if ( lpki->nKey == VK_RETURN )
   {
     WCHAR szCmd[128] = L"ECHOS ^s";
     if ( GetEnvironmentVariable(L"CMD_POSTFIX", szCmd + 8, 120) && *(lpki->pszCurrent - 1) != L'^' && *lpki->pszLine != 0 )
     {
       INT len = lstrlen(lpki->pszLine);
       csbi.dwCursorPosition.Y = lpki->nHomeRow  + (len / csbi.dwSize.X);
       csbi.dwCursorPosition.X = lpki->nHomeColumn + (len % csbi.dwSize.X);
       SetConsoleCursorPosition(STD_OUT, csbi.dwCursorPosition);
       Command(szCmd, 0);
     }
     return 0;
   }
 

Similar threads

Back
Top