Syntax for executing shell commands

This commit is contained in:
Krzosa Karol
2024-08-08 11:06:51 +02:00
parent ad2efab7c8
commit 3488c71155
5 changed files with 20 additions and 7 deletions

View File

@@ -84,6 +84,12 @@ bool AreEqual(String16 a, String16 b, unsigned ignore_case = false) {
inline bool operator==(String16 a, String16 b) { return AreEqual(a, b); }
inline bool operator!=(String16 a, String16 b) { return !AreEqual(a, b); }
wchar_t GetChar(String16 string, int64_t i) {
wchar_t result = 0;
if (i < string.len) result = string.data[i];
return result;
}
String16 Merge(Allocator allocator, Array<String16> list, String16 separator = " ") {
int64_t char_count = 0;
For(list) char_count += it.len;

View File

@@ -367,8 +367,11 @@ Process CreateCommandLineProcess(String command_line, String working_dir) {
String16 cmd = ToString16(scratch, command_line);
void *env = NULL;
DWORD dwCreationFlags = 0;
BOOL bInheritHandles = TRUE;
PROCESS_INFORMATION info = {};
if (!CreateProcessW(L"c:\\windows\\system32\\cmd.exe", cmd.data, 0, 0, TRUE, 0, env, cwd.data, &startup, &info)) {
if (!CreateProcessW(L"c:\\windows\\system32\\cmd.exe", cmd.data, 0, 0, bInheritHandles, dwCreationFlags, env, cwd.data, &startup, &info)) {
Win32ProcessError(&process, "failed to create process", command_line);
return process;
}

View File

@@ -884,13 +884,20 @@ void WindowCommand(Event event, Window *window, View *view) {
Range range = caret.range;
if (GetSize(caret.range) == 0) range = EncloseLoadWord(buffer, GetFront(caret));
String16 string = GetString(*buffer, range);
Open(string);
} else if (Alt(SDLK_Q)) {
Caret caret = view->carets[0];
Range range = caret.range;
if (GetSize(caret.range) == 0) range = EncloseExecWord(buffer, GetFront(caret));
String16 string = GetString(*buffer, range);
Command_EvalLua(view, string);
if (GetChar(string, 0) == L'!') {
string = Skip(string, 1);
Exec(ConsoleViewID, true, string, GetCurrentBufferDir());
} else {
Command_EvalLua(view, string);
}
// Exec(string, GetCurrentBufferDir());
}

View File

@@ -24,5 +24,3 @@ https://handmade.network/forums/t/1219-win32_asynchronous_pipes_question
- coloring seems even more hairy to do correctly because there are multiline comments etc.
- it honestly seems no matter what you do it's a very hairy problem, text was not meant for this
Ok for reference only, I would like to share my experience and how I solved the problem. IT may be possible that there's something wrong in the child process I spawn, but from what I see, if I call Read in non-blocking mode, so only after a PeekNamedPipe, there's nothing that prevent the process from being deallocated, even I keep a reference to the pipe. I've solved launching another thread that does blocking Read on the pipe descriptor, and I'm longer loosing the last bytes..

View File

@@ -1,13 +1,11 @@
- I guess it's pretty dangerous passing pointers everywhere?
- text in events aren't we using invalid memory for text? We need an intern table?
- kill all processes on exit https://devblogs.microsoft.com/oldnewthing/20131209-00/?p=2433
- if exec is prepended with '!' symbol then run a shell command
- try using git grep for search for now, combine with fuzzy search buffer
- Test stdin writing code
- Implement shell interaction (last line should have a '$'' symbols, if you press enter it should send that line to stdin of a running shell)
- exe icon
- search as a command to execute which is going to be in the title bar
- search backwards
@@ -46,6 +44,7 @@ BUG: there is a click hang when switching windows sometimes, you click after sel
backlog
- drop text into window
- page up and down should also scroll and leave you in exactly same scroll
- I think the way sublime text and we display line highlights is confusing with multiple cursors (line highlight can be confused with selection)
- ctrl + delete maybe should stop on new line but it keeps on going, sublime is much more careful with deleting