User should be able to save all the commands emitted #1355

Closed
opened 2026-01-30 22:23:30 +00:00 by claunia · 3 comments
Owner

Originally created by @ChristophePichaud on GitHub (May 25, 2019).

Summary of the new feature/enhancement

When the user emits commands, either in powershell or cmd, terminal can save them in memory (it's already done for the buffer) and enable the user to save them in a text file using a 'Save Commands in Text' item in a menu or via a button.

Proposed technical implementation details (optional)

It should not be difficult to make a static classic with a static vector and makeing a push_back everytimes and commands is started... I think it's already done for the bufer accessible with upper keyword key... Once the UI item is cliked, open the common dialog "Save As" and make a range for on th vector for writing the strings in a text file.
In theory, its about 20 lines of code... The idea is to properly catch the command after a carriage return or on upper wrapper called OnExecute(const wstring& command) or ireating through the memory buffer... Two possibilities.

Originally created by @ChristophePichaud on GitHub (May 25, 2019). # Summary of the new feature/enhancement When the user emits commands, either in powershell or cmd, terminal can save them in memory (it's already done for the buffer) and enable the user to save them in a text file using a 'Save Commands in Text' item in a menu or via a button. # Proposed technical implementation details (optional) It should not be difficult to make a static classic with a static vector<wstring> and makeing a push_back everytimes and commands is started... I think it's already done for the bufer accessible with upper keyword key... Once the UI item is cliked, open the common dialog "Save As" and make a range for on th vector for writing the strings in a text file. In theory, its about 20 lines of code... The idea is to properly catch the command after a carriage return or on upper wrapper called OnExecute(const wstring& command) or ireating through the memory buffer... Two possibilities.
Author
Owner

@mdtauk commented on GitHub (May 25, 2019):

These issues may be relevant #642 #644

@mdtauk commented on GitHub (May 25, 2019): These issues may be relevant #642 #644
Author
Owner

@zadjii-msft commented on GitHub (May 28, 2019):

Yea, this actually probably isn't solvable by the Terminal at all. It's the responsibility of the shell to execute commands, as well as knowing what a command actually is. From the terminal's perspective, we're just sending keystrokes.

Lets look at an example: editing a file in vim. While working in vim, the user is going to type a lot of keystrokes, including carriage returns, but the large majority of them are actually not commands. How could the terminal differentiate between keystrokes for vim vs keystrokes for cmd?

What about another example, powershell.exe. Say you use the reverse search functionality in powershell.

If you do not want to browse the entire history of PowerShell commands using up / down arrows, you can search the command history using CTRL+R (reverse search) or CTRL+S (forward search). Press the key combination and start typing part of the command that you want to find in previously executed commands. The text you entered will be found in the command history in any position (unlike search in PowerShell using F8 or Shift+F8, which allows to look for the matches from the beginning of the line only) and a suitable variant will be highlighted.

In the above case, a user typed Ctrl+R, then some subset of the command, then hit enter, but executed a much longer command. How could the terminal possible know what command was actually executed?

This seems like it should be easy, but would actually very quickly devlove into a myriad number of special per-shell cases. This is a feature request that's probably better suited for PowerShell/PowerShell

@zadjii-msft commented on GitHub (May 28, 2019): Yea, this actually probably isn't solvable by the Terminal at all. It's the responsibility of the _shell_ to execute commands, as well as knowing what a command actually is. From the terminal's perspective, we're just sending keystrokes. Lets look at an example: editing a file in vim. While working in vim, the user is going to type a lot of keystrokes, including carriage returns, but the large majority of them are actually _not_ commands. How could the terminal differentiate between keystrokes for vim vs keystrokes for cmd? What about another example, powershell.exe. Say you use the [reverse search ](http://woshub.com/powershell-commands-history/) functionality in powershell. > If you do not want to browse the entire history of PowerShell commands using up / down arrows, you can search the command history using CTRL+R (reverse search) or CTRL+S (forward search). Press the key combination and start typing part of the command that you want to find in previously executed commands. The text you entered will be found in the command history in any position (unlike search in PowerShell using F8 or Shift+F8, which allows to look for the matches from the beginning of the line only) and a suitable variant will be highlighted. In the above case, a user typed Ctrl+R, then some subset of the command, then hit enter, but executed a much longer command. How could the terminal possible know what command was actually executed? This _seems_ like it should be easy, but would actually very quickly devlove into a myriad number of special per-shell cases. This is a feature request that's probably better suited for [PowerShell/PowerShell](https://github.com/PowerShell/PowerShell)
Author
Owner

@ChristophePichaud commented on GitHub (May 29, 2019):

In readDataCooked.cpp in Terminal\src\host, in the function _handlePostCharInputLoop, there is a way to handle the history in cmd line. The feature is dedicated to cmd for the moment.
Are you interested in ?

NTSTATUS COOKED_READ_DATA::_handlePostCharInputLoop(const bool isUnicode, size_t& numBytes, ULONG& controlKeyState) noexcept
{
../..
if (FoundCR)
{
if (_commandHistory)
{
// add to command line recall list if we have a history list.
_commandHistory->Add({ _backupLimit // <-
::MessageBox(NULL, _backupLimit, L"command", MB_OK);
}
../..

@ChristophePichaud commented on GitHub (May 29, 2019): In readDataCooked.cpp in Terminal\src\host, in the function _handlePostCharInputLoop, there is a way to handle the history in cmd line. The feature **is dedicated to cmd** for the moment. Are you interested in ? NTSTATUS COOKED_READ_DATA::_handlePostCharInputLoop(const bool isUnicode, size_t& numBytes, ULONG& controlKeyState) noexcept { ../.. if (FoundCR) { if (_commandHistory) { // add to command line recall list if we have a history list. _commandHistory->Add({ _backupLimit // <- ::MessageBox(NULL, _backupLimit, L"command", MB_OK); } ../..
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#1355