Possible with a plugin?

May 20, 2008
11,411
99
Syracuse, NY, USA
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.
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,466
88
Albuquerque, NM
prospero.unm.edu
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!
 
May 20, 2008
11,411
99
Syracuse, NY, USA
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).
 
May 20, 2008
11,411
99
Syracuse, NY, USA
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;
   }
 
May 20, 2008
11,411
99
Syracuse, NY, USA
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).
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,466
88
Albuquerque, NM
prospero.unm.edu
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?
 
May 20, 2008
11,411
99
Syracuse, NY, USA
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
Thread starter Title Forum Replies Date
Stefano Piccardi typing keyboard input to two tabs at once, possible? Plugins 10
Joe Caverly 64-bit Plugin development using PureBasic Plugins 15
R New Plugin Plugins 0
Alpengreis elevated plugin questions Plugins 3
fpefpe utf-8 support in sdk/plugin api Plugins 4
S How to? Can @DU function in 4Utils64 plugin somehow cater for dirs with spaces? Plugins 3
vefatica Plugin access to arrays? Plugins 4
vefatica How big is a plugin's parameter buffer? Plugins 5
C @knownpath plugin Plugins 0
Charles Dye Updated OSD plugin Plugins 0
Joe Caverly C# plugin framework for JPSoft's TCC Plugins 0
dcantor Help for newest version of TEXTUTILS plugin Plugins 10
dcantor UISTUFF plugin missing help topic Plugins 12
M How to? Use SafeChars plugin... Plugins 2
dcantor Error in SAFECHARS plugin v 1.9.0 Plugins 2
dcantor Request for documentation for ISO8601 plugin Plugins 4
dcantor Inconsistency between textutils plugin and wrap utility Plugins 2
M (Stupid?) Problem with 64-bit 4Utils plugin... Plugins 3
H Latest ISO8601 plugin? Plugins 1
Charles Dye New plugin: QKeys Plugins 34
S Plugin to quickly locate all files hard linked together Plugins 5
S Documentation Plugin everything.dll Plugins 5
newbie How to? Multi-plugin installation errors, Re: FedUtils8 Plugins 7
vefatica Plugin -> thread -> Command() -> Ctrl-C? Plugins 20
Charles Dye A weirdoid plugin question Plugins 6
M SafeChars plugin misbehaving... Plugins 3
M A weird error re a plugin... Plugins 0
vefatica Plugin dilemma Plugins 2
fpefpe Documentation Plugin API/SDK Plugins 3
C Looking for Vince's old 4UTILS plugin for TCMD v8 Plugins 1
S DESKTOP plugin - anyone ? Plugins 0
C How to? a plugin to sort Outlook Express "rules" Plugins 0
M ISO Plugin: Yes, it's wonderful, but it could be yet more wonderful... Plugins 7
M The ISO plugin is wonderful, but it lacks a little something... Plugins 22
Charles Dye Beta plugin: HidePasswords Plugins 3
M ISO8601 Plugin not "reporting" errors to TCC... Plugins 4
Frank 4console plugin Plugins 4
S WAD ISO8601 Plugin Plugins 15
Joe Caverly Plugin and 64-bit TCC Plugins 3
C Problem with FixNames plugin Plugins 9
dcantor Suggestion and request for DBF plugin Plugins 6
dcantor Suggestion for SafeChars plugin Plugins 7
M Charles, I just installed the "new" SafeChars plugin, ... Plugins 5
M A problem with the SafeChars Plugin... Plugins 30
S WHICHWIN (sysutils plugin) Plugins 13
M A (presumbly pretty simple) SafeChars plugin request... Plugins 2
M A "SafeChars" plugin request... Plugins 2
S ISO 8601 plugin enhancement Plugins 6
D UNKNOWN_CMD in Plugin Plugins 13
C Looking for isemailaddress[string] plugin Plugins 7

Similar threads